Clear up test based on line number differences between the core and the
[p5sagit/p5-mst-13.2.git] / lib / 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;
b1ddf169 14use Test::More tests => 18;
89c1e84a 15use TieOut;
d020a79a 16
17BEGIN { $^W = 1; }
18
19my $warnings = '';
a9153838 20local $SIG{__WARN__} = sub { $warnings .= join '', @_ };
d020a79a 21
b1ddf169 22my $TB = Test::Builder->new;
23sub no_warnings {
24 $TB->is_eq($warnings, '', ' no warnings');
25 $warnings = '';
26}
27
28sub warnings_is {
29 $TB->is_eq($warnings, $_[0]);
30 $warnings = '';
31}
32
33sub warnings_like {
34 $TB->like($warnings, "/$_[0]/");
35 $warnings = '';
36}
37
38
39my $Filename = quotemeta $0;
40
41
d020a79a 42is( undef, undef, 'undef is undef');
b1ddf169 43no_warnings;
d020a79a 44
45isnt( undef, 'foo', 'undef isnt foo');
b1ddf169 46no_warnings;
d020a79a 47
a9153838 48isnt( undef, '', 'undef isnt an empty string' );
49isnt( undef, 0, 'undef isnt zero' );
50
b1ddf169 51#line 45
d020a79a 52like( undef, '/.*/', 'undef is like anything' );
b1ddf169 53warnings_like("Use of uninitialized value.* at $Filename line 45\\.\n");
d020a79a 54
55eq_array( [undef, undef], [undef, 23] );
b1ddf169 56no_warnings;
d020a79a 57
58eq_hash ( { foo => undef, bar => undef },
59 { foo => undef, bar => 23 } );
b1ddf169 60no_warnings;
d020a79a 61
62eq_set ( [undef, undef, 12], [29, undef, undef] );
b1ddf169 63no_warnings;
d020a79a 64
65
66eq_hash ( { foo => undef, bar => { baz => undef, moo => 23 } },
67 { foo => undef, bar => { baz => undef, moo => 23 } } );
b1ddf169 68no_warnings;
69
70
71#line 64
72cmp_ok( undef, '<=', 2, ' undef <= 2' );
73warnings_like("Use of uninitialized value.* at $Filename line 64\\.\n");
74
d020a79a 75
76
89c1e84a 77my $tb = Test::More->builder;
78
79use TieOut;
80my $caught = tie *CATCH, 'TieOut';
81my $old_fail = $tb->failure_output;
82$tb->failure_output(\*CATCH);
83diag(undef);
84$tb->failure_output($old_fail);
85
86is( $caught->read, "# undef\n" );
b1ddf169 87no_warnings;
0257f296 88
89
90$tb->maybe_regex(undef);
91is( $caught->read, '' );
b1ddf169 92no_warnings;