This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Integrate:
[perl5.git] / lib / Test / Simple / t / undef.t
1 #!/usr/bin/perl -w
2
3 BEGIN {
4     if( $ENV{PERL_CORE} ) {
5         chdir 't';
6         @INC = ('../lib', 'lib');
7     }
8     else {
9         unshift @INC, 't/lib';
10     }
11 }
12
13 use strict;
14 use Test::More tests => 16;
15 use TieOut;
16
17 BEGIN { $^W = 1; }
18
19 my $warnings = '';
20 local $SIG{__WARN__} = sub { $warnings .= join '', @_ };
21
22 is( undef, undef,           'undef is undef');
23 is( $warnings, '',          '  no warnings' );
24
25 isnt( undef, 'foo',         'undef isnt foo');
26 is( $warnings, '',          '  no warnings' );
27
28 isnt( undef, '',            'undef isnt an empty string' );
29 isnt( undef, 0,             'undef isnt zero' );
30
31 like( undef, '/.*/',        'undef is like anything' );
32 is( $warnings, '',          '  no warnings' );
33
34 eq_array( [undef, undef], [undef, 23] );
35 is( $warnings, '',          'eq_array()  no warnings' );
36
37 eq_hash ( { foo => undef, bar => undef },
38           { foo => undef, bar => 23 } );
39 is( $warnings, '',          'eq_hash()   no warnings' );
40
41 eq_set  ( [undef, undef, 12], [29, undef, undef] );
42 is( $warnings, '',          'eq_set()    no warnings' );
43
44
45 eq_hash ( { foo => undef, bar => { baz => undef, moo => 23 } },
46           { foo => undef, bar => { baz => undef, moo => 23 } } );
47 is( $warnings, '',          'eq_hash()   no warnings' );
48
49
50 my $tb = Test::More->builder;
51
52 use TieOut;
53 my $caught = tie *CATCH, 'TieOut';
54 my $old_fail = $tb->failure_output;
55 $tb->failure_output(\*CATCH);
56 diag(undef);
57 $tb->failure_output($old_fail);
58
59 is( $caught->read, "# undef\n" );
60 is( $warnings, '',          'diag(undef)  no warnings' );
61
62
63 $tb->maybe_regex(undef);
64 is( $caught->read, '' );
65 is( $warnings, '',          'maybe_regex(undef) no warnings' );