Small optimisations, by Brandon Black
[p5sagit/p5-mst-13.2.git] / t / op / glob.t
CommitLineData
a687059c 1#!./perl
2
72b16652 3BEGIN {
4 chdir 't' if -d 't';
9b38b307 5 @INC = qw(. ../lib);
72b16652 6}
a687059c 7
9b38b307 8require 'test.pl';
010be86b 9plan( tests => 15 );
a687059c 10
0a753a76 11@oops = @ops = <op/*>;
a687059c 12
68dc0745 13if ($^O eq 'MSWin32') {
3cd616b9 14 map { $files{lc($_)}++ } <op/*>;
6d0cc0d7 15 map { delete $files{"op/$_"} } split /[\s\n]/, `dir /b /l op & dir /b /l /ah op 2>nul`,
68dc0745 16}
0405c3f2 17elsif ($^O eq 'VMS') {
18 map { $files{lc($_)}++ } <[.op]*>;
19 map { s/;.*$//; delete $files{lc($_)}; } split /[\n]/, `directory/noheading/notrailing/versions=1 [.op]`,
20}
6664971e 21elsif ($^O eq 'MacOS') {
22 @oops = @ops = <:op:*>;
23 map { $files{$_}++ } <:op:*>;
24 map { delete $files{$_} } split /[\s\n]/, `echo :op:\xc5`;
25}
68dc0745 26else {
3cd616b9 27 map { $files{$_}++ } <op/*>;
68dc0745 28 map { delete $files{$_} } split /[\s\n]/, `echo op/*`;
29}
9b38b307 30ok( !(keys(%files)),'leftover op/* files' ) or diag(join(' ',sort keys %files));
a687059c 31
9b38b307 32cmp_ok($/,'eq',"\n",'sane input record separator');
a687059c 33
9b38b307 34$not = '';
6664971e 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 45}
9b38b307 46ok(!$not,"glob amid garbage [$not]");
a687059c 47
9b38b307 48cmp_ok($/,'eq',"\n",'input record separator still sane');
0a753a76 49
6664971e 50$_ = $^O eq 'MacOS' ? ":op:*" : "op/*";
0a753a76 51@glops = glob $_;
9b38b307 52cmp_ok("@glops",'eq',"@oops",'glob operator 1');
0a753a76 53
54@glops = glob;
9b38b307 55cmp_ok("@glops",'eq',"@oops",'glob operator 2');
ba112943 56
57# glob should still work even after the File::Glob stash has gone away
58# (this used to dump core)
59my $i = 0;
60for (1..2) {
61 eval "<.>";
9b38b307 62 ok(!length($@),"eval'ed a glob $_");
ba112943 63 undef %File::Glob::;
64 ++$i;
65}
9b38b307 66cmp_ok($i,'==',2,'remore File::Glob stash');
fe4a5e1f 67
48beb55f 68# ... while ($var = glob(...)) should test definedness not truth
69
9b38b307 70SKIP: {
71 skip('no File::Glob to emulate Unix-ism', 1)
72 unless $INC{'File/Glob.pm'};
73 my $ok = 0;
74 $ok = 1 while my $var = glob("0");
75 ok($ok,'define versus truth');
6ffa69ae 76}
ed2962a1 77
78# The formerly-broken test for the situation above would accidentally
79# test definedness for an assignment with a LOGOP on the right:
33cec765 80{
9b38b307 81 my $f = 0;
82 my $ok = 1;
83 $ok = 0, undef $f while $x = $f||$f;
84 ok($ok,'test definedness with LOGOP');
33cec765 85}
9b38b307 86
87cmp_ok(scalar(@oops),'>',0,'glob globbed something');
010be86b 88
89*aieee = 4;
90pass('Can assign integers to typeglobs');
91*aieee = 3.14;
92pass('Can assign floats to typeglobs');
93*aieee = 'pi';
94pass('Can assign strings to typeglobs');