This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
[perl #131263] clear the UTF8 flag on a glob if it isn't UTF8
[perl5.git] / t / lib / overload_fallback.t
CommitLineData
c989e6a3
GD
1use warnings;
2use strict;
5cc9a776
DC
3
4BEGIN {
5 chdir 't' if -d 't';
6 @INC = '../lib';
7 require './test.pl';
6b776407 8 plan(tests => 4);
5cc9a776 9}
c989e6a3
GD
10
11use overload '""' => sub { 'stringvalue' }, fallback => 1;
12
13BEGIN {
14my $x = bless {}, 'main';
15ok ($x eq 'stringvalue', 'fallback worked');
16}
17
18
19# NOTE: delete the next line and this test script will pass
20use overload '+' => sub { die "unused"; };
21
22my $x = bless {}, 'main';
23ok (eval {$x eq 'stringvalue'}, 'fallback worked again');
24
5cc9a776
DC
25TODO: {
26 local $::TODO = 'RT #43356: Autogeneration of ++ is incorrect';
27 fresh_perl_is(<<'EOC', '2', {}, 'RT #43356: Autogeneration of ++');
28use overload
29 "0+" => sub { ${$_[0]} },
30 "=" => sub { ${$_[0]} },
31 fallback => 1;
32my $value = bless \(my $dummy = 1), __PACKAGE__;
33print ++$value;
34EOC
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