source: trunk/essentials/dev-lang/perl/lib/vars.t

Last change on this file was 3181, checked in by bird, 19 years ago

perl 5.8.8

File size: 2.7 KB
Line 
1#!./perl
2
3BEGIN {
4 chdir 't' if -d 't';
5 @INC = '../lib';
6 $ENV{PERL5LIB} = '../lib';
7}
8
9$| = 1;
10
11print "1..27\n";
12
13# catch "used once" warnings
14my @warns;
15BEGIN { $SIG{__WARN__} = sub { push @warns, @_ }; $^W = 1 };
16
17%x = ();
18$y = 3;
19@z = ();
20$X::x = 13;
21
22use vars qw($p @q %r *s &t $X::p);
23
24my $e = !(grep /^Name "X::x" used only once: possible typo/, @warns) && 'not ';
25print "${e}ok 1\n";
26$e = !(grep /^Name "main::x" used only once: possible typo/, @warns) && 'not ';
27print "${e}ok 2\n";
28$e = !(grep /^Name "main::y" used only once: possible typo/, @warns) && 'not ';
29print "${e}ok 3\n";
30$e = !(grep /^Name "main::z" used only once: possible typo/, @warns) && 'not ';
31print "${e}ok 4\n";
32($e, @warns) = @warns != 4 && 'not ';
33print "${e}ok 5\n";
34
35# this is inside eval() to avoid creation of symbol table entries and
36# to avoid "used once" warnings
37eval <<'EOE';
38$e = ! $main::{p} && 'not ';
39print "${e}ok 6\n";
40$e = ! *q{ARRAY} && 'not ';
41print "${e}ok 7\n";
42$e = ! *r{HASH} && 'not ';
43print "${e}ok 8\n";
44$e = ! $main::{s} && 'not ';
45print "${e}ok 9\n";
46$e = ! *t{CODE} && 'not ';
47print "${e}ok 10\n";
48$e = defined $X::{q} && 'not ';
49print "${e}ok 11\n";
50$e = ! $X::{p} && 'not ';
51print "${e}ok 12\n";
52EOE
53$e = $@ && 'not ';
54print "${e}ok 13\n";
55
56eval q{use vars qw(@X::y !abc); $e = ! *X::y{ARRAY} && 'not '};
57print "${e}ok 14\n";
58$e = $@ !~ /^'!abc' is not a valid variable name/ && 'not ';
59print "${e}ok 15\n";