Assimilate Test-Simple 0.50
[p5sagit/p5-mst-13.2.git] / lib / Test / Simple / t / overload.t
1 #!perl -w
2
3 BEGIN {
4     if( $ENV{PERL_CORE} ) {
5         chdir 't';
6         @INC = ('../lib', 'lib');
7     }
8     else {
9         unshift @INC, 't/lib';
10     }
11 }
12 chdir 't';
13
14 BEGIN {
15     # There was a bug with overloaded objects and threads.
16     # See rt.cpan.org 4218
17     eval { require threads; 'threads'->import; 1; };
18 }
19
20 use Test::More;
21
22 BEGIN {
23     if( !eval "require overload" ) {
24         plan skip_all => "needs overload.pm";
25     }
26     else {
27         plan tests => 3;
28     }
29 }
30
31
32 package Overloaded;
33
34 use overload
35   q{""} => sub { $_[0]->{string} };
36
37 sub new {
38     my $class = shift;
39     bless { string => shift }, $class;
40 }
41
42
43 package main;
44
45 my $warnings = '';
46 local $SIG{__WARN__} = sub { $warnings = join '', @_ };
47 my $obj = Overloaded->new('foo');
48 ok( 1, $obj );
49
50 my $undef = Overloaded->new(undef);
51 pass( $undef );
52
53 is( $warnings, '' );