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 my $tb = Test::More->builder;
54 my $Filename = quotemeta $0;
56 # Preserve the line numbers.
60 # Failed test 'failing'
65 is( "foo", "bar", 'foo is bar?');
66 is( undef, '', 'undef is empty string?');
67 is( undef, 0, 'undef is 0?');
68 is( '', 0, 'empty string is 0?' );
70 # Failed test 'foo is bar?'
74 # Failed test 'undef is empty string?'
78 # Failed test 'undef is 0?'
82 # Failed test 'empty string is 0?'
89 isnt("foo", "foo", 'foo isnt foo?' );
90 isn't("foo", "foo",'foo isn\'t foo?' );
91 isnt(undef, undef, 'undef isnt undef?');
93 # Failed test 'foo isnt foo?'
98 # Failed test 'foo isn\'t foo?'
103 # Failed test 'undef isnt undef?'
111 like( "foo", '/that/', 'is foo like that' );
112 unlike( "foo", '/foo/', 'is foo unlike foo' );
114 # Failed test 'is foo like that'
117 # doesn't match '/that/'
118 # Failed test 'is foo unlike foo'
124 # Nick Clark found this was a bug. Fixed in 0.40.
126 like( "bug", '/(%)/', 'regex with % in it' );
128 # Failed test 'regex with % in it'
131 # doesn't match '/(%)/'
137 # Failed test 'fail()'
142 can_ok('Mooble::Hooble::Yooble', qw(this that));
143 can_ok('Mooble::Hooble::Yooble', ());
144 can_ok(undef, undef);
146 # Failed test 'Mooble::Hooble::Yooble->can(...)'
148 # Mooble::Hooble::Yooble->can('this') failed
149 # Mooble::Hooble::Yooble->can('that') failed
150 # Failed test 'Mooble::Hooble::Yooble->can(...)'
152 # can_ok() called with no methods
153 # Failed test '->can(...)'
155 # can_ok() called with empty class or reference
159 isa_ok(bless([], "Foo"), "Wibble");
160 isa_ok(42, "Wibble", "My Wibble");
161 isa_ok(undef, "Wibble", "Another Wibble");
164 # Failed test 'The object isa Wibble'
166 # The object isn't a 'Wibble' it's a 'Foo'
167 # Failed test 'My Wibble isa Wibble'
169 # My Wibble isn't a reference
170 # Failed test 'Another Wibble isa Wibble'
172 # Another Wibble isn't defined
173 # Failed test 'The object isa HASH'
175 # The object isn't a 'HASH' it's a 'ARRAY'
179 cmp_ok( 'foo', 'eq', 'bar', 'cmp_ok eq' );
180 cmp_ok( 42.1, '==', 23, , ' ==' );
181 cmp_ok( 42, '!=', 42 , ' !=' );
182 cmp_ok( 1, '&&', 0 , ' &&' );
184 # Failed test 'cmp_ok eq'
206 cmp_ok( 42, 'eq', "foo", ' eq with numbers' );
208 # Failed test ' eq with numbers'
217 local $SIG{__WARN__} = sub { $warnings .= join '', @_ };
220 cmp_ok( 42, '==', "foo", ' == with strings' );
222 # Failed test ' == with strings'
227 My::Test::like $warnings,
228 qq[/^Argument "foo" isn't numeric in .* at $Filename line 211\\\.\n\$/];
233 # generate a $!, it changes its value by context.
235 my $Errno_Number = $!+0;
236 my $Errno_String = $!.'';
238 cmp_ok( $!, 'eq', '', ' eq with stringified errno' );
239 cmp_ok( $!, '==', -1, ' eq with numerified errno' );
241 # Failed test ' eq with stringified errno'
243 # got: '$Errno_String'
245 # Failed test ' eq with numerified errno'
252 use_ok('Hooble::mooble::yooble');
254 my $more_err_re = <<ERR;
255 # Failed test 'use Hooble::mooble::yooble;'
256 # in $Filename at line 84\\.
257 # Tried to use 'Hooble::mooble::yooble'.
258 # Error: Can't locate Hooble.* in \\\@INC .*
259 # BEGIN failed--compilation aborted at $Filename line 84.
262 My::Test::like($err->read, "/^$more_err_re/");
266 require_ok('ALL::YOUR::BASE::ARE::BELONG::TO::US::wibble');
267 $more_err_re = <<ERR;
268 # Failed test 'require ALL::YOUR::BASE::ARE::BELONG::TO::US::wibble;'
269 # in $Filename at line 85\\.
270 # Tried to require 'ALL::YOUR::BASE::ARE::BELONG::TO::US::wibble'.
271 # Error: Can't locate ALL.* in \\\@INC .*
274 My::Test::like($err->read, "/^$more_err_re/");
279 $TB->is_eq($$out, <<OUT, 'failing output');
283 not ok - undef is empty string?
285 not ok - empty string is 0?
286 not ok - foo isnt foo?
287 not ok - foo isn't foo?
288 not ok - undef isnt undef?
289 not ok - is foo like that
290 not ok - is foo unlike foo
291 not ok - regex with % in it
293 not ok - Mooble::Hooble::Yooble->can(...)
294 not ok - Mooble::Hooble::Yooble->can(...)
296 not ok - The object isa Wibble
297 not ok - My Wibble isa Wibble
298 not ok - Another Wibble isa Wibble
299 not ok - The object isa HASH
304 not ok - eq with numbers
305 not ok - == with strings
306 not ok - eq with stringified errno
307 not ok - eq with numerified errno
308 not ok - use Hooble::mooble::yooble;
309 not ok - require ALL::YOUR::BASE::ARE::BELONG::TO::US::wibble;
313 # Looks like you failed $Total tests of $Total.