This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
The warning no more comes from util.c, it comes from numeric.c.
[perl5.git] / t / lib / tb-xvari.t
1 BEGIN {
2     chdir 't' if -d 't';
3     @INC = '../lib';
4 }
5
6 # Before `make install' is performed this script should be runnable with
7 # `make test'. After `make install' it should work as `perl test.pl'
8
9 ######################### We start with some black magic to print on failure.
10
11 # Change 1..1 below to 1..last_test_to_print .
12 # (It may become useful if the test is moved to ./t subdirectory.)
13
14 BEGIN { $| = 1; print "1..81\n"; }
15 END {print "not ok 1\n" unless $loaded;}
16 use Text::Balanced qw ( extract_variable );
17 $loaded = 1;
18 print "ok 1\n";
19 $count=2;
20 use vars qw( $DEBUG );
21 sub debug { print "\t>>>",@_ if $DEBUG }
22
23 ######################### End of black magic.
24
25
26 $cmd = "print";
27 $neg = 0;
28 while (defined($str = <DATA>))
29 {
30         chomp $str;
31         if ($str =~ s/\A# USING://) { $neg = 0; $cmd = $str; next; }
32         elsif ($str =~ /\A# TH[EI]SE? SHOULD FAIL/) { $neg = 1; next; }
33         elsif (!$str || $str =~ /\A#/) { $neg = 0; next }
34         $str =~ s/\\n/\n/g;
35         debug "\tUsing: $cmd\n";
36         debug "\t   on: [$str]\n";
37
38         my @res;
39         $var = eval "\@res = $cmd";
40         debug "\t list got: [" . join("|",@res) . "]\n";
41         debug "\t list left: [$str]\n";
42         print "not " if (substr($str,pos($str)||0,1) eq ';')==$neg;
43         print "ok ", $count++;
44         print " ($@)" if $@ && $DEBUG;
45         print "\n";
46
47         pos $str = 0;
48         $var = eval $cmd;
49         $var = "<undef>" unless defined $var;
50         debug "\t scalar got: [$var]\n";
51         debug "\t scalar left: [$str]\n";
52         print "not " if ($str =~ '\A;')==$neg;
53         print "ok ", $count++;
54         print " ($@)" if $@ && $DEBUG;
55         print "\n";
56 }
57
58 __DATA__
59
60 # USING: extract_variable($str);
61 # THESE SHOULD FAIL
62 $a->;
63 $a (1..3) { print $a };
64
65 # USING: extract_variable($str);
66 *var;
67 *$var;
68 *{var};
69 *{$var};
70 *var{cat};
71 \&var;
72 \&mod::var;
73 \&mod'var;
74 $a;
75 $_;
76 $a[1];
77 $_[1];
78 $a{cat};
79 $_{cat};
80 $a->[1];
81 $a->{"cat"}[1];
82 @$listref;
83 @{$listref};
84 $obj->nextval;
85 $obj->_nextval;
86 $obj->next_val_;
87 @{$obj->nextval};
88 @{$obj->nextval($cat,$dog)->{new}};
89 @{$obj->nextval($cat?$dog:$fish)->{new}};
90 @{$obj->nextval(cat()?$dog:$fish)->{new}};
91 $ a {'cat'};
92 $a::b::c{d}->{$e->()};
93 $a'b'c'd{e}->{$e->()};
94 $a'b::c'd{e}->{$e->()};
95 $#_;
96 $#array;
97 $#{array};
98 $var[$#var];
99
100 # THESE SHOULD FAIL
101 $a->;
102 @{$;
103 $ a :: b :: c
104 $ a ' b ' c
105
106 # USING: extract_variable($str,'=*');
107 ========$a;