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