6 @INC = qw(: ::lib ::macos:lib);
11 require Config; import Config;
12 if ($Config{'extensions'} !~ /\bFile\/Glob\b/i) {
18 use Test::More tests => 14;
19 BEGIN {use_ok('File::Glob', ':glob')};
26 if (eval 'require VMS::Feature') {
27 $vms_unix_rpt = VMS::Feature::current("filename_unix_report");
28 $vms_efs = VMS::Feature::current("efs_charset");
30 my $unix_rpt = $ENV{'DECC$FILENAME_UNIX_REPORT'} || '';
31 my $efs_charset = $ENV{'DECC$EFS_CHARSET'} || '';
32 $vms_unix_rpt = $unix_rpt =~ /^[ET1]/i;
33 $vms_efs = $efs_charset =~ /^[ET1]/i;
35 $vms_mode = 1 unless ($vms_unix_rpt);
39 # look for the contents of the current directory
41 delete @ENV{qw(BASH_ENV CDPATH ENV IFS)};
43 if (opendir(D, $^O eq "MacOS" ? ":" : ".")) {
44 @correct = grep { !/^\./ } sort readdir(D);
47 my @a = File::Glob::glob("*", 0);
52 is_deeply(\@a, \@correct);
55 # look up the user's home directory
56 # should return a list with one item, and not set ERROR
59 skip $^O, 1 if $^O eq 'MSWin32' || $^O eq 'NetWare' || $^O eq 'VMS'
60 || $^O eq 'os2' || $^O eq 'beos';
61 skip "Can't find user for $>: $@", 1 unless eval {
62 ($name, $home) = (getpwuid($>))[0,7];
65 skip "$> has no home directory", 1
66 unless defined $home && defined $name && -d $home;
68 @a = bsd_glob("~$name", GLOB_TILDE);
73 is_deeply (\@a, [$home]);
78 # should return a list with one item, and not set ERROR
79 @a = bsd_glob('TEST', GLOB_QUOTE);
83 is_deeply(\@a, ['TEST']);
86 # check nonexistent checks
87 # should return an empty list
88 # XXX since errfunc is NULL on win32, this test is not valid there
89 @a = bsd_glob("asdfasdf", 0);
91 skip $^O, 1 if $^O eq 'MSWin32' || $^O eq 'NetWare';
95 # check bad protections
96 # should return an empty list, and set ERROR
98 skip $^O, 2 if $^O eq 'mpeix' or $^O eq 'MSWin32' or $^O eq 'NetWare'
99 or $^O eq 'os2' or $^O eq 'VMS' or $^O eq 'cygwin';
100 skip "AFS", 2 if Cwd::cwd() =~ m#^$Config{'afsroot'}#s;
101 skip "running as root", 2 if not $>;
103 my $dir = "pteerslo";
105 @a = bsd_glob("$dir/*", GLOB_ERR);
107 local $TODO = 'hit VOS bug posix-956' if $^O eq 'vos';
113 # check for csh style globbing
114 @a = bsd_glob('{a,b}', GLOB_BRACE | GLOB_NOMAGIC);
115 is_deeply(\@a, ['a', 'b']);
118 '{TES*,doesntexist*,a,b}',
119 GLOB_BRACE | GLOB_NOMAGIC | ($^O eq 'VMS' ? GLOB_NOCASE : 0)
122 # Working on t/TEST often causes this test to fail because it sees Emacs temp
123 # and RCS files. Filter them out, and .pm files too, and patch temp files.
124 @a = grep !/(,v$|~$|\.(pm|ori?g|rej)$)/, @a;
125 @a = (grep !/test.pl/, @a) if $^O eq 'VMS';
129 is_deeply(\@a, [($vms_mode ? 'test.' : 'TEST'), 'a', 'b']);
131 # "~" should expand to $ENV{HOME}
132 $ENV{HOME} = "sweet home";
133 @a = bsd_glob('~', GLOB_TILDE | GLOB_NOMAGIC);
135 skip $^O, 1 if $^O eq "MacOS";
136 is_deeply(\@a, [$ENV{HOME}]);
139 # GLOB_ALPHASORT (default) should sort alphabetically regardless of case
140 mkdir "pteerslo", 0777;
143 my @f_names = qw(Ax.pl Bx.pl Cx.pl aY.pl bY.pl cY.pl);
144 my @f_alpha = qw(Ax.pl aY.pl Bx.pl bY.pl Cx.pl cY.pl);
145 if ('a' lt 'A') { # EBCDIC char sets sort lower case before UPPER
146 @f_names = sort(@f_names);
148 if ($^O eq 'VMS') { # VMS is happily caseignorant
149 @f_alpha = qw(ax.pl ay.pl bx.pl by.pl cx.pl cy.pl);
160 my @g_names = bsd_glob($pat, 0);
161 print "# f_names = @f_names\n";
162 print "# g_names = @g_names\n";
163 is_deeply(\@g_names, \@f_names);
165 my @g_alpha = bsd_glob($pat);
166 print "# f_alpha = @f_alpha\n";
167 print "# g_alpha = @g_alpha\n";
168 is_deeply(\@g_alpha, \@f_alpha);
174 # this can panic if PL_glob_index gets passed as flags to bsd_glob
179 use File::Temp qw(tempdir);
182 my($dir) = tempdir(CLEANUP => 1)
183 or die "Could not create temporary directory";
184 for my $file (qw(a_dej a_ghj a_qej)) {
185 open my $fh, ">", File::Spec->catfile($dir, $file)
186 or die "Could not create file $dir/$file: $!";
189 my $cwd = Cwd::cwd();
191 or die "Could not chdir to $dir: $!";
192 my(@glob_files) = glob("a*{d[e]}j");
194 or die "Could not chdir back to $cwd: $!";
195 local $TODO = "home-made glob doesn't do regexes" if $^O eq 'VMS';
196 is_deeply(\@glob_files, ['a_dej']);