File: 05_is_excluded.t

package info (click to toggle)
libtest-checkmanifest-perl 1.43-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 236 kB
  • sloc: perl: 773; makefile: 2
file content (155 lines) | stat: -rw-r--r-- 4,236 bytes parent folder | download | duplicates (2)
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
#!/usr/bin/perl

use strict;
use warnings;

use File::Spec;
use File::Basename;
use Test::More;
use Cwd;

use Test::More;
use Test::CheckManifest;

# create a directory and a file
my $sub = Test::CheckManifest->can('_is_excluded');
ok $sub;

my $dir   = Cwd::realpath( dirname __FILE__ );
$dir      =~ s{.t\z}{};
my $file  = File::Spec->catfile( $dir, 'MANIFEST.SKIP' );
my $t_dir = File::Spec->catdir( $dir, 't' );
my $meta  = 'META.yml';

my $abs_t_file = File::Spec->rel2abs( __FILE__ );
my $this_file  = basename($abs_t_file);
my $bak_t_file = $abs_t_file . '.bak';

# my ($file,$dirref,$filter,$bool,$files_in_skip,$home) = @_;

# set up testcases
my @tests = (
    [
        [ $meta ],   # arguments
        1,           # success
        $meta,       # description
    ],
    [
        [ $meta, [] ],
        1,
        "meta, empty dirref",
    ],
    [
        [ $meta, [$t_dir] ],
        1,
        "meta, t/ directory",
    ],
    [
        [ $abs_t_file ],
        0,
        "this file",
    ],
    [
        [ $abs_t_file, [] ],
        0,
        "this file, empty dirref",
    ],
    [
        [ $abs_t_file, [ $t_dir ] ],
        1,
        "this file, t/ dir",
    ],
    [
        [ $abs_t_file, [ $t_dir ], [qr/excluded/] ],
        2,
        "this file, t/ dir, filter: 'excluded'",
    ],
    [
        [ $abs_t_file, [ $t_dir ], [qr/excluded/], 'and' ],
        1,
        "this file, t/ dir, filter: 'excluded', bool => 'and'",
    ],
    [
        [ $abs_t_file, [ $t_dir ], [qr/not_excluded/] ],
        1,
        "this file, t/ dir, filter: 'not_excluded'",
    ],
    [
        [ $abs_t_file, [ $t_dir ], [qr/not_excluded/], 'and' ],
        0,
        "this file, t/ dir, filter: 'not_excluded', bool => 'and'",
    ],
    [
        [ $abs_t_file, [ $t_dir ], [qr/excluded/], 'and', [] ],
        1,
        "this file, t/ dir, filter: 'excluded', bool => 'and', empty files_in_skip",
    ],
    [
        [ $abs_t_file, [ $t_dir ], [qr/excluded/], 'and', [qr/\Q$abs_t_file\E/] ],
        1,
        "this file, t/ dir, filter: 'excluded', bool => 'and', skip this file",
    ],
    [
        [ $abs_t_file . '.bak', [ $t_dir ], [qr/excluded/], 'and', [qr/\Q$bak_t_file\E/] ],
        1,
        "<this_file>.bak, t/ dir, filter: 'excluded', bool => 'and', skip backup of this file",
    ],
    [
        [ '/tmp/test', [ $t_dir ], [qr/excluded/], 'and', [qr/\Q$bak_t_file\E/] ],
        0,
        "/tmp/test, t/ dir, filter: 'excluded', bool => 'and', skip backup of this file",
    ],
    [
        [ '/tmp/test', [ $t_dir ], [qr/excluded/], 'and', ['/test'], '/tmp' ],
        0,
        "/tmp/test, t/ dir, filter: 'excluded', bool => 'and', skip /test in /tmp",
    ],
    [
        [ '/tmp/test', [ $t_dir ], [qr/excluded/], 'and', ['^test'], '/tmp' ],
        1,
        "/tmp/test, t/ dir, filter: 'excluded', bool => 'and', skip ^test in /tmp",
    ],
    [
        [ $abs_t_file, [ $t_dir ], [qr/excluded/], 'and', [qr/\Q$bak_t_file\E/] ],
        1,
        "this file, t/ dir, filter: 'excluded', bool => 'and', skip backup of this file",
    ],
    [
        [ $abs_t_file, [ $t_dir ], [qr/excluded/], 'and', {} ],
        0,
        "this file, t/ dir, filter: 'excluded', bool => 'and', wrong reftype files_in_skip",
    ],
    [
        [ $abs_t_file, [ $t_dir ], [qr/excluded/], 'and' ],
        1,
        "this file, t/ dir, filter: 'excluded', bool => 'and'",
    ],
    [
        [ $abs_t_file, [ $t_dir ], [qr/excluded/], 'or' ],
        2,
        "this file, t/ dir, filter: 'excluded', bool => 'or'",
    ],
    [
        [ $abs_t_file, [ $t_dir ], [qr/excluded/], 'and', [qr/\Q$abs_t_file\E/] ],
        1,
        "this file, t/ dir, filter: 'excluded', bool => 'and', excluded",
    ],
    [
        [ $abs_t_file, [], [], undef, [qr/^$this_file/], $t_dir ],
        1,
        "this file, matched by files_in_skip with start of string anchor",
    ],
    [
        [ $abs_t_file, [], [], undef, [qr/\/$this_file/], $t_dir ],
        0,
        "this file, not matched by files_in_skip because of leading slash",
    ],
);

for my $test ( @tests ) {
    my ($input, $check, $desc) = @{$test};
    my $ret = $sub->( @{$input} );
    is $ret, $check, $desc;
}

done_testing();