4 if( $ENV{PERL_CORE} ) {
6 @INC = ('../lib', 'lib');
15 require Test::Simple::Catch;
16 my($out, $err) = Test::Simple::Catch::caught();
17 local $ENV{HARNESS_ACTIVE} = 0;
20 # Can't use Test.pm, that's a 5.005 thing.
26 # Utility testing functions.
28 my($test, $name) = @_;
30 $ok .= "not " unless $test;
31 $ok .= "ok $test_num";
32 $ok .= " - $name" if defined $name;
45 my $ok = ok( $got eq $expect );
48 print STDERR "$got\n";
49 print STDERR "$expect\n";
60 Test::More->import(tests => $Total);
62 my $tb = Test::More->builder;
65 # Preserve the line numbers.
69 # Failed test ($0 at line 38)
73 is( "foo", "bar", 'foo is bar?');
74 is( undef, '', 'undef is empty string?');
75 is( undef, 0, 'undef is 0?');
76 is( '', 0, 'empty string is 0?' );
78 # Failed test ($0 at line 40)
81 # Failed test ($0 at line 41)
84 # Failed test ($0 at line 42)
87 # Failed test ($0 at line 43)
93 isnt("foo", "foo", 'foo isnt foo?' );
94 isn't("foo", "foo",'foo isn\'t foo?' );
95 isnt(undef, undef, 'undef isnt undef?');
97 # Failed test ($0 at line 45)
101 # Failed test ($0 at line 46)
105 # Failed test ($0 at line 47)
112 like( "foo", '/that/', 'is foo like that' );
113 unlike( "foo", '/foo/', 'is foo unlike foo' );
115 # Failed test ($0 at line 48)
117 # doesn't match '/that/'
118 # Failed test ($0 at line 49)
123 # Nick Clark found this was a bug. Fixed in 0.40.
124 like( "bug", '/(%)/', 'regex with % in it' );
126 # Failed test ($0 at line 60)
128 # doesn't match '/(%)/'
133 # Failed test ($0 at line 67)
137 can_ok('Mooble::Hooble::Yooble', qw(this that));
138 can_ok('Mooble::Hooble::Yooble', ());
140 # Failed test ($0 at line 52)
141 # Mooble::Hooble::Yooble->can('this') failed
142 # Mooble::Hooble::Yooble->can('that') failed
143 # Failed test ($0 at line 53)
144 # can_ok() called with no methods
148 isa_ok(bless([], "Foo"), "Wibble");
149 isa_ok(42, "Wibble", "My Wibble");
150 isa_ok(undef, "Wibble", "Another Wibble");
153 # Failed test ($0 at line 55)
154 # The object isn't a 'Wibble' it's a 'Foo'
155 # Failed test ($0 at line 56)
156 # My Wibble isn't a reference
157 # Failed test ($0 at line 57)
158 # Another Wibble isn't defined
159 # Failed test ($0 at line 58)
160 # The object isn't a 'HASH' it's a 'ARRAY'
164 cmp_ok( 'foo', 'eq', 'bar', 'cmp_ok eq' );
165 cmp_ok( 42.1, '==', 23, , ' ==' );
166 cmp_ok( 42, '!=', 42 , ' !=' );
167 cmp_ok( 1, '&&', 0 , ' &&' );
168 cmp_ok( 42, '==', "foo", ' == with strings' );
169 cmp_ok( 42, 'eq', "foo", ' eq with numbers' );
170 cmp_ok( undef, 'eq', 'foo', ' eq with undef' );
172 # Failed test ($0 at line 68)
175 # Failed test ($0 at line 69)
178 # Failed test ($0 at line 70)
182 # Failed test ($0 at line 71)
186 # Failed test ($0 at line 72)
189 # Failed test ($0 at line 73)
192 # Failed test ($0 at line 74)
197 # generate a $!, it changes its value by context.
199 my $Errno_Number = $!+0;
200 my $Errno_String = $!.'';
202 cmp_ok( $!, 'eq', '', ' eq with stringified errno' );
203 cmp_ok( $!, '==', -1, ' eq with numerified errno' );
205 # Failed test ($0 at line 80)
206 # got: '$Errno_String'
208 # Failed test ($0 at line 81)
214 use_ok('Hooble::mooble::yooble');
215 require_ok('ALL::YOUR::BASE::ARE::BELONG::TO::US::wibble');
219 My::Test::ok($$out eq <<OUT, 'failing output');
223 not ok - undef is empty string?
225 not ok - empty string is 0?
226 not ok - foo isnt foo?
227 not ok - foo isn't foo?
228 not ok - undef isnt undef?
229 not ok - is foo like that
230 not ok - is foo unlike foo
231 not ok - regex with % in it
233 not ok - Mooble::Hooble::Yooble->can(...)
234 not ok - Mooble::Hooble::Yooble->can(...)
235 not ok - The object isa Wibble
236 not ok - My Wibble isa Wibble
237 not ok - Another Wibble isa Wibble
238 not ok - The object isa HASH
243 not ok - == with strings
244 not ok - eq with numbers
245 not ok - eq with undef
246 not ok - eq with stringified errno
247 not ok - eq with numerified errno
248 not ok - use Hooble::mooble::yooble;
249 not ok - require ALL::YOUR::BASE::ARE::BELONG::TO::US::wibble;
252 my $filename = quotemeta $0;
253 my $more_err_re = <<ERR;
254 # Failed test \\($filename at line 84\\)
255 # Tried to use 'Hooble::mooble::yooble'.
256 # Error: Can't locate Hooble.* in \\\@INC .*
257 # BEGIN failed--compilation aborted at $filename line 84.
258 # Failed test \\($filename at line 85\\)
259 # Tried to require 'ALL::YOUR::BASE::ARE::BELONG::TO::US::wibble'.
260 # Error: Can't locate ALL.* in \\\@INC .*
261 # Looks like you failed $Total tests of $Total.
264 unless( My::Test::ok($$err =~ /^$more_err_re$/,
265 'failing errors') ) {