Test::Simple/More/Builder/Tutorial 0.41
[p5sagit/p5-mst-13.2.git] / lib / Test / Simple / t / fail.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 require 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..2\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
37
38 package main;
39
40 require Test::Simple;
41 Test::Simple->import(tests => 5);
42
43 #line 35
44 ok( 1, 'passing' );
45 ok( 2, 'passing still' );
46 ok( 3, 'still passing' );
47 ok( 0, 'oh no!' );
48 ok( 0, 'damnit' );
49
50
51 END {
52     My::Test::ok($$out eq <<OUT);
53 1..5
54 ok 1 - passing
55 ok 2 - passing still
56 ok 3 - still passing
57 not ok 4 - oh no!
58 not ok 5 - damnit
59 OUT
60
61     My::Test::ok($$err eq <<ERR);
62 #     Failed test ($0 at line 38)
63 #     Failed test ($0 at line 39)
64 # Looks like you failed 2 tests of 5.
65 ERR
66
67     # Prevent Test::Simple from exiting with non zero
68     exit 0;
69 }