6 require Config; import Config;
7 if ($Config{'extensions'} !~ /\bFile\/Glob\b/i) {
13 use Test::More tests => 18;
14 BEGIN {use_ok('File::Glob', ':glob')};
21 if (eval 'require VMS::Feature') {
22 $vms_unix_rpt = VMS::Feature::current("filename_unix_report");
23 $vms_efs = VMS::Feature::current("efs_charset");
25 my $unix_rpt = $ENV{'DECC$FILENAME_UNIX_REPORT'} || '';
26 my $efs_charset = $ENV{'DECC$EFS_CHARSET'} || '';
27 $vms_unix_rpt = $unix_rpt =~ /^[ET1]/i;
28 $vms_efs = $efs_charset =~ /^[ET1]/i;
30 $vms_mode = 1 unless ($vms_unix_rpt);
34 # look for the contents of the current directory
36 delete @ENV{qw(BASH_ENV CDPATH ENV IFS)};
38 if (opendir(D, ".")) {
39 @correct = grep { !/^\./ } sort readdir(D);
42 my @a = File::Glob::glob("*", 0);
47 is_deeply(\@a, \@correct);
50 # look up the user's home directory
51 # should return a list with one item, and not set ERROR
54 skip $^O, 1 if $^O eq 'MSWin32' || $^O eq 'NetWare' || $^O eq 'VMS'
55 || $^O eq 'os2' || $^O eq 'beos';
56 skip "Can't find user for $>: $@", 1 unless eval {
57 ($name, $home) = (getpwuid($>))[0,7];
60 skip "$> has no home directory", 1
61 unless defined $home && defined $name && -d $home;
63 @a = bsd_glob("~$name", GLOB_TILDE);
68 is_deeply (\@a, [$home]);
71 # check plain tilde expansion
73 my $tilde_check = sub {
74 my @a = bsd_glob('~');
79 is_deeply (\@a, [$_[0]], join ' - ', 'tilde expansion', @_ > 1 ? $_[1] : ());
82 my $passwd_home = eval { (getpwuid($>))[7] };
87 delete $ENV{USERPROFILE};
88 $tilde_check->(defined $passwd_home ? $passwd_home : q{~}, 'no environment');
92 skip 'MSWin32 only', 1 if $^O ne 'MSWin32';
95 $ENV{USERPROFILE} = 'sweet win32 home';
96 $tilde_check->(defined $passwd_home ? $passwd_home : $ENV{USERPROFILE}, 'USERPROFILE');
99 my $home = exists $ENV{HOME} ? $ENV{HOME}
100 : eval { getpwuid($>); 1 } ? (getpwuid($>))[7]
101 : $^O eq 'MSWin32' && exists $ENV{USERPROFILE} ? $ENV{USERPROFILE}
103 $tilde_check->($home);
107 # should return a list with one item, and not set ERROR
108 @a = bsd_glob('TEST', GLOB_QUOTE);
112 is_deeply(\@a, ['TEST']);
115 # check nonexistent checks
116 # should return an empty list
117 # XXX since errfunc is NULL on win32, this test is not valid there
118 @a = bsd_glob("asdfasdf", 0);
120 skip $^O, 1 if $^O eq 'MSWin32' || $^O eq 'NetWare';
124 # check bad protections
125 # should return an empty list, and set ERROR
127 skip $^O, 2 if $^O eq 'mpeix' or $^O eq 'MSWin32' or $^O eq 'NetWare'
128 or $^O eq 'os2' or $^O eq 'VMS' or $^O eq 'cygwin';
129 skip "AFS", 2 if Cwd::cwd() =~ m#^$Config{'afsroot'}#s;
130 skip "running as root", 2 if not $>;
132 my $dir = "pteerslo";
134 @a = bsd_glob("$dir/*", GLOB_ERR);
136 local $TODO = 'hit VOS bug posix-956' if $^O eq 'vos';
142 # check for csh style globbing
143 @a = bsd_glob('{a,b}', GLOB_BRACE | GLOB_NOMAGIC);
144 is_deeply(\@a, ['a', 'b']);
147 '{TES*,doesntexist*,a,b}',
148 GLOB_BRACE | GLOB_NOMAGIC | ($^O eq 'VMS' ? GLOB_NOCASE : 0)
151 # Working on t/TEST often causes this test to fail because it sees Emacs temp
152 # and RCS files. Filter them out, and .pm files too, and patch temp files.
153 @a = grep !/(,v$|~$|\.(pm|ori?g|rej)$)/, @a;
154 @a = (grep !/test.pl/, @a) if $^O eq 'VMS';
158 is_deeply(\@a, [($vms_mode ? 'test.' : 'TEST'), 'a', 'b']);
160 # "~" should expand to $ENV{HOME}
161 $ENV{HOME} = "sweet home";
162 @a = bsd_glob('~', GLOB_TILDE | GLOB_NOMAGIC);
163 is_deeply(\@a, [$ENV{HOME}]);
165 # GLOB_ALPHASORT (default) should sort alphabetically regardless of case
166 mkdir "pteerslo", 0777;
169 my @f_names = qw(Ax.pl Bx.pl Cx.pl aY.pl bY.pl cY.pl);
170 my @f_alpha = qw(Ax.pl aY.pl Bx.pl bY.pl Cx.pl cY.pl);
171 if ('a' lt 'A') { # EBCDIC char sets sort lower case before UPPER
172 @f_names = sort(@f_names);
174 if ($^O eq 'VMS') { # VMS is happily caseignorant
175 @f_alpha = qw(ax.pl ay.pl bx.pl by.pl cx.pl cy.pl);
186 my @g_names = bsd_glob($pat, 0);
187 print "# f_names = @f_names\n";
188 print "# g_names = @g_names\n";
189 is_deeply(\@g_names, \@f_names);
191 my @g_alpha = bsd_glob($pat);
192 print "# f_alpha = @f_alpha\n";
193 print "# g_alpha = @g_alpha\n";
194 is_deeply(\@g_alpha, \@f_alpha);
200 # this can panic if PL_glob_index gets passed as flags to bsd_glob
205 use File::Temp qw(tempdir);
208 my($dir) = tempdir(CLEANUP => 1)
209 or die "Could not create temporary directory";
210 for my $file (qw(a_dej a_ghj a_qej)) {
211 open my $fh, ">", File::Spec->catfile($dir, $file)
212 or die "Could not create file $dir/$file: $!";
215 my $cwd = Cwd::cwd();
217 or die "Could not chdir to $dir: $!";
218 my(@glob_files) = glob("a*{d[e]}j");
220 or die "Could not chdir back to $cwd: $!";
221 local $TODO = "home-made glob doesn't do regexes" if $^O eq 'VMS';
222 is_deeply(\@glob_files, ['a_dej']);
225 # This used to segfault.
226 my $i = bsd_glob('*', GLOB_ALTDIRFUNC);
227 is(&File::Glob::GLOB_ERROR, 0, "Successfuly ignored unsupported flag");