Commit | Line | Data |
---|---|---|
30e302f8 | 1 | #!perl -w |
ccbd73a4 | 2 | # $Id: /mirror/googlecode/test-more/t/harness_active.t 57943 2008-08-18T02:09:22.275428Z brooklyn.kid51 $ |
30e302f8 | 3 | |
4 | BEGIN { | |
5 | if( $ENV{PERL_CORE} ) { | |
6 | chdir 't'; | |
7 | @INC = ('../lib', 'lib'); | |
8 | } | |
9 | else { | |
10 | unshift @INC, 't/lib'; | |
11 | } | |
12 | } | |
13 | ||
14 | use strict; | |
15 | ||
16 | use Test::Simple::Catch; | |
17 | my($out, $err) = Test::Simple::Catch::caught(); | |
18 | ||
19 | ||
20 | # Can't use Test.pm, that's a 5.005 thing. | |
21 | package My::Test; | |
22 | ||
b1ddf169 | 23 | # This has to be a require or else the END block below runs before |
24 | # Test::Builder's own and the ending diagnostics don't come out right. | |
25 | require Test::Builder; | |
26 | my $TB = Test::Builder->create; | |
27 | $TB->plan(tests => 4); | |
30e302f8 | 28 | |
30e302f8 | 29 | # Utility testing functions. |
30 | sub ok ($;$) { | |
b1ddf169 | 31 | return $TB->ok(@_); |
30e302f8 | 32 | } |
33 | ||
34 | ||
0257f296 | 35 | sub main::err_ok ($) { |
30e302f8 | 36 | my($expect) = @_; |
37 | my $got = $err->read; | |
38 | ||
b1ddf169 | 39 | return $TB->is_eq( $got, $expect ); |
30e302f8 | 40 | } |
41 | ||
42 | ||
43 | package main; | |
44 | ||
45 | require Test::More; | |
46 | Test::More->import(tests => 4); | |
47 | Test::More->builder->no_ending(1); | |
48 | ||
49 | { | |
50 | local $ENV{HARNESS_ACTIVE} = 0; | |
51 | ||
52 | #line 62 | |
53 | fail( "this fails" ); | |
0257f296 | 54 | err_ok( <<ERR ); |
b1ddf169 | 55 | # Failed test 'this fails' |
b7f9bbeb | 56 | # at $0 line 62. |
30e302f8 | 57 | ERR |
58 | ||
59 | #line 72 | |
60 | is( 1, 0 ); | |
0257f296 | 61 | err_ok( <<ERR ); |
b7f9bbeb | 62 | # Failed test at $0 line 72. |
30e302f8 | 63 | # got: '1' |
64 | # expected: '0' | |
65 | ERR | |
66 | } | |
67 | ||
68 | { | |
69 | local $ENV{HARNESS_ACTIVE} = 1; | |
70 | ||
71 | #line 71 | |
72 | fail( "this fails" ); | |
0257f296 | 73 | err_ok( <<ERR ); |
30e302f8 | 74 | |
b1ddf169 | 75 | # Failed test 'this fails' |
b7f9bbeb | 76 | # at $0 line 71. |
30e302f8 | 77 | ERR |
78 | ||
79 | ||
80 | #line 84 | |
81 | is( 1, 0 ); | |
0257f296 | 82 | err_ok( <<ERR ); |
30e302f8 | 83 | |
b7f9bbeb | 84 | # Failed test at $0 line 84. |
30e302f8 | 85 | # got: '1' |
86 | # expected: '0' | |
87 | ERR | |
88 | ||
89 | } |