summaryrefslogtreecommitdiff
path: root/cpan/Test-Simple/t/undef.t
blob: 2c8cace491ad9be4da0fb746788cd364eaf4ac5c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#!/usr/bin/perl -w

BEGIN {
    if( $ENV{PERL_CORE} ) {
        chdir 't';
        @INC = ('../lib', 'lib');
    }
    else {
        unshift @INC, 't/lib';
    }
}

use strict;
use Test::More tests => 21;

BEGIN { $^W = 1; }

my $warnings = '';
local $SIG{__WARN__} = sub { $warnings .= join '', @_ };

my $TB = Test::Builder->new;
sub no_warnings {
    $TB->is_eq($warnings, '', '  no warnings');
    $warnings = '';
}

sub warnings_is {
    $TB->is_eq($warnings, $_[0]);
    $warnings = '';
}

sub warnings_like {
    $TB->like($warnings, $_[0]);
    $warnings = '';
}


my $Filename = quotemeta $0;
   

is( undef, undef,           'undef is undef');
no_warnings;

isnt( undef, 'foo',         'undef isnt foo');
no_warnings;

isnt( undef, '',            'undef isnt an empty string' );
isnt( undef, 0,             'undef isnt zero' );

Test::More->builder->is_num(undef, undef, 'is_num()');
Test::More->builder->isnt_num(23, undef,  'isnt_num()');

#line 45
like( undef, qr/.*/,        'undef is like anything' );
no_warnings;

eq_array( [undef, undef], [undef, 23] );
no_warnings;

eq_hash ( { foo => undef, bar => undef },
          { foo => undef, bar => 23 } );
no_warnings;

eq_set  ( [undef, undef, 12], [29, undef, undef] );
no_warnings;


eq_hash ( { foo => undef, bar => { baz => undef, moo => 23 } },
          { foo => undef, bar => { baz => undef, moo => 23 } } );
no_warnings;


#line 74
cmp_ok( undef, '<=', 2, '  undef <= 2' );
warnings_like(qr/Use of uninitialized value.* at \(eval in cmp_ok\) $Filename line 74\.\n/);



my $tb = Test::More->builder;

my $err = '';
$tb->failure_output(\$err);
diag(undef);
$tb->reset_outputs;

is( $err, "# undef\n" );
no_warnings;


$tb->maybe_regex(undef);
no_warnings;


# test-more.googlecode.com #42
{
    is_deeply([ undef ], [ undef ]);
    no_warnings;
}