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