Commit | Line | Data |
---|---|---|
3f2ec160 JH |
1 | use strict; |
2 | ||
3 | # Can't use Test.pm, that's a 5.005 thing. | |
4 | package My::Test; | |
5 | ||
6 | print "1..2\n"; | |
7 | ||
8 | my $test_num = 1; | |
9 | # Utility testing functions. | |
10 | sub ok ($;$) { | |
11 | my($test, $name) = @_; | |
12 | print "not " unless $test; | |
13 | print "ok $test_num"; | |
14 | print " - $name" if defined $name; | |
15 | print "\n"; | |
16 | $test_num++; | |
17 | } | |
18 | ||
19 | ||
20 | package main; | |
21 | require Test::More; | |
22 | ||
23 | push @INC, 'lib/Test/More/'; | |
24 | require Catch; | |
25 | my($out, $err) = Catch::caught(); | |
26 | ||
27 | Test::More->import(tests => 8); | |
28 | ||
29 | ok( 0, 'failing' ); | |
30 | is( "foo", "bar", 'foo is bar?'); | |
31 | isnt("foo", "foo", 'foo isnt foo?' ); | |
32 | isn't("foo", "foo",'foo isn\'t foo?' ); | |
33 | ||
34 | like( "foo", '/that/', 'is foo like that' ); | |
35 | ||
36 | fail('fail()'); | |
37 | ||
38 | use_ok('Hooble::mooble::yooble'); | |
39 | require_ok('ALL::YOUR::BASE::ARE::BELONG::TO::US::wibble'); | |
40 | ||
41 | END { | |
42 | My::Test::ok($$out eq <<OUT, 'failing output'); | |
43 | 1..8 | |
44 | not ok 1 - failing | |
45 | not ok 2 - foo is bar? | |
46 | not ok 3 - foo isnt foo? | |
47 | not ok 4 - foo isn't foo? | |
48 | not ok 5 - is foo like that | |
49 | not ok 6 - fail() | |
50 | not ok 7 - use Hooble::mooble::yooble; | |
51 | not ok 8 - require ALL::YOUR::BASE::ARE::BELONG::TO::US::wibble; | |
52 | OUT | |
53 | ||
54 | my $err_re = <<ERR; | |
55 | # Failed test ($0 at line 29) | |
56 | # Failed test ($0 at line 30) | |
57 | # got: 'foo' | |
58 | # expected: 'bar' | |
59 | # Failed test ($0 at line 31) | |
60 | # it should not be 'foo' | |
61 | # but it is. | |
62 | # Failed test ($0 at line 32) | |
63 | # it should not be 'foo' | |
64 | # but it is. | |
65 | # Failed test ($0 at line 34) | |
66 | # 'foo' | |
67 | # doesn't match '/that/' | |
68 | # Failed test ($0 at line 36) | |
69 | ERR | |
70 | ||
71 | my $more_err_re = <<ERR; | |
72 | # Failed test \\($0 at line 38\\) | |
73 | # Tried to use 'Hooble::mooble::yooble'. | |
74 | # Error: Can't locate Hooble.* in \\\@INC .* | |
75 | ||
76 | # Failed test \\($0 at line 39\\) | |
77 | # Tried to require 'ALL::YOUR::BASE::ARE::BELONG::TO::US::wibble'. | |
78 | # Error: Can't locate ALL.* in \\\@INC .* | |
79 | ||
80 | # Looks like you failed 8 tests of 8. | |
81 | ERR | |
82 | ||
83 | My::Test::ok($$err =~ /^\Q$err_re\E$more_err_re$/, 'failing errors'); | |
84 | ||
85 | exit(0); | |
86 | } |