Upgrade to Test-Simple-0.82.
[p5sagit/p5-mst-13.2.git] / lib / Test / Simple / t / undef.t
1 #!/usr/bin/perl -w
2 # $Id: /mirror/googlecode/test-more/t/undef.t 60310 2008-09-07T23:47:22.837229Z schwern  $
3
4 BEGIN {
5     if( $ENV{PERL_CORE} ) {
6         chdir 't';
7         @INC = ('../lib', 'lib');
8     }
9     else {
10         unshift @INC, 't/lib';
11     }
12 }
13
14 use strict;
15 use Test::More tests => 20;
16 use TieOut;
17
18 BEGIN { $^W = 1; }
19
20 my $warnings = '';
21 local $SIG{__WARN__} = sub { $warnings .= join '', @_ };
22
23 my $TB = Test::Builder->new;
24 sub no_warnings {
25     $TB->is_eq($warnings, '', '  no warnings');
26     $warnings = '';
27 }
28
29 sub warnings_is {
30     $TB->is_eq($warnings, $_[0]);
31     $warnings = '';
32 }
33
34 sub warnings_like {
35     $TB->like($warnings, "/$_[0]/");
36     $warnings = '';
37 }
38
39
40 my $Filename = quotemeta $0;
41    
42
43 is( undef, undef,           'undef is undef');
44 no_warnings;
45
46 isnt( undef, 'foo',         'undef isnt foo');
47 no_warnings;
48
49 isnt( undef, '',            'undef isnt an empty string' );
50 isnt( undef, 0,             'undef isnt zero' );
51
52 Test::More->builder->is_num(undef, undef, 'is_num()');
53 Test::More->builder->isnt_num(23, undef,  'isnt_num()');
54
55 #line 45
56 like( undef, '/.*/',        'undef is like anything' );
57 warnings_like("Use of uninitialized value.* at $Filename line 45\\.\n");
58
59 eq_array( [undef, undef], [undef, 23] );
60 no_warnings;
61
62 eq_hash ( { foo => undef, bar => undef },
63           { foo => undef, bar => 23 } );
64 no_warnings;
65
66 eq_set  ( [undef, undef, 12], [29, undef, undef] );
67 no_warnings;
68
69
70 eq_hash ( { foo => undef, bar => { baz => undef, moo => 23 } },
71           { foo => undef, bar => { baz => undef, moo => 23 } } );
72 no_warnings;
73
74
75 #line 64
76 cmp_ok( undef, '<=', 2, '  undef <= 2' );
77 warnings_like("Use of uninitialized value.* at $Filename line 64\\.\n");
78
79
80
81 my $tb = Test::More->builder;
82
83 use TieOut;
84 my $caught = tie *CATCH, 'TieOut';
85 my $old_fail = $tb->failure_output;
86 $tb->failure_output(\*CATCH);
87 diag(undef);
88 $tb->failure_output($old_fail);
89
90 is( $caught->read, "# undef\n" );
91 no_warnings;
92
93
94 $tb->maybe_regex(undef);
95 is( $caught->read, '' );
96 no_warnings;