1#!perl -w
2
3BEGIN {
4    if( $ENV{PERL_CORE} ) {
5        chdir 't';
6        @INC = ('../lib', 'lib');
7    }
8    else {
9        unshift @INC, 't/lib';
10    }
11}
12
13use strict;
14
15require Test::Simple::Catch;
16my($out, $err) = Test::Simple::Catch::caught();
17
18
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) = @_;
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;
34    $test_num++;
35
36    return $test;
37}
38
39
40package main;
41
42require Test::More;
43my $Total = 28;
44Test::More->import(tests => $Total);
45
46# Preserve the line numbers.
47#line 38
48ok( 0, 'failing' );
49
50#line 40
51is( "foo", "bar", 'foo is bar?');
52is( undef, '',    'undef is empty string?');
53is( undef, 0,     'undef is 0?');
54is( '',    0,     'empty string is 0?' );
55
56isnt("foo", "foo", 'foo isnt foo?' );
57isn't("foo", "foo",'foo isn\'t foo?' );
58
59like( "foo", '/that/',  'is foo like that' );
60unlike( "foo", '/foo/', 'is foo unlike foo' );
61
62# Nick Clark found this was a bug.  Fixed in 0.40.
63like( "bug", '/(%)/',   'regex with % in it' );
64
65fail('fail()');
66
67#line 52
68can_ok('Mooble::Hooble::Yooble', qw(this that));
69can_ok('Mooble::Hooble::Yooble', ());
70
71isa_ok(bless([], "Foo"), "Wibble");
72isa_ok(42,    "Wibble", "My Wibble");
73isa_ok(undef, "Wibble", "Another Wibble");
74isa_ok([],    "HASH");
75
76#line 68
77cmp_ok( 'foo', 'eq', 'bar', 'cmp_ok eq' );
78cmp_ok( 42.1,  '==', 23,  , '       ==' );
79cmp_ok( 42,    '!=', 42   , '       !=' );
80cmp_ok( 1,     '&&', 0    , '       &&' );
81cmp_ok( 42,    '==', "foo", '       == with strings' );
82cmp_ok( 42,    'eq', "foo", '       eq with numbers' );
83cmp_ok( undef, 'eq', 'foo', '       eq with undef' );
84
85# generate a $!, it changes its value by context.
86-e "wibblehibble";
87my $Errno_Number = $!+0;
88my $Errno_String = $!.'';
89cmp_ok( $!,    'eq', '',    '       eq with stringified errno' );
90cmp_ok( $!,    '==', -1,    '       eq with numerified errno' );
91
92#line 84
93use_ok('Hooble::mooble::yooble');
94require_ok('ALL::YOUR::BASE::ARE::BELONG::TO::US::wibble');
95
96#line 88
97END {
98    My::Test::ok($$out eq <<OUT, 'failing output');
991..$Total
100not ok 1 - failing
101not ok 2 - foo is bar?
102not ok 3 - undef is empty string?
103not ok 4 - undef is 0?
104not ok 5 - empty string is 0?
105not ok 6 - foo isnt foo?
106not ok 7 - foo isn't foo?
107not ok 8 - is foo like that
108not ok 9 - is foo unlike foo
109not ok 10 - regex with % in it
110not ok 11 - fail()
111not ok 12 - Mooble::Hooble::Yooble->can(...)
112not ok 13 - Mooble::Hooble::Yooble->can(...)
113not ok 14 - The object isa Wibble
114not ok 15 - My Wibble isa Wibble
115not ok 16 - Another Wibble isa Wibble
116not ok 17 - The object isa HASH
117not ok 18 - cmp_ok eq
118not ok 19 -        ==
119not ok 20 -        !=
120not ok 21 -        &&
121not ok 22 -        == with strings
122not ok 23 -        eq with numbers
123not ok 24 -        eq with undef
124not ok 25 -        eq with stringified errno
125not ok 26 -        eq with numerified errno
126not ok 27 - use Hooble::mooble::yooble;
127not ok 28 - require ALL::YOUR::BASE::ARE::BELONG::TO::US::wibble;
128OUT
129
130    my $err_re = <<ERR;
131#     Failed test ($0 at line 38)
132#     Failed test ($0 at line 40)
133#          got: 'foo'
134#     expected: 'bar'
135#     Failed test ($0 at line 41)
136#          got: undef
137#     expected: ''
138#     Failed test ($0 at line 42)
139#          got: undef
140#     expected: '0'
141#     Failed test ($0 at line 43)
142#          got: ''
143#     expected: '0'
144#     Failed test ($0 at line 45)
145#     'foo'
146#         ne
147#     'foo'
148#     Failed test ($0 at line 46)
149#     'foo'
150#         ne
151#     'foo'
152#     Failed test ($0 at line 48)
153#                   'foo'
154#     doesn't match '/that/'
155#     Failed test ($0 at line 49)
156#                   'foo'
157#           matches '/foo/'
158#     Failed test ($0 at line 52)
159#                   'bug'
160#     doesn't match '/(%)/'
161#     Failed test ($0 at line 54)
162#     Failed test ($0 at line 52)
163#     Mooble::Hooble::Yooble->can('this') failed
164#     Mooble::Hooble::Yooble->can('that') failed
165#     Failed test ($0 at line 53)
166#     can_ok() called with no methods
167#     Failed test ($0 at line 55)
168#     The object isn't a 'Wibble' it's a 'Foo'
169#     Failed test ($0 at line 56)
170#     My Wibble isn't a reference
171#     Failed test ($0 at line 57)
172#     Another Wibble isn't defined
173#     Failed test ($0 at line 58)
174#     The object isn't a 'HASH' it's a 'ARRAY'
175#     Failed test ($0 at line 68)
176#          got: 'foo'
177#     expected: 'bar'
178#     Failed test ($0 at line 69)
179#          got: 42.1
180#     expected: 23
181#     Failed test ($0 at line 70)
182#     '42'
183#         !=
184#     '42'
185#     Failed test ($0 at line 71)
186#     '1'
187#         &&
188#     '0'
189#     Failed test ($0 at line 72)
190#          got: 42
191#     expected: 0
192#     Failed test ($0 at line 73)
193#          got: '42'
194#     expected: 'foo'
195#     Failed test ($0 at line 74)
196#          got: undef
197#     expected: 'foo'
198#     Failed test ($0 at line 80)
199#          got: '$Errno_String'
200#     expected: ''
201#     Failed test ($0 at line 81)
202#          got: $Errno_Number
203#     expected: -1
204ERR
205
206   my $filename = quotemeta $0;
207   my $more_err_re = <<ERR;
208#     Failed test \\($filename at line 84\\)
209#     Tried to use 'Hooble::mooble::yooble'.
210#     Error:  Can't locate Hooble.* in \\\@INC .*
211#     Failed test \\($filename at line 85\\)
212#     Tried to require 'ALL::YOUR::BASE::ARE::BELONG::TO::US::wibble'.
213#     Error:  Can't locate ALL.* in \\\@INC .*
214# Looks like you failed $Total tests of $Total.
215ERR
216
217    unless( My::Test::ok($$err =~ /^\Q$err_re\E$more_err_re$/, 
218                         'failing errors') ) {
219        print $$err;
220    }
221
222    exit(0);
223}
224