File: 02-checkstructurealone.t

package info (click to toggle)
libsvn-hooks-perl 1.36-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, sid, trixie
  • size: 380 kB
  • sloc: perl: 1,365; makefile: 7
file content (68 lines) | stat: -rwxr-xr-x 1,513 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# -*- cperl -*-

use strict;
use warnings;
use lib 't';
use lib 'blib/lib';
use Test::More tests => 14;
use SVN::Hooks::CheckStructure;

my $structure = [
    file     => 'FILE',
    dir      => 'DIR',
    subdir1  => [
	qr/^regex/   => 1,
	qr/^noregex/ => 0,
	1           => 'FILE',
    ],
    subdir2  => [
	subfile => 'FILE',
	0       => 'error 2',
    ],
    sub1 => [
	sub2 => [
	    sub3 => [
	    ],
	],
    ],
];

sub check_ok {
    my ($path, $test) = @_;
    eval {check_structure($structure, $path)};
    ok(!$@, $test)
	or diag $@;
}

sub check_nok {
    my ($path, $expect, $test) = @_;
    eval {check_structure($structure, $path)};
    if ($@) {
	like($@, $expect, $test);
    }
    else {
	fail($test);
	diag('test succeeded unexpectedly');
    }
}

check_ok('/file', 'FILE ok');
check_nok('/file/', qr/the component \(file\) should be a FILE/, 'FILE nok');

check_ok('/dir/', 'DIR ok');
check_nok('/dir', qr/the component \(dir\) should be a DIR/, 'DIR nok');

check_nok('/subdir1', qr/the component \(subdir1\) should be a DIR/, 'array DIR nok');
check_ok('/subdir1/', 'array DIR ok');

check_ok('/subdir1/regex', 'regex ok');
check_nok('/subdir1/noregex', qr/invalid path/, 'regex nok');

check_ok('/subdir1/file', 'else FILE ok');
check_nok('/subdir1/file/', qr/the component \(file\) should be a FILE/, 'else FILE nok');

check_nok('/subdir2/other', qr/error 2/, '0 =>');

check_ok('/sub1/', '/sub1');
check_ok('/sub1/sub2/', '/sub1/sub2/');
check_ok('/sub1/sub2/sub3/', '/sub1/sub2/sub3/');