Commit | Line | Data |
30e302f8 |
1 | #!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 | |
15 | use Test::Simple::Catch; |
16 | my($out, $err) = Test::Simple::Catch::caught(); |
17 | |
18 | |
19 | # Can't use Test.pm, that's a 5.005 thing. |
20 | package My::Test; |
21 | |
22 | print "1..4\n"; |
23 | |
24 | my $test_num = 1; |
25 | # Utility testing functions. |
26 | sub ok ($;$) { |
27 | my($test, $name) = @_; |
28 | my $ok = ''; |
29 | $ok .= "not " unless $test; |
30 | $ok .= "ok $test_num"; |
31 | $ok .= " - $name" if defined $name; |
32 | $ok .= "\n"; |
33 | print $ok; |
34 | $test_num++; |
35 | |
36 | return $test; |
37 | } |
38 | |
39 | |
0257f296 |
40 | sub main::err_ok ($) { |
30e302f8 |
41 | my($expect) = @_; |
42 | my $got = $err->read; |
43 | |
44 | my $ok = ok( $got eq $expect ); |
45 | |
46 | unless( $ok ) { |
47 | print STDERR "got\n$got\n"; |
48 | print STDERR "expected\n$expect\n"; |
49 | } |
50 | |
51 | return $ok; |
52 | } |
53 | |
54 | |
55 | package main; |
56 | |
57 | require Test::More; |
58 | Test::More->import(tests => 4); |
59 | Test::More->builder->no_ending(1); |
60 | |
61 | { |
62 | local $ENV{HARNESS_ACTIVE} = 0; |
63 | |
64 | #line 62 |
65 | fail( "this fails" ); |
0257f296 |
66 | err_ok( <<ERR ); |
30e302f8 |
67 | # Failed test ($0 at line 62) |
68 | ERR |
69 | |
70 | #line 72 |
71 | is( 1, 0 ); |
0257f296 |
72 | err_ok( <<ERR ); |
30e302f8 |
73 | # Failed test ($0 at line 72) |
74 | # got: '1' |
75 | # expected: '0' |
76 | ERR |
77 | } |
78 | |
79 | { |
80 | local $ENV{HARNESS_ACTIVE} = 1; |
81 | |
82 | #line 71 |
83 | fail( "this fails" ); |
0257f296 |
84 | err_ok( <<ERR ); |
30e302f8 |
85 | |
86 | # Failed test ($0 at line 71) |
87 | ERR |
88 | |
89 | |
90 | #line 84 |
91 | is( 1, 0 ); |
0257f296 |
92 | err_ok( <<ERR ); |
30e302f8 |
93 | |
94 | # Failed test ($0 at line 84) |
95 | # got: '1' |
96 | # expected: '0' |
97 | ERR |
98 | |
99 | } |