Commit | Line | Data |
---|---|---|
c989e6a3 GD |
1 | use warnings; |
2 | use strict; | |
5cc9a776 DC |
3 | |
4 | BEGIN { | |
5 | chdir 't' if -d 't'; | |
6 | @INC = '../lib'; | |
7 | require './test.pl'; | |
6b776407 | 8 | plan(tests => 4); |
5cc9a776 | 9 | } |
c989e6a3 GD |
10 | |
11 | use overload '""' => sub { 'stringvalue' }, fallback => 1; | |
12 | ||
13 | BEGIN { | |
14 | my $x = bless {}, 'main'; | |
15 | ok ($x eq 'stringvalue', 'fallback worked'); | |
16 | } | |
17 | ||
18 | ||
19 | # NOTE: delete the next line and this test script will pass | |
20 | use overload '+' => sub { die "unused"; }; | |
21 | ||
22 | my $x = bless {}, 'main'; | |
23 | ok (eval {$x eq 'stringvalue'}, 'fallback worked again'); | |
24 | ||
5cc9a776 DC |
25 | TODO: { |
26 | local $::TODO = 'RT #43356: Autogeneration of ++ is incorrect'; | |
27 | fresh_perl_is(<<'EOC', '2', {}, 'RT #43356: Autogeneration of ++'); | |
28 | use overload | |
29 | "0+" => sub { ${$_[0]} }, | |
30 | "=" => sub { ${$_[0]} }, | |
31 | fallback => 1; | |
32 | my $value = bless \(my $dummy = 1), __PACKAGE__; | |
33 | print ++$value; | |
34 | EOC | |
35 | } | |
6b776407 DC |
36 | |
37 | { | |
38 | my $warned = 0; | |
39 | local $SIG{__WARN__} = sub { $warned++; }; | |
40 | ||
41 | eval q{ | |
42 | use overload '${}', 'fallback'; | |
43 | no overload '${}', 'fallback'; | |
44 | }; | |
45 | ||
46 | ok($warned == 0, 'no overload should not warn'); | |
47 | } | |
48 |