4 use File::Temp 'tempdir';
5 use File::Spec::Functions;
7 use Time::HiRes qw(time);
10 plan skip_all => 'This platform doesn\'t use File::Glob'
11 if $Config{ccflags} =~ /\b{wb}-DPERL_EXTERNAL_GLOB\b{wb}/;
14 my $path = tempdir uc cleanup => 1;
16 "x".("a" x 50)."b", # 0
19 "aaabaaaabaaaabc", # 3
26 "wewewewewewewewewewewewewewewewewq", # 10
27 "wtttttttetttttttwr", # 11
31 # VMS needs a real extension.
32 map { $_ .= '.tmp' } @files if $^O eq 'VMS';
35 open(my $f, ">", catfile $path, $_);
44 while (++$count < 10) {
45 $elapsed_match -= time;
46 @got_files= glob catfile $path, "x".("a*" x $count) . "b";
47 $elapsed_match += time;
49 $elapsed_fail -= time;
50 @no_files= glob catfile $path, "x".("a*" x $count) . "c";
51 $elapsed_fail += time;
52 last if $elapsed_fail > $elapsed_match * 100;
56 "tried all the patterns without bailing out";
59 skip "unstable timing", 1 unless $elapsed_match && $elapsed_fail;
60 ok $elapsed_fail <= 10 * $elapsed_match,
61 "time to fail less than 10x the time to match"
62 or diag("elapsed_match=$elapsed_match elapsed_fail=$elapsed_fail");
65 is "@got_files", catfile($path, $files[0]),
66 "only got the expected file for xa*..b";
67 is "@no_files", "", "shouldnt have files for xa*..c";
70 @got_files= glob catfile $path, "a*b*b*b*bc";
71 is "@got_files", catfile($path, $files[1]),
72 "only got the expected file for a*b*b*b*bc";
74 @got_files= sort glob catfile $path, "a*b*b*bc";
75 is "@got_files", catfile($path, $files[3])." ".catfile($path,$files[1]),
76 "got the expected two files for a*b*b*bc";
78 @got_files= sort glob catfile $path, "p*";
79 is "@got_files", catfile($path, $files[4]),
82 @got_files= sort glob catfile $path, "r*???????";
83 is "@got_files", catfile($path, $files[6]),
84 "r*??????? works as expected";
86 @got_files= sort glob catfile $path, "w*e*w??e";
87 is "@got_files", join(" ", sort map { catfile($path, $files[$_]) } (7,8)),
88 "w*e*w??e works as expected";
90 @got_files= sort glob catfile $path, "w*e*we??";
91 is "@got_files", join(" ", sort map { catfile($path, $files[$_]) } (7,8,9,10)),
92 "w*e*we?? works as expected";
94 @got_files= sort glob catfile $path, "w**e**w";
95 is "@got_files", join(" ", sort map { catfile($path, $files[$_]) } (9)),
96 "w**e**w works as expected";
98 @got_files= sort glob catfile $path, "*wee*";
99 is "@got_files", join(" ", sort map { catfile($path, $files[$_]) } (8,9)),
100 "*wee* works as expected";
102 @got_files= sort glob catfile $path, "we*";
103 is "@got_files", join(" ", sort map { catfile($path, $files[$_]) } (7,8,9,10)),
104 "we* works as expected";