This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
embed.fnc: Fix declaration of my_strerror()
[perl5.git] / ext / File-Glob / t / rt131211.t
1 use strict;
2 use warnings;
3 use v5.16.0;
4 use File::Temp 'tempdir';
5 use File::Spec::Functions;
6 use Test::More;
7 use Time::HiRes qw(time);
8 use Config;
9
10 plan skip_all => 'This platform doesn\'t use File::Glob'
11                     if $Config{ccflags} =~ /\b{wb}-DPERL_EXTERNAL_GLOB\b\{wb}/;
12 plan tests => 13;
13
14 my $path = tempdir uc cleanup => 1;
15 my @files= (
16     "x".("a" x 50)."b", # 0
17     "abbbbbbbbbbbbc",   # 1
18     "abbbbbbbbbbbbd",   # 2
19     "aaabaaaabaaaabc",  # 3
20     "pq",               # 4
21     "r",                # 5
22     "rttiiiiiii",       # 6
23     "wewewewewewe",     # 7
24     "weeeweeeweee",     # 8
25     "weewweewweew",     # 9
26     "wewewewewewewewewewewewewewewewewq", # 10
27     "wtttttttetttttttwr", # 11
28 );
29
30
31 foreach (@files) {
32     open(my $f, ">", catfile $path, $_);
33 }
34
35 my $elapsed_fail= 0;
36 my $elapsed_match= 0;
37 my @got_files;
38 my @no_files;
39 my $count = 0;
40
41 while (++$count < 10) {
42     $elapsed_match -= time;
43     @got_files= glob catfile $path, "x".("a*" x $count) . "b";
44     $elapsed_match += time;
45
46     $elapsed_fail -= time;
47     @no_files= glob catfile $path, "x".("a*" x $count) . "c";
48     $elapsed_fail += time;
49     last if $elapsed_fail > $elapsed_match * 100;
50 }
51
52 is $count,10,
53     "tried all the patterns without bailing out";
54
55 SKIP: {
56     skip "unstable timing", 1 unless $elapsed_match && $elapsed_fail;
57     ok $elapsed_fail <= 10 * $elapsed_match,
58         "time to fail less than 10x the time to match"
59         or diag("elapsed_match=$elapsed_match elapsed_fail=$elapsed_fail");
60 }
61
62 is "@got_files", catfile($path, $files[0]),
63     "only got the expected file for xa*..b";
64 is "@no_files", "", "shouldnt have files for xa*..c";
65
66
67 @got_files= glob catfile $path, "a*b*b*b*bc";
68 is "@got_files", catfile($path, $files[1]),
69     "only got the expected file for a*b*b*b*bc";
70
71 @got_files= sort glob catfile $path, "a*b*b*bc";
72 is "@got_files", catfile($path, $files[3])." ".catfile($path,$files[1]),
73     "got the expected two files for a*b*b*bc";
74
75 @got_files= sort glob catfile $path, "p*";
76 is "@got_files", catfile($path, $files[4]),
77     "p* matches pq";
78
79 @got_files= sort glob catfile $path, "r*???????";
80 is "@got_files", catfile($path, $files[6]),
81     "r*??????? works as expected";
82
83 @got_files= sort glob catfile $path, "w*e*w??e";
84 is "@got_files", join(" ", sort map { catfile($path, $files[$_]) } (7,8)),
85     "w*e*w??e works as expected";
86
87 @got_files= sort glob catfile $path, "w*e*we??";
88 is "@got_files", join(" ", sort map { catfile($path, $files[$_]) } (7,8,9,10)),
89     "w*e*we?? works as expected";
90
91 @got_files= sort glob catfile $path, "w**e**w";
92 is "@got_files", join(" ", sort map { catfile($path, $files[$_]) } (9)),
93     "w**e**w works as expected";
94
95 @got_files= sort glob catfile $path, "*wee*";
96 is "@got_files", join(" ", sort map { catfile($path, $files[$_]) } (8,9)),
97     "*wee* works as expected";
98
99 @got_files= sort glob catfile $path, "we*";
100 is "@got_files", join(" ", sort map { catfile($path, $files[$_]) } (7,8,9,10)),
101     "we* works as expected";
102