xref: /openbsd/gnu/usr.bin/perl/t/op/glob.t (revision 3d8817e4)
1#!./perl
2
3BEGIN {
4    chdir 't' if -d 't';
5    @INC = qw(. ../lib);
6}
7
8require 'test.pl';
9plan( tests => 16 );
10
11@oops = @ops = <op/*>;
12
13if ($^O eq 'MSWin32') {
14  map { $files{lc($_)}++ } <op/*>;
15  map { delete $files{"op/$_"} } split /[\s\n]/, `dir /b /l op & dir /b /l /ah op 2>nul`,
16}
17elsif ($^O eq 'VMS') {
18  map { $files{lc($_)}++ } <[.op]*>;
19  map { s/;.*$//; delete $files{lc($_)}; } split /[\n]/, `directory/noheading/notrailing/versions=1 [.op]`,
20}
21else {
22  map { $files{$_}++ } <op/*>;
23  map { delete $files{$_} } split /[\s\n]/, `echo op/*`;
24}
25ok( !(keys(%files)),'leftover op/* files' ) or diag(join(' ',sort keys %files));
26
27cmp_ok($/,'eq',"\n",'sane input record separator');
28
29$not = '';
30while (<jskdfjskdfj* op/* jskdjfjkosvk*>) {
31    $not = "not " unless $_ eq shift @ops;
32    $not = "not at all " if $/ eq "\0";
33}
34ok(!$not,"glob amid garbage [$not]");
35
36cmp_ok($/,'eq',"\n",'input record separator still sane');
37
38$_ = "op/*";
39@glops = glob $_;
40cmp_ok("@glops",'eq',"@oops",'glob operator 1');
41
42@glops = glob;
43cmp_ok("@glops",'eq',"@oops",'glob operator 2');
44
45# glob should still work even after the File::Glob stash has gone away
46# (this used to dump core)
47my $i = 0;
48for (1..2) {
49    eval "<.>";
50    ok(!length($@),"eval'ed a glob $_");
51    undef %File::Glob::;
52    ++$i;
53}
54cmp_ok($i,'==',2,'remove File::Glob stash');
55
56# a more sinister version of the same test (crashes from 5.8 to 5.13.1)
57{
58    undef %File::Glob::;
59    local %CORE::GLOBAL::;
60    eval "<.>";
61    ok(!length($@),"remove File::Glob stash *and* CORE::GLOBAL::glob");
62}
63
64# ... while ($var = glob(...)) should test definedness not truth
65
66SKIP: {
67    skip('no File::Glob to emulate Unix-ism', 1)
68	unless $INC{'File/Glob.pm'};
69    my $ok = 0;
70    $ok = 1 while my $var = glob("0");
71    ok($ok,'define versus truth');
72}
73
74# The formerly-broken test for the situation above would accidentally
75# test definedness for an assignment with a LOGOP on the right:
76{
77    my $f = 0;
78    my $ok = 1;
79    $ok = 0, undef $f while $x = $f||$f;
80    ok($ok,'test definedness with LOGOP');
81}
82
83cmp_ok(scalar(@oops),'>',0,'glob globbed something');
84
85*aieee = 4;
86pass('Can assign integers to typeglobs');
87*aieee = 3.14;
88pass('Can assign floats to typeglobs');
89*aieee = 'pi';
90pass('Can assign strings to typeglobs');
91