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 | |
13 | plan 37; |
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); |
48 | ok defined(%ary); |
a687059c |
49 | undef @ary; |
48f8bad9 |
50 | ok !defined(@ary); |
a687059c |
51 | undef %ary; |
48f8bad9 |
52 | ok !defined(%ary); |
a687059c |
53 | @ary = (1); |
48f8bad9 |
54 | ok defined @ary; |
a687059c |
55 | %ary = (1,1); |
48f8bad9 |
56 | ok defined %ary; |
a687059c |
57 | |
48f8bad9 |
58 | sub foo { pass; 1 } |
a687059c |
59 | |
48f8bad9 |
60 | &foo || fail; |
a687059c |
61 | |
48f8bad9 |
62 | ok defined &foo; |
a687059c |
63 | undef &foo; |
48f8bad9 |
64 | ok !defined(&foo); |
a3f914c5 |
65 | |
66 | eval { undef $1 }; |
48f8bad9 |
67 | like $@, qr/^Modification of a read/; |
a3f914c5 |
68 | |
69 | eval { $1 = undef }; |
48f8bad9 |
70 | like $@, qr/^Modification of a read/; |
a3f914c5 |
71 | |
659eaf73 |
72 | { |
73 | require Tie::Hash; |
74 | tie my %foo, 'Tie::StdHash'; |
48f8bad9 |
75 | ok defined %foo; |
659eaf73 |
76 | %foo = ( a => 1 ); |
48f8bad9 |
77 | ok defined %foo; |
659eaf73 |
78 | } |
79 | |
80 | { |
81 | require Tie::Array; |
82 | tie my @foo, 'Tie::StdArray'; |
48f8bad9 |
83 | ok defined @foo; |
659eaf73 |
84 | @foo = ( a => 1 ); |
48f8bad9 |
85 | ok defined @foo; |
659eaf73 |
86 | } |
3d387947 |
87 | |
88 | { |
89 | # [perl #17753] segfault when undef'ing unquoted string constant |
90 | eval 'undef tcp'; |
48f8bad9 |
91 | like $@, qr/^Can't modify constant item/; |
3d387947 |
92 | } |
2f86008e |
93 | |
94 | # bugid 3096 |
95 | # undefing a hash may free objects with destructors that then try to |
96 | # modify the hash. To them, the hash should appear empty. |
97 | |
2f86008e |
98 | %hash = ( |
99 | key1 => bless({}, 'X'), |
100 | key2 => bless({}, 'X'), |
101 | ); |
102 | undef %hash; |
103 | sub X::DESTROY { |
48f8bad9 |
104 | is scalar keys %hash, 0; |
105 | is scalar values %hash, 0; |
106 | my @l = each %hash; |
107 | is @l, 0; |
108 | is delete $hash{'key2'}, undef; |
2f86008e |
109 | } |
6e592b3a |
110 | |
111 | # this will segfault if it fails |
112 | |
113 | sub PVBM () { 'foo' } |
114 | { my $dummy = index 'foo', PVBM } |
115 | |
116 | my $pvbm = PVBM; |
117 | undef $pvbm; |
48f8bad9 |
118 | ok !defined $pvbm; |