FileList/t/exclude.t

filter: Statementstmt 72.8% 43 / 59 Branchbran 62.5% 15 / 24 Conditioncond 33.3% 1 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 100% 3 / 3 Podpod n/a totaltotal 68.1% 62 / 91 CC 1 SCAR 0.0
CC
1
Cov
69%
BEGIN
1.0
BEGIN
1.0
BEGIN
1.0
CRAP 1.0
« Digest/t/fileDigest.t ↑ Summary blib/lib/File/RsyncP/FileList.pm »
1 #!/bin/perl
2  
3 1 ▶use File::RsyncP;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 1 my $f = File::RsyncP::FileList->new({
7 protocol_version => 28,
8 });
9  
10 1 my @Tests = (
11 #
12 # Test 1: basic excludes with wildcards
13 #
14 {
15 excludes => [
16 {exclude => "*.doc"},
17 {exclude => "*.xls"},
18 ],
19 tests => [
20 {file => "other/bar.doc", result => -1},
21 {file => "other/bar.xls", result => -1},
22 {file => "other/bar.doc2", result => 0},
23 {file => "other/bar.xls2", result => 0},
24 ],
25 data => "050000002a2e646f63050000002a2e786c7300000000",
26 },
27  
28 #
29 # Test 2: basic excludes and includes with wildcards
30 #
31 {
32 excludes => [
33 {exclude => "*.doc"},
34 {include => "*.doc2"},
35 {exclude => "*.xls"},
36 {include => "*.xls2"},
37 ],
38 tests => [
39 {file => "other/bar.doc", result => -1},
40 {file => "other/bar.xls", result => -1},
41 {file => "other/bar.doc2", result => 1},
42 {file => "other/bar.xls2", result => 1},
43 ],
44 data => "050000002a2e646f63080000002b202a2e646f6332050000002a2e786c73080000002b202a2e786c733200000000",
45 },
46  
47 #
48 # Test 2: top-level patterns
49 #
50 {
51 excludes => [
52 {exclude => "/*/*.doc"},
53 {exclude => "/*/*/*.xls"},
54 {include => "*.xls2"},
55 ],
56 tests => [
57 {file => "other/bar.doc", result => -1},
58 {file => "other/bar.xls", result => 0},
59 {file => "other/bar.doc2", result => 0},
60 {file => "other/bar.xls2", result => 1},
61 ],
62 data => "080000002f2a2f2a2e646f630a0000002f2a2f2a2f2a2e786c73080000002b202a2e786c733200000000",
63 },
64 );
65 1 my $numTests = @Tests;
66 1 print "1..$numTests\n";
67  
68 1 my $testNum = 1;
69 1 foreach my $t ( @Tests ) {
70 3 my $ok = 1;
71  
72 #
73 # Add excludes
74 #
75 3 $f->exclude_list_clear();
76 3 foreach my $e ( @{$t->{excludes}} ) {
77 9 ▶ if ( defined($e->{exclude}) ) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined $e->{'exclude'}) { } 6 3 9
elsif (defined $e->{'include'}) { } 3 0 3
78 6 $f->exclude_add($e->{exclude}, 0);
79 } elsif ( defined($e->{include}) ) {
80 3 $f->exclude_add($e->{include}, 2);
81 }
82 }
83  
84 #
85 # Check list
86 #
87 3 my $exc = $f->exclude_list_get();
88 #print STDERR Dumper $exc;
89 3 ▶ if ( @$exc != @{$t->{excludes}} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@$exc != @{$t->{"excludes"};}) 0 3 3
90 printf(STDERR "Exclude list count mismatch: %d vs %d\n",
91 0 scalar(@$exc), scalar(@{$t->{excludes}}));
92 0 $ok = 0;
93 }
94 3 foreach my $e ( @{$t->{excludes}} ) {
95 9 ▶ if ( defined($e->{exclude}) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $e->{"exclude"}) 6 3 9
96 6 ▶ if ( $e->{exclude} ne $exc->[0]{pattern} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($e->{"exclude"} ne $exc->[0]{"pattern"}) 0 6 6
97 printf(STDERR "Exclude list pattern mismatch: %s vs %s\n",
98 0 $e->{exclude}, $exc->[0]{pattern});
99 0 $ok = 0;
100 }
101 6 ▶ if ( $exc->[0]{flags} & (1 << 4) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($exc->[0]{"flags"} & 16) 0 6 6
102 printf(STDERR "Exclude %s has wrong flag %d\n",
103 0 $e->{exclude}, $exc->[0]{flags});
104 0 $ok = 0;
105 }
106 }
107 9 ▶ if ( defined($e->{include}) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $e->{"include"}) 3 6 9
108 3 ▶ if ( $e->{include} ne $exc->[0]{pattern} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($e->{"include"} ne $exc->[0]{"pattern"}) 0 3 3
109 printf(STDERR "Exclude list pattern mismatch: %s vs %s\n",
110 0 $e->{include}, $exc->[0]{pattern});
111 0 $ok = 0;
112 }
113 3 ▶ if ( !($exc->[0]{flags} & (1 << 4)) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($exc->[0]{"flags"} & 16) 0 3 3
114 printf(STDERR "Exclude %s has wrong flag %d\n",
115 0 $e->{include}, $exc->[0]{flags});
116 0 $ok = 0;
117 }
118 }
119 9 shift(@$exc);
120 }
121  
122 #
123 # Check files
124 #
125 3 foreach my $file ( @{$t->{tests}} ) {
126 12 ▶ if ( $f->exclude_check($file->{file}, 0) != $file->{result} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($f->exclude_check($file->{"file"}, 0) != $file->{"result"}) 0 12 12
127 0 $ok = 0;
128 printf(STDERR "Exclude check on %s returns %d vs %d\n",
129 $file->{file},
130 0 $f->exclude_check($file->{file}, 0), $file->{result});
131 }
132 }
133  
134 #
135 # Check encoding
136 #
137 3 $f->exclude_list_send();
138 3 my $data = $f->encodeData();
139 3 ▶ if ( defined($t->{data}) && $t->{data} ne unpack("H*", $data) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $t->{"data"} and $t->{"data"} ne unpack("H*", $data)) 0 3 3
Condition33%1/3
defined $t->{"data"} and $t->{"data"} ne unpack("H*", $data)
!ll&&!rl&&r
030
MC/DC0%0/2
defined $t->{"data"} and $t->{"data"} ne unpack("H*", $data)
defined $t->{"data"} $t->{"data"} ne unpack("H*", $data)
Truth table33%1/3
A and B
A= defined $t->{"data"}B= $t->{"data"} ne unpack("H*", $data)
ABresult
0X0
100
111
140 0 print(STDERR "Botch encoded data: ", unpack("H*", $data),
141 " vs $t->{data}\n");
142 0 $ok = 0;
143 }
144  
145 #
146 # Print result
147 #
148 3 ▶ if ( $ok ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ok) { } 3 0 3
149 3 print("ok $testNum\n");
150 } else {
151 0 print("not ok $testNum\n");
152 }
153 3 $testNum++;
154 }
« Digest/t/fileDigest.t ↑ Summary blib/lib/File/RsyncP/FileList.pm »