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