Upgrade to Test::Simple 0.54
[p5sagit/p5-mst-13.2.git] / lib / Test / Simple / t / harness_active.t
CommitLineData
30e302f8 1#!perl -w
2
3BEGIN {
4 if( $ENV{PERL_CORE} ) {
5 chdir 't';
6 @INC = ('../lib', 'lib');
7 }
8 else {
9 unshift @INC, 't/lib';
10 }
11}
12
13use strict;
14
15use Test::Simple::Catch;
16my($out, $err) = Test::Simple::Catch::caught();
17
18
19# Can't use Test.pm, that's a 5.005 thing.
20package My::Test;
21
22print "1..4\n";
23
24my $test_num = 1;
25# Utility testing functions.
26sub 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 40sub 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
55package main;
56
57require Test::More;
58Test::More->import(tests => 4);
59Test::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)
68ERR
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'
76ERR
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)
87ERR
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'
97ERR
98
99}