Commit | Line | Data |
a687059c |
1 | #!./perl |
2 | |
e03bd546 |
3 | BEGIN { |
4 | chdir 't' if -d 't'; |
20822f61 |
5 | @INC = '../lib'; |
48f8bad9 |
6 | require './test.pl'; |
e03bd546 |
7 | } |
8 | |
48f8bad9 |
9 | use strict; |
a687059c |
10 | |
48f8bad9 |
11 | use vars qw(@ary %ary %hash); |
12 | |
d47e1c27 |
13 | plan 40; |
48f8bad9 |
14 | |
15 | ok !defined($a); |
a687059c |
16 | |
17 | $a = 1+1; |
48f8bad9 |
18 | ok defined($a); |
a687059c |
19 | |
20 | undef $a; |
48f8bad9 |
21 | ok !defined($a); |
a687059c |
22 | |
23 | $a = "hi"; |
48f8bad9 |
24 | ok defined($a); |
a687059c |
25 | |
26 | $a = $b; |
48f8bad9 |
27 | ok !defined($a); |
a687059c |
28 | |
29 | @ary = ("1arg"); |
30 | $a = pop(@ary); |
48f8bad9 |
31 | ok defined($a); |
a687059c |
32 | $a = pop(@ary); |
48f8bad9 |
33 | ok !defined($a); |
a687059c |
34 | |
35 | @ary = ("1arg"); |
36 | $a = shift(@ary); |
48f8bad9 |
37 | ok defined($a); |
a687059c |
38 | $a = shift(@ary); |
48f8bad9 |
39 | ok !defined($a); |
a687059c |
40 | |
41 | $ary{'foo'} = 'hi'; |
48f8bad9 |
42 | ok defined($ary{'foo'}); |
43 | ok !defined($ary{'bar'}); |
a687059c |
44 | undef $ary{'foo'}; |
48f8bad9 |
45 | ok !defined($ary{'foo'}); |
a687059c |
46 | |
48f8bad9 |
47 | ok defined(@ary); |
d47e1c27 |
48 | { |
49 | no warnings 'deprecated'; |
50 | ok defined(%ary); |
51 | } |
52 | ok %ary; |
a687059c |
53 | undef @ary; |
48f8bad9 |
54 | ok !defined(@ary); |
a687059c |
55 | undef %ary; |
d47e1c27 |
56 | { |
57 | no warnings 'deprecated'; |
58 | ok !defined(%ary); |
59 | } |
60 | ok !%ary; |
a687059c |
61 | @ary = (1); |
48f8bad9 |
62 | ok defined @ary; |
a687059c |
63 | %ary = (1,1); |
d47e1c27 |
64 | { |
65 | no warnings 'deprecated'; |
66 | ok defined %ary; |
67 | } |
68 | ok %ary; |
a687059c |
69 | |
48f8bad9 |
70 | sub foo { pass; 1 } |
a687059c |
71 | |
48f8bad9 |
72 | &foo || fail; |
a687059c |
73 | |
48f8bad9 |
74 | ok defined &foo; |
a687059c |
75 | undef &foo; |
48f8bad9 |
76 | ok !defined(&foo); |
a3f914c5 |
77 | |
78 | eval { undef $1 }; |
48f8bad9 |
79 | like $@, qr/^Modification of a read/; |
a3f914c5 |
80 | |
81 | eval { $1 = undef }; |
48f8bad9 |
82 | like $@, qr/^Modification of a read/; |
a3f914c5 |
83 | |
659eaf73 |
84 | { |
85 | require Tie::Hash; |
86 | tie my %foo, 'Tie::StdHash'; |
140d27a4 |
87 | no warnings 'deprecated'; |
48f8bad9 |
88 | ok defined %foo; |
659eaf73 |
89 | %foo = ( a => 1 ); |
48f8bad9 |
90 | ok defined %foo; |
659eaf73 |
91 | } |
92 | |
93 | { |
94 | require Tie::Array; |
95 | tie my @foo, 'Tie::StdArray'; |
140d27a4 |
96 | no warnings 'deprecated'; |
48f8bad9 |
97 | ok defined @foo; |
659eaf73 |
98 | @foo = ( a => 1 ); |
48f8bad9 |
99 | ok defined @foo; |
659eaf73 |
100 | } |
3d387947 |
101 | |
102 | { |
103 | # [perl #17753] segfault when undef'ing unquoted string constant |
104 | eval 'undef tcp'; |
48f8bad9 |
105 | like $@, qr/^Can't modify constant item/; |
3d387947 |
106 | } |
2f86008e |
107 | |
108 | # bugid 3096 |
109 | # undefing a hash may free objects with destructors that then try to |
110 | # modify the hash. To them, the hash should appear empty. |
111 | |
2f86008e |
112 | %hash = ( |
113 | key1 => bless({}, 'X'), |
114 | key2 => bless({}, 'X'), |
115 | ); |
116 | undef %hash; |
117 | sub X::DESTROY { |
48f8bad9 |
118 | is scalar keys %hash, 0; |
119 | is scalar values %hash, 0; |
120 | my @l = each %hash; |
121 | is @l, 0; |
122 | is delete $hash{'key2'}, undef; |
2f86008e |
123 | } |
6e592b3a |
124 | |
125 | # this will segfault if it fails |
126 | |
127 | sub PVBM () { 'foo' } |
128 | { my $dummy = index 'foo', PVBM } |
129 | |
130 | my $pvbm = PVBM; |
131 | undef $pvbm; |
48f8bad9 |
132 | ok !defined $pvbm; |