This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Move Test::Simple from ext/ to cpan/
[perl5.git] / cpan / Test-Simple / t / is_deeply_dne_bug.t
1 #!/usr/bin/perl -w
2
3 # test for rt.cpan.org 20768
4 #
5 # There was a bug where the internal "does not exist" object could get
6 # confused with an overloaded object.
7
8 BEGIN {
9     if( $ENV{PERL_CORE} ) {
10         chdir 't';
11         @INC = ('../lib', 'lib');
12     }
13     else {
14         unshift @INC, 't/lib';
15     }
16 }
17
18 use strict;
19 use Test::More tests => 2;
20
21 {
22     package Foo;
23
24     use overload
25     'eq' => \&overload_equiv,
26     '==' => \&overload_equiv;
27
28     sub new {
29         return bless {}, shift;
30     }
31
32     sub overload_equiv {
33         if (ref($_[0]) ne 'Foo' || ref($_[1]) ne 'Foo') {
34             print ref($_[0]), " ", ref($_[1]), "\n";
35             die "Invalid object passed to overload_equiv\n";
36         }
37
38         return 1; # change to 0 ... makes little difference
39     }
40 }
41
42 my $obj1 = Foo->new();
43 my $obj2 = Foo->new();
44
45 eval { is_deeply([$obj1, $obj2], [$obj1, $obj2]); };
46 is $@, '';
47