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