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