12 plan(skip_all => "File::GlobMapper needs Perl 5.005 or better - you have
16 # use Test::NoWarnings, if available
19 if eval { require Test::NoWarnings ; import Test::NoWarnings; 1 };
21 plan tests => 68 + $extra ;
23 use_ok('File::GlobMapper') ;
31 for my $delim ( qw/ ( ) { } [ ] / )
33 $gm = new File::GlobMapper("${delim}abc", '*.X');
34 ok ! $gm, " new failed" ;
35 is $File::GlobMapper::Error, "Unmatched $delim in input fileglob",
36 " catch unmatched $delim";
39 for my $delim ( qw/ ( ) [ ] / )
41 $gm = new File::GlobMapper("{${delim}abc}", '*.X');
42 ok ! $gm, " new failed" ;
43 is $File::GlobMapper::Error, "Unmatched $delim in input fileglob",
44 " catch unmatched $delim inside {}";
51 title "input glob matches zero files";
54 my $lex = new LexDir $tmpDir;
56 my $gm = new File::GlobMapper("$tmpDir/Z*", '*.X');
57 ok $gm, " created GlobMapper object" ;
59 my $map = $gm->getFileMap() ;
60 is @{ $map }, 0, " returned 0 maps";
61 is_deeply $map, [], " zero maps" ;
63 my $hash = $gm->getHash() ;
64 is_deeply $hash, {}, " zero maps" ;
68 title 'test wildcard mapping of * in destination';
71 my $lex = new LexDir $tmpDir;
74 touch map { "$tmpDir/$_.tmp" } qw( abc1 abc2 abc3 ) ;
76 my $gm = new File::GlobMapper("$tmpDir/ab*.tmp", "*X");
77 ok $gm, " created GlobMapper object" ;
79 my $map = $gm->getFileMap() ;
80 is @{ $map }, 3, " returned 3 maps";
82 [ [map { "$tmpDir/$_" } qw(abc1.tmp abc1.tmpX)],
83 [map { "$tmpDir/$_" } qw(abc2.tmp abc2.tmpX)],
84 [map { "$tmpDir/$_" } qw(abc3.tmp abc3.tmpX)],
87 my $hash = $gm->getHash() ;
89 { map { "$tmpDir/$_" } qw(abc1.tmp abc1.tmpX
96 title 'no wildcards in input or destination';
99 my $lex = new LexDir $tmpDir;
100 mkdir $tmpDir, 0777 ;
102 touch map { "$tmpDir/$_.tmp" } qw( abc1 abc2 abc3 ) ;
104 my $gm = new File::GlobMapper("$tmpDir/abc2.tmp", "$tmpDir/abc2.tmp");
105 ok $gm, " created GlobMapper object" ;
107 my $map = $gm->getFileMap() ;
108 is @{ $map }, 1, " returned 1 maps";
110 [ [map { "$tmpDir/$_.tmp" } qw(abc2 abc2)],
113 my $hash = $gm->getHash() ;
115 { map { "$tmpDir/$_.tmp" } qw(abc2 abc2),
120 title 'test wildcard mapping of {} in destination';
123 my $lex = new LexDir $tmpDir;
124 mkdir $tmpDir, 0777 ;
126 touch map { "$tmpDir/$_.tmp" } qw( abc1 abc2 abc3 ) ;
128 my $gm = new File::GlobMapper("$tmpDir/abc{1,3}.tmp", "*.X");
129 #diag "Input pattern is $gm->{InputPattern}";
130 ok $gm, " created GlobMapper object" ;
132 my $map = $gm->getFileMap() ;
133 is @{ $map }, 2, " returned 2 maps";
135 [ [map { "$tmpDir/$_" } qw(abc1.tmp abc1.tmp.X)],
136 [map { "$tmpDir/$_" } qw(abc3.tmp abc3.tmp.X)],
139 $gm = new File::GlobMapper("$tmpDir/abc{1,3}.tmp", "$tmpDir/X.#1.X")
140 or diag $File::GlobMapper::Error ;
141 #diag "Input pattern is $gm->{InputPattern}";
142 ok $gm, " created GlobMapper object" ;
144 $map = $gm->getFileMap() ;
145 is @{ $map }, 2, " returned 2 maps";
147 [ [map { "$tmpDir/$_" } qw(abc1.tmp X.1.X)],
148 [map { "$tmpDir/$_" } qw(abc3.tmp X.3.X)],
155 title 'test wildcard mapping of multiple * to #';
158 my $lex = new LexDir $tmpDir;
159 mkdir $tmpDir, 0777 ;
161 touch map { "$tmpDir/$_.tmp" } qw( abc1 abc2 abc3 ) ;
163 my $gm = new File::GlobMapper("$tmpDir/*b(*).tmp", "$tmpDir/X-#2-#1-X");
164 ok $gm, " created GlobMapper object"
165 or diag $File::GlobMapper::Error ;
167 my $map = $gm->getFileMap() ;
168 is @{ $map }, 3, " returned 3 maps";
170 [ [map { "$tmpDir/$_" } qw(abc1.tmp X-c1-a-X)],
171 [map { "$tmpDir/$_" } qw(abc2.tmp X-c2-a-X)],
172 [map { "$tmpDir/$_" } qw(abc3.tmp X-c3-a-X)],
177 title 'test wildcard mapping of multiple ? to #';
180 my $lex = new LexDir $tmpDir;
181 mkdir $tmpDir, 0777 ;
183 touch map { "$tmpDir/$_.tmp" } qw( abc1 abc2 abc3 ) ;
185 my $gm = new File::GlobMapper("$tmpDir/?b(*).tmp", "$tmpDir/X-#2-#1-X");
186 ok $gm, " created GlobMapper object" ;
188 my $map = $gm->getFileMap() ;
189 is @{ $map }, 3, " returned 3 maps";
191 [ [map { "$tmpDir/$_" } qw(abc1.tmp X-c1-a-X)],
192 [map { "$tmpDir/$_" } qw(abc2.tmp X-c2-a-X)],
193 [map { "$tmpDir/$_" } qw(abc3.tmp X-c3-a-X)],
198 title 'test wildcard mapping of multiple ?,* and [] to #';
201 my $lex = new LexDir $tmpDir;
202 mkdir $tmpDir, 0777 ;
204 touch map { "$tmpDir/$_.tmp" } qw( abc1 abc2 abc3 ) ;
206 my $gm = new File::GlobMapper("./$tmpDir/?b[a-z]*.tmp", "./$tmpDir/X-#3-#2-#1-X");
207 ok $gm, " created GlobMapper object" ;
209 #diag "Input pattern is $gm->{InputPattern}";
210 my $map = $gm->getFileMap() ;
211 is @{ $map }, 3, " returned 3 maps";
213 [ [map { "./$tmpDir/$_" } qw(abc1.tmp X-1-c-a-X)],
214 [map { "./$tmpDir/$_" } qw(abc2.tmp X-2-c-a-X)],
215 [map { "./$tmpDir/$_" } qw(abc3.tmp X-3-c-a-X)],
220 title 'input glob matches a file multiple times';
223 my $lex = new LexDir $tmpDir;
224 mkdir $tmpDir, 0777 ;
226 touch "$tmpDir/abc.tmp";
228 my $gm = new File::GlobMapper("$tmpDir/{a*,*c}.tmp", '*.X');
229 ok $gm, " created GlobMapper object" ;
231 my $map = $gm->getFileMap() ;
232 is @{ $map }, 1, " returned 1 maps";
234 [ [map { "$tmpDir/$_" } qw(abc.tmp abc.tmp.X)], ], " got mapping";
236 my $hash = $gm->getHash() ;
238 { map { "$tmpDir/$_" } qw(abc.tmp abc.tmp.X) }, " got mapping";
243 title 'multiple input files map to one output file';
246 my $lex = new LexDir $tmpDir;
247 mkdir $tmpDir, 0777 ;
249 touch map { "$tmpDir/$_.tmp" } qw( abc def) ;
251 my $gm = new File::GlobMapper("$tmpDir/*.tmp", "$tmpDir/fred");
252 ok ! $gm, " did not create GlobMapper object" ;
254 is $File::GlobMapper::Error, 'multiple input files map to one output file', " Error is expected" ;
256 #my $map = $gm->getFileMap() ;
257 #is @{ $map }, 1, " returned 1 maps";
259 #[ [map { "$tmpDir/$_" } qw(abc1 abc.X)], ], " got mapping";
266 my $lex = new LexDir $tmpDir;
267 mkdir $tmpDir, 0777 ;
269 touch map { "$tmpDir/$_.tmp" } qw( abc1 abc2 abc3 ) ;
271 my $map = File::GlobMapper::globmap("$tmpDir/*b*.tmp", "$tmpDir/X-#2-#1-X");
273 or diag $File::GlobMapper::Error ;
275 is @{ $map }, 3, " returned 3 maps";
277 [ [map { "$tmpDir/$_" } qw(abc1.tmp X-c1-a-X)],
278 [map { "$tmpDir/$_" } qw(abc2.tmp X-c2-a-X)],
279 [map { "$tmpDir/$_" } qw(abc3.tmp X-c3-a-X)],
284 # test each of the wildcard metacharacters can be mapped to the output filename
288 # input & output glob with no wildcards is ok
289 # input with no wild or output with no wild is bad
290 # input wild has concatenated *'s
291 # empty string for either both from & to
292 # escaped chars within [] and {}, including the chars []{}
293 # escaped , within {}
294 # missing ] and missing }
295 # {} and {,} are special cases
297 # {abc,{},{de,f}} => abc {} de f