Debian Codegraph @

t/05_is_excluded.t

raw symbols SCIP
1 #!/usr/bin/perl
2
3 use strict;
4 use warnings;
5
6 use File::Spec;
7 use File::Basename;
8 use Test::More;
9 use Cwd;
10
11 use Test::More;
12 use Test::CheckManifest;
13
14 # create a directory and a file
15 my $sub = Test::CheckManifest->can('_is_excluded');
16 ok $sub;
17
18 my $dir = Cwd::realpath( dirname __FILE__ );
19 $dir =~ s{.t\z}{};
20 my $file = File::Spec->catfile( $dir, 'MANIFEST.SKIP' );
21 my $t_dir = File::Spec->catdir( $dir, 't' );
22 my $meta = 'META.yml';
23
24 my $abs_t_file = File::Spec->rel2abs( __FILE__ );
25 my $this_file = basename($abs_t_file);
26 my $bak_t_file = $abs_t_file . '.bak';
27
28 # my ($file,$dirref,$filter,$bool,$files_in_skip,$home) = @_;
29
30 # set up testcases
31 my @tests = (
32 [
33 [ $meta ], # arguments
34 1, # success
35 $meta, # description
36 ],
37 [
38 [ $meta, [] ],
39 1,
40 "meta, empty dirref",
41 ],
42 [
43 [ $meta, [$t_dir] ],
44 1,
45 "meta, t/ directory",
46 ],
47 [
48 [ $abs_t_file ],
49 0,
50 "this file",
51 ],
52 [
53 [ $abs_t_file, [] ],
54 0,
55 "this file, empty dirref",
56 ],
57 [
58 [ $abs_t_file, [ $t_dir ] ],
59 1,
60 "this file, t/ dir",
61 ],
62 [
63 [ $abs_t_file, [ $t_dir ], [qr/excluded/] ],
64 2,
65 "this file, t/ dir, filter: 'excluded'",
66 ],
67 [
68 [ $abs_t_file, [ $t_dir ], [qr/excluded/], 'and' ],
69 1,
70 "this file, t/ dir, filter: 'excluded', bool => 'and'",
71 ],
72 [
73 [ $abs_t_file, [ $t_dir ], [qr/not_excluded/] ],
74 1,
75 "this file, t/ dir, filter: 'not_excluded'",
76 ],
77 [
78 [ $abs_t_file, [ $t_dir ], [qr/not_excluded/], 'and' ],
79 0,
80 "this file, t/ dir, filter: 'not_excluded', bool => 'and'",
81 ],
82 [
83 [ $abs_t_file, [ $t_dir ], [qr/excluded/], 'and', [] ],
84 1,
85 "this file, t/ dir, filter: 'excluded', bool => 'and', empty files_in_skip",
86 ],
87 [
88 [ $abs_t_file, [ $t_dir ], [qr/excluded/], 'and', [qr/\Q$abs_t_file\E/] ],
89 1,
90 "this file, t/ dir, filter: 'excluded', bool => 'and', skip this file",
91 ],
92 [
93 [ $abs_t_file . '.bak', [ $t_dir ], [qr/excluded/], 'and', [qr/\Q$bak_t_file\E/] ],
94 1,
95 "<this_file>.bak, t/ dir, filter: 'excluded', bool => 'and', skip backup of this file",
96 ],
97 [
98 [ '/tmp/test', [ $t_dir ], [qr/excluded/], 'and', [qr/\Q$bak_t_file\E/] ],
99 0,
100 "/tmp/test, t/ dir, filter: 'excluded', bool => 'and', skip backup of this file",
101 ],
102 [
103 [ '/tmp/test', [ $t_dir ], [qr/excluded/], 'and', ['/test'], '/tmp' ],
104 0,
105 "/tmp/test, t/ dir, filter: 'excluded', bool => 'and', skip /test in /tmp",
106 ],
107 [
108 [ '/tmp/test', [ $t_dir ], [qr/excluded/], 'and', ['^test'], '/tmp' ],
109 1,
110 "/tmp/test, t/ dir, filter: 'excluded', bool => 'and', skip ^test in /tmp",
111 ],
112 [
113 [ $abs_t_file, [ $t_dir ], [qr/excluded/], 'and', [qr/\Q$bak_t_file\E/] ],
114 1,
115 "this file, t/ dir, filter: 'excluded', bool => 'and', skip backup of this file",
116 ],
117 [
118 [ $abs_t_file, [ $t_dir ], [qr/excluded/], 'and', {} ],
119 0,
120 "this file, t/ dir, filter: 'excluded', bool => 'and', wrong reftype files_in_skip",
121 ],
122 [
123 [ $abs_t_file, [ $t_dir ], [qr/excluded/], 'and' ],
124 1,
125 "this file, t/ dir, filter: 'excluded', bool => 'and'",
126 ],
127 [
128 [ $abs_t_file, [ $t_dir ], [qr/excluded/], 'or' ],
129 2,
130 "this file, t/ dir, filter: 'excluded', bool => 'or'",
131 ],
132 [
133 [ $abs_t_file, [ $t_dir ], [qr/excluded/], 'and', [qr/\Q$abs_t_file\E/] ],
134 1,
135 "this file, t/ dir, filter: 'excluded', bool => 'and', excluded",
136 ],
137 [
138 [ $abs_t_file, [], [], undef, [qr/^$this_file/], $t_dir ],
139 1,
140 "this file, matched by files_in_skip with start of string anchor",
141 ],
142 [
143 [ $abs_t_file, [], [], undef, [qr/\/$this_file/], $t_dir ],
144 0,
145 "this file, not matched by files_in_skip because of leading slash",
146 ],
147 );
148
149 for my $test ( @tests ) {
150 my ($input, $check, $desc) = @{$test};
151 my $ret = $sub->( @{$input} );
152 is $ret, $check, $desc;
153 }
154
155 done_testing();