autogenerate API listing from comments in the source (from Benjamin
[p5sagit/p5-mst-13.2.git] / t / lib / glob-basic.t
CommitLineData
72b16652 1#!./perl
2
3BEGIN {
4 chdir 't' if -d 't';
5 unshift @INC, '../lib';
6
7 print "1..9\n";
8}
9END {
10 print "not ok 1\n" unless $loaded;
11}
12use File::Glob ':glob';
13$loaded = 1;
14print "ok 1\n";
15
16sub array {
17 return '(', join(", ", map {defined $_ ? "\"$_\"" : "undef"} @a), ")\n";
18}
19
20# look for the contents of the current directory
21$ENV{PATH} = "/bin";
22delete @ENV{BASH_ENV, CDPATH, ENV, IFS};
23@correct = ();
24if (opendir(D, ".")) {
25 @correct = grep { !/^\.\.?$/ } sort readdir(D);
26 closedir D;
27}
28@a = File::Glob::glob("*", 0);
29@a = sort @a;
30if ("@a" ne "@correct" || GLOB_ERROR) {
31 print "# |@a| ne |@correct|\nnot ";
32}
33print "ok 2\n";
34
35# look up the user's home directory
36# should return a list with one item, and not set ERROR
37if ($^O ne 'MSWin32') {
0eb4ebd7 38 eval {
72b16652 39 ($name, $home) = (getpwuid($>))[0,7];
0eb4ebd7 40 1;
41 } and do {
72b16652 42 @a = File::Glob::glob("~$name", GLOB_TILDE);
43 if (scalar(@a) != 1 || $a[0] ne $home || GLOB_ERROR) {
44 print "not ";
45 }
0eb4ebd7 46 };
72b16652 47}
48print "ok 3\n";
49
50# check backslashing
51# should return a list with one item, and not set ERROR
52@a = File::Glob::glob('TEST', GLOB_QUOTE);
53if (scalar @a != 1 || $a[0] ne 'TEST' || GLOB_ERROR) {
54 local $/ = "][";
55 print "# [@a]\n";
56 print "not ";
57}
58print "ok 4\n";
59
60# check nonexistent checks
61# should return an empty list
62# XXX since errfunc is NULL on win32, this test is not valid there
63@a = File::Glob::glob("asdfasdf", 0);
64if ($^O ne 'MSWin32' and scalar @a != 0) {
65 print "# |@a|\nnot ";
66}
67print "ok 5\n";
68
69# check bad protections
70# should return an empty list, and set ERROR
1cf742e9 71if ($^O eq 'MSWin32' or $^O eq 'os2' or not $>) {
72 print "ok 6 # skipped\n";
73}
74else {
75 $dir = "PtEeRsLt.dir";
76 mkdir $dir, 0;
77 @a = File::Glob::glob("$dir/*", GLOB_ERR);
78 #print "\@a = ", array(@a);
79 rmdir $dir;
80 if (scalar(@a) != 0 || GLOB_ERROR == 0) {
81 print "not ";
82 }
83 print "ok 6\n";
72b16652 84}
72b16652 85
86# check for csh style globbing
87@a = File::Glob::glob('{a,b}', GLOB_BRACE | GLOB_NOMAGIC);
88unless (@a == 2 and $a[0] eq 'a' and $a[1] eq 'b') {
89 print "not ";
90}
91print "ok 7\n";
92
93@a = File::Glob::glob(
94 '{TES*,doesntexist*,a,b}',
95 GLOB_BRACE | GLOB_NOMAGIC
96);
97unless (@a == 3
98 and $a[0] eq 'TEST'
99 and $a[1] eq 'a'
100 and $a[2] eq 'b')
101{
102 print "not ";
103}
104print "ok 8\n";
105
106# "~" should expand to $ENV{HOME}
107$ENV{HOME} = "sweet home";
108@a = File::Glob::glob('~', GLOB_TILDE | GLOB_NOMAGIC);
109unless (@a == 1 and $a[0] eq $ENV{HOME}) {
110 print "not ";
111}
112print "ok 9\n";