This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
fix typo in pp_defined() causing C<defined %tied> to fail
[perl5.git] / t / op / undef.t
CommitLineData
a687059c
LW
1#!./perl
2
a3f914c5 3print "1..23\n";
a687059c
LW
4
5print defined($a) ? "not ok 1\n" : "ok 1\n";
6
7$a = 1+1;
8print defined($a) ? "ok 2\n" : "not ok 2\n";
9
10undef $a;
11print defined($a) ? "not ok 3\n" : "ok 3\n";
12
13$a = "hi";
14print defined($a) ? "ok 4\n" : "not ok 4\n";
15
16$a = $b;
17print defined($a) ? "not ok 5\n" : "ok 5\n";
18
19@ary = ("1arg");
20$a = pop(@ary);
21print defined($a) ? "ok 6\n" : "not ok 6\n";
22$a = pop(@ary);
23print defined($a) ? "not ok 7\n" : "ok 7\n";
24
25@ary = ("1arg");
26$a = shift(@ary);
27print defined($a) ? "ok 8\n" : "not ok 8\n";
28$a = shift(@ary);
29print defined($a) ? "not ok 9\n" : "ok 9\n";
30
31$ary{'foo'} = 'hi';
32print defined($ary{'foo'}) ? "ok 10\n" : "not ok 10\n";
33print defined($ary{'bar'}) ? "not ok 11\n" : "ok 11\n";
34undef $ary{'foo'};
35print defined($ary{'foo'}) ? "not ok 12\n" : "ok 12\n";
36
37print defined(@ary) ? "ok 13\n" : "not ok 13\n";
38print defined(%ary) ? "ok 14\n" : "not ok 14\n";
39undef @ary;
40print defined(@ary) ? "not ok 15\n" : "ok 15\n";
41undef %ary;
42print defined(%ary) ? "not ok 16\n" : "ok 16\n";
43@ary = (1);
fe14fcc3 44print defined @ary ? "ok 17\n" : "not ok 17\n";
a687059c
LW
45%ary = (1,1);
46print defined %ary ? "ok 18\n" : "not ok 18\n";
47
48sub foo { print "ok 19\n"; }
49
50&foo || print "not ok 19\n";
51
52print defined &foo ? "ok 20\n" : "not ok 20\n";
53undef &foo;
54print defined(&foo) ? "not ok 21\n" : "ok 21\n";
a3f914c5
GS
55
56eval { undef $1 };
57print $@ =~ /^Modification of a read/ ? "ok 22\n" : "not ok 22\n";
58
59eval { $1 = undef };
60print $@ =~ /^Modification of a read/ ? "ok 23\n" : "not ok 23\n";
61