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