Test::Simple/More/Builder/Tutorial 0.41
[p5sagit/p5-mst-13.2.git] / lib / Test / Simple / t / fail.t
CommitLineData
33459055 1#!perl -w
4dd974da 2
15db8fc4 3BEGIN {
a9153838 4 if( $ENV{PERL_CORE} ) {
5 chdir 't';
6 @INC = ('../lib', 'lib');
7 }
8 else {
9 unshift @INC, 't/lib';
10 }
15db8fc4 11}
12
33459055 13use strict;
33459055 14
15require Test::Simple::Catch;
16my($out, $err) = Test::Simple::Catch::caught();
17
18
4dd974da 19# Can't use Test.pm, that's a 5.005 thing.
20package My::Test;
21
22print "1..2\n";
23
24my $test_num = 1;
25# Utility testing functions.
26sub ok ($;$) {
27 my($test, $name) = @_;
11ea77c5 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;
4dd974da 34 $test_num++;
35}
36
37
38package main;
39
40require Test::Simple;
4dd974da 41Test::Simple->import(tests => 5);
42
33459055 43#line 35
4dd974da 44ok( 1, 'passing' );
45ok( 2, 'passing still' );
46ok( 3, 'still passing' );
47ok( 0, 'oh no!' );
48ok( 0, 'damnit' );
49
50
51END {
52 My::Test::ok($$out eq <<OUT);
531..5
54ok 1 - passing
55ok 2 - passing still
56ok 3 - still passing
57not ok 4 - oh no!
58not ok 5 - damnit
59OUT
60
33459055 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.
65ERR
4dd974da 66
67 # Prevent Test::Simple from exiting with non zero
68 exit 0;
69}