[PATCH] Syncing with Test::Simple 0.19
[p5sagit/p5-mst-13.2.git] / lib / Test / Simple / t / fail-more.t
1 use strict;
2
3 BEGIN {
4     chdir 't' if -d 't';
5     @INC = '../lib';
6 }
7
8 # Can't use Test.pm, that's a 5.005 thing.
9 package My::Test;
10
11 print "1..2\n";
12
13 my $test_num = 1;
14 # Utility testing functions.
15 sub ok ($;$) {
16     my($test, $name) = @_;
17     my $ok = '';
18     $ok .= "not " unless $test;
19     $ok .= "ok $test_num";
20     $ok .= " - $name" if defined $name;
21     $ok .= "\n";
22     print $ok;
23     $test_num++;
24
25     return $test;
26 }
27
28
29 package main;
30
31 require Test::More;
32
33 push @INC, '../t/lib';
34 require Test::Simple::Catch::More;
35 my($out, $err) = Test::Simple::Catch::More::caught();
36
37 Test::More->import(tests => 10);
38
39 # Preserve the line numbers.
40 #line 31
41 ok( 0, 'failing' );
42 is(  "foo", "bar", 'foo is bar?');
43 isnt("foo", "foo", 'foo isnt foo?' );
44 isn't("foo", "foo",'foo isn\'t foo?' );
45
46 like( "foo", '/that/',  'is foo like that' );
47
48 fail('fail()');
49
50 can_ok('Mooble::Hooble::Yooble', qw(this that));
51 isa_ok(bless([], "Foo"), "Wibble");
52
53 use_ok('Hooble::mooble::yooble');
54 require_ok('ALL::YOUR::BASE::ARE::BELONG::TO::US::wibble');
55
56 END {
57     My::Test::ok($$out eq <<OUT, 'failing output');
58 1..10
59 not ok 1 - failing
60 not ok 2 - foo is bar?
61 not ok 3 - foo isnt foo?
62 not ok 4 - foo isn't foo?
63 not ok 5 - is foo like that
64 not ok 6 - fail()
65 not ok 7 - Mooble::Hooble::Yooble->can(...)
66 not ok 8 - object->isa('Wibble')
67 not ok 9 - use Hooble::mooble::yooble;
68 not ok 10 - require ALL::YOUR::BASE::ARE::BELONG::TO::US::wibble;
69 OUT
70
71     my $err_re = <<ERR;
72 #     Failed test ($0 at line 31)
73 #     Failed test ($0 at line 32)
74 #          got: 'foo'
75 #     expected: 'bar'
76 #     Failed test ($0 at line 33)
77 #     it should not be 'foo'
78 #     but it is.
79 #     Failed test ($0 at line 34)
80 #     it should not be 'foo'
81 #     but it is.
82 #     Failed test ($0 at line 36)
83 #                   'foo'
84 #     doesn't match '/that/'
85 #     Failed test ($0 at line 38)
86 #     Failed test ($0 at line 40)
87 #     Mooble::Hooble::Yooble->can('this') failed
88 #     Mooble::Hooble::Yooble->can('that') failed
89 #     Failed test ($0 at line 41)
90 #     The object isn't a 'Wibble'
91 ERR
92
93    my $filename = quotemeta $0;
94    my $more_err_re = <<ERR;
95 #     Failed test \\($filename at line 43\\)
96 #     Tried to use 'Hooble::mooble::yooble'.
97 #     Error:  Can't locate Hooble.* in \\\@INC .*
98 #     Failed test \\($filename at line 44\\)
99 #     Tried to require 'ALL::YOUR::BASE::ARE::BELONG::TO::US::wibble'.
100 #     Error:  Can't locate ALL.* in \\\@INC .*
101 # Looks like you failed 10 tests of 10.
102 ERR
103
104     unless( My::Test::ok($$err =~ /^\Q$err_re\E$more_err_re$/, 
105                          'failing errors') ) {
106         print map "# $_", $$err;
107     }
108
109     exit(0);
110 }