Upgrade to Test::Simple 0.54
[p5sagit/p5-mst-13.2.git] / lib / Test / Simple / t / harness_active.t
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
40 sub main::err_ok ($) {
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" );
66     err_ok( <<ERR );
67 #     Failed test ($0 at line 62)
68 ERR
69
70 #line 72
71     is( 1, 0 );
72     err_ok( <<ERR );
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" );
84     err_ok( <<ERR );
85
86 #     Failed test ($0 at line 71)
87 ERR
88
89
90 #line 84
91     is( 1, 0 );
92     err_ok( <<ERR );
93
94 #     Failed test ($0 at line 84)
95 #          got: '1'
96 #     expected: '0'
97 ERR
98
99 }