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