This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
t/lib/croak/regcomp: Fix up for EBCDIC
[perl5.git] / t / lib / overload_fallback.t
1 use warnings;
2 use strict;
3
4 BEGIN {
5     chdir 't' if -d 't';
6     @INC = '../lib';
7     require './test.pl';
8     plan(tests => 4);
9 }
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
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 }
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