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