6 @INC = qw(: ::lib ::macos:lib);
11 require Config; import Config;
12 if ($Config{'extensions'} !~ /\bFile\/Glob\b/i) {
19 print "not ok 1\n" unless $loaded;
21 use File::Glob ':glob';
27 return '(', join(", ", map {defined $_ ? "\"$_\"" : "undef"} @a), ")\n";
30 # look for the contents of the current directory
32 delete @ENV{BASH_ENV, CDPATH, ENV, IFS};
34 if (opendir(D, $^O eq "MacOS" ? ":" : ".")) {
35 @correct = grep { !/^\./ } sort readdir(D);
38 @a = File::Glob::glob("*", 0);
40 if ("@a" ne "@correct" || GLOB_ERROR) {
41 print "# |@a| ne |@correct|\nnot ";
45 # look up the user's home directory
46 # should return a list with one item, and not set ERROR
47 if ($^O ne 'MSWin32' && $^O ne 'NetWare' && $^O ne 'VMS' && $^O ne 'os2') {
49 ($name, $home) = (getpwuid($>))[0,7];
52 if (defined $home && defined $name && -d $home) {
53 @a = bsd_glob("~$name", GLOB_TILDE);
54 if ((scalar(@a) != 1 || $a[0] ne $home || GLOB_ERROR)) {
63 # should return a list with one item, and not set ERROR
64 @a = bsd_glob('TEST', GLOB_QUOTE);
65 if (scalar @a != 1 || $a[0] ne 'TEST' || GLOB_ERROR) {
72 # check nonexistent checks
73 # should return an empty list
74 # XXX since errfunc is NULL on win32, this test is not valid there
75 @a = bsd_glob("asdfasdf", 0);
76 if (($^O ne 'MSWin32' && $^O ne 'NetWare') and scalar @a != 0) {
81 # check bad protections
82 # should return an empty list, and set ERROR
83 if ($^O eq 'mpeix' or $^O eq 'MSWin32' or $^O eq 'NetWare' or $^O eq 'os2' or $^O eq 'VMS'
84 or $^O eq 'cygwin' or Cwd::cwd() =~ m#^$Config{'afsroot'}#s or not $>)
86 print "ok 6 # skipped\n";
91 @a = bsd_glob("$dir/*", GLOB_ERR);
92 #print "\@a = ", array(@a);
94 if (scalar(@a) != 0 || GLOB_ERROR == 0) {
96 print "not ok 6 -- hit VOS bug posix-956\n";
106 # check for csh style globbing
107 @a = bsd_glob('{a,b}', GLOB_BRACE | GLOB_NOMAGIC);
108 unless (@a == 2 and $a[0] eq 'a' and $a[1] eq 'b') {
114 '{TES*,doesntexist*,a,b}',
115 GLOB_BRACE | GLOB_NOMAGIC | ($^O eq 'VMS' ? GLOB_NOCASE : 0)
118 # Working on t/TEST often causes this test to fail because it sees Emacs temp
119 # and RCS files. Filter them out, and .pm files too, and patch temp files.
120 @a = grep !/(,v$|~$|\.(pm|ori?g|rej)$)/, @a;
121 @a = (grep !/test.pl/, @a) if $^O eq 'VMS';
126 and $a[0] eq ($^O eq 'VMS'? 'test.' : 'TEST')
130 print "not ok 8 # @a\n";
135 # "~" should expand to $ENV{HOME}
136 $ENV{HOME} = "sweet home";
137 @a = bsd_glob('~', GLOB_TILDE | GLOB_NOMAGIC);
138 unless ($^O eq "MacOS" || (@a == 1 and $a[0] eq $ENV{HOME})) {
143 # GLOB_ALPHASORT (default) should sort alphabetically regardless of case
144 mkdir "pteerslo", 0777;
147 @f_names = qw(Ax.pl Bx.pl Cx.pl aY.pl bY.pl cY.pl);
148 @f_alpha = qw(Ax.pl aY.pl Bx.pl bY.pl Cx.pl cY.pl);
149 if ('a' lt 'A') { # EBCDIC char sets sort lower case before UPPER
150 @f_names = sort(@f_names);
152 if ($^O eq 'VMS') { # VMS is happily caseignorant
153 @f_alpha = qw(ax.pl ay.pl bx.pl by.pl cx.pl cy.pl);
165 @g_names = bsd_glob($pat, 0);
166 print "# f_names = @f_names\n";
167 print "# g_names = @g_names\n";
169 $ok = 0 unless $_ eq shift @g_names;
171 print $ok ? "ok 10\n" : "not ok 10\n";
174 @g_alpha = bsd_glob($pat);
175 print "# f_alpha = @f_alpha\n";
176 print "# g_alpha = @g_alpha\n";
178 $ok = 0 unless $_ eq shift @g_alpha;
180 print $ok ? "ok 11\n" : "not ok 11\n";