Commit | Line | Data |
3f2ec160 |
1 | use strict; |
2 | |
15db8fc4 |
3 | BEGIN { |
4 | chdir 't' if -d 't'; |
5 | @INC = '../lib'; |
6 | } |
7 | |
3f2ec160 |
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) = @_; |
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 | |
29 | package main; |
d020a79a |
30 | |
3f2ec160 |
31 | require Test::More; |
32 | |
15db8fc4 |
33 | push @INC, '../t/lib'; |
d020a79a |
34 | require Test::Simple::Catch::More; |
35 | my($out, $err) = Test::Simple::Catch::More::caught(); |
3f2ec160 |
36 | |
d020a79a |
37 | Test::More->import(tests => 10); |
3f2ec160 |
38 | |
d020a79a |
39 | # Preserve the line numbers. |
40 | #line 31 |
3f2ec160 |
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 | |
d020a79a |
50 | can_ok('Mooble::Hooble::Yooble', qw(this that)); |
51 | isa_ok(bless([], "Foo"), "Wibble"); |
52 | |
3f2ec160 |
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'); |
d020a79a |
58 | 1..10 |
3f2ec160 |
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() |
d020a79a |
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; |
3f2ec160 |
69 | OUT |
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 |
91 | ERR |
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 |
102 | ERR |
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 | } |