This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
move back to a stable Test-Simple, v1.001014
[perl5.git] / cpan / Test-Simple / t / undef.t
1 #!/usr/bin/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
13 use strict;
14 use Test::More tests => 21;
15
16 BEGIN { $^W = 1; }
17
18 my $warnings = '';
19 local $SIG{__WARN__} = sub { $warnings .= join '', @_ };
20
21 my $TB = Test::Builder->new;
22 sub no_warnings {
23     $TB->is_eq($warnings, '', '  no warnings');
24     $warnings = '';
25 }
26
27 sub warnings_is {
28     $TB->is_eq($warnings, $_[0]);
29     $warnings = '';
30 }
31
32 sub warnings_like {
33     $TB->like($warnings, $_[0]);
34     $warnings = '';
35 }
36
37
38 my $Filename = quotemeta $0;
39    
40
41 is( undef, undef,           'undef is undef');
42 no_warnings;
43
44 isnt( undef, 'foo',         'undef isnt foo');
45 no_warnings;
46
47 isnt( undef, '',            'undef isnt an empty string' );
48 isnt( undef, 0,             'undef isnt zero' );
49
50 Test::More->builder->is_num(undef, undef, 'is_num()');
51 Test::More->builder->isnt_num(23, undef,  'isnt_num()');
52
53 #line 45
54 like( undef, qr/.*/,        'undef is like anything' );
55 no_warnings;
56
57 eq_array( [undef, undef], [undef, 23] );
58 no_warnings;
59
60 eq_hash ( { foo => undef, bar => undef },
61           { foo => undef, bar => 23 } );
62 no_warnings;
63
64 eq_set  ( [undef, undef, 12], [29, undef, undef] );
65 no_warnings;
66
67
68 eq_hash ( { foo => undef, bar => { baz => undef, moo => 23 } },
69           { foo => undef, bar => { baz => undef, moo => 23 } } );
70 no_warnings;
71
72
73 #line 74
74 cmp_ok( undef, '<=', 2, '  undef <= 2' );
75 warnings_like(qr/Use of uninitialized value.* at \(eval in cmp_ok\) $Filename line 74\.\n/);
76
77
78
79 my $tb = Test::More->builder;
80
81 my $err = '';
82 $tb->failure_output(\$err);
83 diag(undef);
84 $tb->reset_outputs;
85
86 is( $err, "# undef\n" );
87 no_warnings;
88
89
90 $tb->maybe_regex(undef);
91 no_warnings;
92
93
94 # test-more.googlecode.com #42
95 {
96     is_deeply([ undef ], [ undef ]);
97     no_warnings;
98 }