Commit | Line | Data |
49d42823 |
1 | #!./perl |
2 | |
96e82bbb |
3 | # Add new tests to the end with format: |
3ca7705e |
4 | # ######## |
5 | # |
6 | # # test description |
7 | # Test code |
8 | # EXPECT |
9 | # Warn or die msgs (if any) at - line 1234 |
96e82bbb |
10 | # |
49d42823 |
11 | |
12 | chdir 't' if -d 't'; |
20822f61 |
13 | @INC = '../lib'; |
49d42823 |
14 | $ENV{PERL5LIB} = "../lib"; |
15 | |
16 | $|=1; |
17 | |
18 | undef $/; |
f0faabb7 |
19 | @prgs = split /^########\n/m, <DATA>; |
49d42823 |
20 | |
3ca7705e |
21 | require './test.pl'; |
22 | plan(tests => scalar @prgs); |
49d42823 |
23 | for (@prgs){ |
f0faabb7 |
24 | ++$i; |
25 | my($prog,$expected) = split(/\nEXPECT\n/, $_, 2); |
26 | print("not ok $i # bad test format\n"), next |
27 | unless defined $expected; |
3ca7705e |
28 | my ($testname) = $prog =~ /^# (.*)\n/m; |
f0faabb7 |
29 | $testname ||= ''; |
49d42823 |
30 | $results =~ s/\n+$//; |
31 | $expected =~ s/\n+$//; |
3ca7705e |
32 | |
33 | fresh_perl_is($prog, $expected, {}, $testname); |
49d42823 |
34 | } |
35 | |
36 | __END__ |
37 | |
38 | # standard behaviour, without any extra references |
39 | use Tie::Hash ; |
40 | tie %h, Tie::StdHash; |
41 | untie %h; |
42 | EXPECT |
43 | ######## |
44 | |
a29a5827 |
45 | # standard behaviour, without any extra references |
46 | use Tie::Hash ; |
47 | {package Tie::HashUntie; |
48 | use base 'Tie::StdHash'; |
49 | sub UNTIE |
50 | { |
51 | warn "Untied\n"; |
52 | } |
53 | } |
54 | tie %h, Tie::HashUntie; |
55 | untie %h; |
56 | EXPECT |
57 | Untied |
58 | ######## |
59 | |
49d42823 |
60 | # standard behaviour, with 1 extra reference |
61 | use Tie::Hash ; |
62 | $a = tie %h, Tie::StdHash; |
63 | untie %h; |
64 | EXPECT |
65 | ######## |
66 | |
67 | # standard behaviour, with 1 extra reference via tied |
68 | use Tie::Hash ; |
69 | tie %h, Tie::StdHash; |
70 | $a = tied %h; |
71 | untie %h; |
72 | EXPECT |
73 | ######## |
74 | |
75 | # standard behaviour, with 1 extra reference which is destroyed |
76 | use Tie::Hash ; |
77 | $a = tie %h, Tie::StdHash; |
78 | $a = 0 ; |
79 | untie %h; |
80 | EXPECT |
81 | ######## |
82 | |
83 | # standard behaviour, with 1 extra reference via tied which is destroyed |
84 | use Tie::Hash ; |
85 | tie %h, Tie::StdHash; |
86 | $a = tied %h; |
87 | $a = 0 ; |
88 | untie %h; |
89 | EXPECT |
90 | ######## |
91 | |
92 | # strict behaviour, without any extra references |
4438c4b7 |
93 | use warnings 'untie'; |
49d42823 |
94 | use Tie::Hash ; |
95 | tie %h, Tie::StdHash; |
96 | untie %h; |
97 | EXPECT |
98 | ######## |
99 | |
100 | # strict behaviour, with 1 extra references generating an error |
4438c4b7 |
101 | use warnings 'untie'; |
49d42823 |
102 | use Tie::Hash ; |
103 | $a = tie %h, Tie::StdHash; |
104 | untie %h; |
105 | EXPECT |
3ca7705e |
106 | untie attempted while 1 inner references still exist at - line 6. |
49d42823 |
107 | ######## |
108 | |
109 | # strict behaviour, with 1 extra references via tied generating an error |
4438c4b7 |
110 | use warnings 'untie'; |
49d42823 |
111 | use Tie::Hash ; |
112 | tie %h, Tie::StdHash; |
113 | $a = tied %h; |
114 | untie %h; |
115 | EXPECT |
3ca7705e |
116 | untie attempted while 1 inner references still exist at - line 7. |
49d42823 |
117 | ######## |
118 | |
119 | # strict behaviour, with 1 extra references which are destroyed |
4438c4b7 |
120 | use warnings 'untie'; |
49d42823 |
121 | use Tie::Hash ; |
122 | $a = tie %h, Tie::StdHash; |
123 | $a = 0 ; |
124 | untie %h; |
125 | EXPECT |
126 | ######## |
127 | |
128 | # strict behaviour, with extra 1 references via tied which are destroyed |
4438c4b7 |
129 | use warnings 'untie'; |
49d42823 |
130 | use Tie::Hash ; |
131 | tie %h, Tie::StdHash; |
132 | $a = tied %h; |
133 | $a = 0 ; |
134 | untie %h; |
135 | EXPECT |
136 | ######## |
137 | |
138 | # strict error behaviour, with 2 extra references |
4438c4b7 |
139 | use warnings 'untie'; |
49d42823 |
140 | use Tie::Hash ; |
141 | $a = tie %h, Tie::StdHash; |
142 | $b = tied %h ; |
143 | untie %h; |
144 | EXPECT |
3ca7705e |
145 | untie attempted while 2 inner references still exist at - line 7. |
49d42823 |
146 | ######## |
147 | |
148 | # strict behaviour, check scope of strictness. |
4438c4b7 |
149 | no warnings 'untie'; |
49d42823 |
150 | use Tie::Hash ; |
151 | $A = tie %H, Tie::StdHash; |
152 | $C = $B = tied %H ; |
153 | { |
4438c4b7 |
154 | use warnings 'untie'; |
49d42823 |
155 | use Tie::Hash ; |
156 | tie %h, Tie::StdHash; |
157 | untie %h; |
158 | } |
159 | untie %H; |
160 | EXPECT |
33c27489 |
161 | ######## |
3ca7705e |
162 | |
ae21d580 |
163 | # Forbidden aggregate self-ties |
33c27489 |
164 | sub Self::TIEHASH { bless $_[1], $_[0] } |
ae21d580 |
165 | { |
f0faabb7 |
166 | my %c; |
ae21d580 |
167 | tie %c, 'Self', \%c; |
168 | } |
169 | EXPECT |
3ca7705e |
170 | Self-ties of arrays and hashes are not supported at - line 6. |
ae21d580 |
171 | ######## |
3ca7705e |
172 | |
ae21d580 |
173 | # Allowed scalar self-ties |
f0faabb7 |
174 | my $destroyed = 0; |
ae21d580 |
175 | sub Self::TIESCALAR { bless $_[1], $_[0] } |
f0faabb7 |
176 | sub Self::DESTROY { $destroyed = 1; } |
33c27489 |
177 | { |
ae21d580 |
178 | my $c = 42; |
ae21d580 |
179 | tie $c, 'Self', \$c; |
33c27489 |
180 | } |
f0faabb7 |
181 | die "self-tied scalar not DESTROYd" unless $destroyed == 1; |
182 | EXPECT |
183 | ######## |
3ca7705e |
184 | |
f0faabb7 |
185 | # Allowed glob self-ties |
186 | my $destroyed = 0; |
187 | sub Self2::TIEHANDLE { bless $_[1], $_[0] } |
188 | sub Self2::DESTROY { $destroyed = 1; } |
189 | { |
190 | use Symbol; |
191 | my $c = gensym; |
192 | tie *$c, 'Self2', $c; |
193 | } |
194 | die "self-tied glob not DESTROYd" unless $destroyed == 1; |
195 | EXPECT |
196 | ######## |
3ca7705e |
197 | |
f0faabb7 |
198 | # Allowed IO self-ties |
199 | my $destroyed = 0; |
200 | sub Self3::TIEHANDLE { bless $_[1], $_[0] } |
201 | sub Self3::DESTROY { $destroyed = 1; } |
202 | { |
203 | use Symbol 'geniosym'; |
204 | my $c = geniosym; |
205 | tie *$c, 'Self3', $c; |
206 | } |
207 | die "self-tied IO not DESTROYd" unless $destroyed == 1; |
33c27489 |
208 | EXPECT |
7bb043c3 |
209 | ######## |
3ca7705e |
210 | |
7bb043c3 |
211 | # Interaction of tie and vec |
212 | |
213 | my ($a, $b); |
214 | use Tie::Scalar; |
215 | tie $a,Tie::StdScalar or die; |
216 | vec($b,1,1)=1; |
217 | $a = $b; |
218 | vec($a,1,1)=0; |
219 | vec($b,1,1)=0; |
220 | die unless $a eq $b; |
221 | EXPECT |
83f527ec |
222 | ######## |
3ca7705e |
223 | |
0b2c215a |
224 | # correct unlocalisation of tied hashes (patch #16431) |
225 | use Tie::Hash ; |
226 | tie %tied, Tie::StdHash; |
96e82bbb |
227 | { local $hash{'foo'} } warn "plain hash bad unlocalize" if exists $hash{'foo'}; |
228 | { local $tied{'foo'} } warn "tied hash bad unlocalize" if exists $tied{'foo'}; |
229 | { local $ENV{'foo'} } warn "%ENV bad unlocalize" if exists $ENV{'foo'}; |
0b2c215a |
230 | EXPECT |
3ca7705e |
231 | ######## |
0b2c215a |
232 | |
3ca7705e |
233 | # An attempt at lvalueable barewords broke this |
234 | tie FH, 'main'; |
235 | EXPECT |
236 | Can't modify constant item in tie at - line 3, near "'main';" |
237 | Execution of - aborted due to compilation errors. |