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.
23 # This has to be a require or else the END block below runs before
24 # Test::Builder's own and the ending diagnostics don't come out right.
25 require Test::Builder;
26 my $TB = Test::Builder->create;
27 $TB->plan(tests => 17);
37 sub main::err_ok ($) {
41 return $TB->is_eq( $got, $expect );
49 Test::More->import(tests => $Total);
51 # This should all work in the presence of a __DIE__ handler.
52 local $SIG{__DIE__} = sub { $TB->ok(0, "DIE handler called: ".join "", @_); };
55 my $tb = Test::More->builder;
58 my $Filename = quotemeta $0;
60 # Preserve the line numbers.
64 # Failed test 'failing'
69 is( "foo", "bar", 'foo is bar?');
70 is( undef, '', 'undef is empty string?');
71 is( undef, 0, 'undef is 0?');
72 is( '', 0, 'empty string is 0?' );
74 # Failed test 'foo is bar?'
78 # Failed test 'undef is empty string?'
82 # Failed test 'undef is 0?'
86 # Failed test 'empty string is 0?'
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 'foo isnt foo?'
102 # Failed test 'foo isn\'t foo?'
107 # Failed test 'undef isnt undef?'
115 like( "foo", '/that/', 'is foo like that' );
116 unlike( "foo", '/foo/', 'is foo unlike foo' );
118 # Failed test 'is foo like that'
121 # doesn't match '/that/'
122 # Failed test 'is foo unlike foo'
128 # Nick Clark found this was a bug. Fixed in 0.40.
130 like( "bug", '/(%)/', 'regex with % in it' );
132 # Failed test 'regex with % in it'
135 # doesn't match '/(%)/'
141 # Failed test 'fail()'
146 can_ok('Mooble::Hooble::Yooble', qw(this that));
147 can_ok('Mooble::Hooble::Yooble', ());
148 can_ok(undef, undef);
151 # Failed test 'Mooble::Hooble::Yooble->can(...)'
153 # Mooble::Hooble::Yooble->can('this') failed
154 # Mooble::Hooble::Yooble->can('that') failed
155 # Failed test 'Mooble::Hooble::Yooble->can(...)'
157 # can_ok() called with no methods
158 # Failed test '->can(...)'
160 # can_ok() called with empty class or reference
161 # Failed test 'ARRAY->can('foo')'
163 # ARRAY->can('foo') failed
167 isa_ok(bless([], "Foo"), "Wibble");
168 isa_ok(42, "Wibble", "My Wibble");
169 isa_ok(undef, "Wibble", "Another Wibble");
172 # Failed test 'The object isa Wibble'
174 # The object isn't a 'Wibble' it's a 'Foo'
175 # Failed test 'My Wibble isa Wibble'
177 # My Wibble isn't a reference
178 # Failed test 'Another Wibble isa Wibble'
180 # Another Wibble isn't defined
181 # Failed test 'The object isa HASH'
183 # The object isn't a 'HASH' it's a 'ARRAY'
187 cmp_ok( 'foo', 'eq', 'bar', 'cmp_ok eq' );
188 cmp_ok( 42.1, '==', 23, , ' ==' );
189 cmp_ok( 42, '!=', 42 , ' !=' );
190 cmp_ok( 1, '&&', 0 , ' &&' );
192 # Failed test 'cmp_ok eq'
214 cmp_ok( 42, 'eq', "foo", ' eq with numbers' );
216 # Failed test ' eq with numbers'
225 local $SIG{__WARN__} = sub { $warnings .= join '', @_ };
228 cmp_ok( 42, '==', "foo", ' == with strings' );
230 # Failed test ' == with strings'
235 My::Test::like $warnings,
236 qq[/^Argument "foo" isn't numeric in .* at $Filename line 211\\\.\n\$/];
241 # generate a $!, it changes its value by context.
243 my $Errno_Number = $!+0;
244 my $Errno_String = $!.'';
246 cmp_ok( $!, 'eq', '', ' eq with stringified errno' );
247 cmp_ok( $!, '==', -1, ' eq with numerified errno' );
249 # Failed test ' eq with stringified errno'
251 # got: '$Errno_String'
253 # Failed test ' eq with numerified errno'
260 use_ok('Hooble::mooble::yooble');
262 my $more_err_re = <<ERR;
263 # Failed test 'use Hooble::mooble::yooble;'
264 # at $Filename line 84\\.
265 # Tried to use 'Hooble::mooble::yooble'.
266 # Error: Can't locate Hooble.* in \\\@INC .*
269 My::Test::like($err->read, "/^$more_err_re/");
273 require_ok('ALL::YOUR::BASE::ARE::BELONG::TO::US::wibble');
274 $more_err_re = <<ERR;
275 # Failed test 'require ALL::YOUR::BASE::ARE::BELONG::TO::US::wibble;'
276 # at $Filename line 85\\.
277 # Tried to require 'ALL::YOUR::BASE::ARE::BELONG::TO::US::wibble'.
278 # Error: Can't locate ALL.* in \\\@INC .*
281 My::Test::like($err->read, "/^$more_err_re/");
286 $TB->is_eq($$out, <<OUT, 'failing output');
290 not ok - undef is empty string?
292 not ok - empty string is 0?
293 not ok - foo isnt foo?
294 not ok - foo isn't foo?
295 not ok - undef isnt undef?
296 not ok - is foo like that
297 not ok - is foo unlike foo
298 not ok - regex with % in it
300 not ok - Mooble::Hooble::Yooble->can(...)
301 not ok - Mooble::Hooble::Yooble->can(...)
303 not ok - ARRAY->can('foo')
304 not ok - The object isa Wibble
305 not ok - My Wibble isa Wibble
306 not ok - Another Wibble isa Wibble
307 not ok - The object isa HASH
312 not ok - eq with numbers
313 not ok - == with strings
314 not ok - eq with stringified errno
315 not ok - eq with numerified errno
316 not ok - use Hooble::mooble::yooble;
317 not ok - require ALL::YOUR::BASE::ARE::BELONG::TO::US::wibble;
321 # Looks like you failed $Total tests of $Total.