This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
some WinCE compilers require a little correction
[perl5.git] / t / op / glob.t
CommitLineData
a687059c
LW
1#!./perl
2
72b16652
GS
3BEGIN {
4 chdir 't' if -d 't';
20822f61 5 @INC = '../lib';
72b16652 6}
a687059c 7
33cec765 8print "1..10\n";
a687059c 9
0a753a76 10@oops = @ops = <op/*>;
a687059c 11
68dc0745 12if ($^O eq 'MSWin32') {
3cd616b9 13 map { $files{lc($_)}++ } <op/*>;
6d0cc0d7 14 map { delete $files{"op/$_"} } split /[\s\n]/, `dir /b /l op & dir /b /l /ah op 2>nul`,
68dc0745 15}
0405c3f2
CB
16elsif ($^O eq 'VMS') {
17 map { $files{lc($_)}++ } <[.op]*>;
18 map { s/;.*$//; delete $files{lc($_)}; } split /[\n]/, `directory/noheading/notrailing/versions=1 [.op]`,
19}
6664971e
JH
20elsif ($^O eq 'MacOS') {
21 @oops = @ops = <:op:*>;
22 map { $files{$_}++ } <:op:*>;
23 map { delete $files{$_} } split /[\s\n]/, `echo :op:\xc5`;
24}
68dc0745 25else {
3cd616b9 26 map { $files{$_}++ } <op/*>;
68dc0745 27 map { delete $files{$_} } split /[\s\n]/, `echo op/*`;
28}
adbc4883
CB
29if (keys %files) {
30 print "not ok 1\t(",join(' ', sort keys %files),"\n";
31} else { print "ok 1\n"; }
a687059c
LW
32
33print $/ eq "\n" ? "ok 2\n" : "not ok 2\n";
34
6664971e
JH
35if ($^O eq 'MacOS') {
36 while (<jskdfjskdfj* :op:* jskdjfjkosvk*>) {
37 $not = "not " unless $_ eq shift @ops;
38 $not = "not at all " if $/ eq "\0";
39 }
40} else {
41 while (<jskdfjskdfj* op/* jskdjfjkosvk*>) {
42 $not = "not " unless $_ eq shift @ops;
43 $not = "not at all " if $/ eq "\0";
44 }
a687059c
LW
45}
46print "${not}ok 3\n";
47
48print $/ eq "\n" ? "ok 4\n" : "not ok 4\n";
0a753a76 49
50# test the "glob" operator
6664971e 51$_ = $^O eq 'MacOS' ? ":op:*" : "op/*";
0a753a76 52@glops = glob $_;
53print "@glops" eq "@oops" ? "ok 5\n" : "not ok 5\n";
54
55@glops = glob;
56print "@glops" eq "@oops" ? "ok 6\n" : "not ok 6\n";
ba112943
BS
57
58# glob should still work even after the File::Glob stash has gone away
59# (this used to dump core)
60my $i = 0;
61for (1..2) {
62 eval "<.>";
63 undef %File::Glob::;
64 ++$i;
65}
66print $i == 2 ? "ok 7\n" : "not ok 7\n";
fe4a5e1f 67
48beb55f
RH
68# ... while ($var = glob(...)) should test definedness not truth
69
6ffa69ae
CB
70if( $INC{'File/Glob.pm'} ) {
71 my $ok = "not ok 8\n";
72 $ok = "ok 8\n" while my $var = glob("0");
73 print $ok;
74}
75else {
76 print "ok 8 # skip: File::Glob emulated Unixism\n";
77}
78
ed2962a1
RH
79
80# The formerly-broken test for the situation above would accidentally
81# test definedness for an assignment with a LOGOP on the right:
82my $f=0;
83$ok="ok 9\n";
84$ok="not ok 9\n", undef $f while $x = $f||$f;
33cec765
IT
85print $ok;
86
87# Better check that glob actually returned some entries
88{
89 my $not = (scalar @oops > 0) ? '' : 'not ';
90 print "${not}ok 10\n";
91}