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', ());
145 # Failed test 'Mooble::Hooble::Yooble->can(...)'
147 # Mooble::Hooble::Yooble->can('this') failed
148 # Mooble::Hooble::Yooble->can('that') failed
149 # Failed test 'Mooble::Hooble::Yooble->can(...)'
151 # can_ok() called with no methods
155 isa_ok(bless([], "Foo"), "Wibble");
156 isa_ok(42, "Wibble", "My Wibble");
157 isa_ok(undef, "Wibble", "Another Wibble");
160 # Failed test 'The object isa Wibble'
162 # The object isn't a 'Wibble' it's a 'Foo'
163 # Failed test 'My Wibble isa Wibble'
165 # My Wibble isn't a reference
166 # Failed test 'Another Wibble isa Wibble'
168 # Another Wibble isn't defined
169 # Failed test 'The object isa HASH'
171 # The object isn't a 'HASH' it's a 'ARRAY'
175 cmp_ok( 'foo', 'eq', 'bar', 'cmp_ok eq' );
176 cmp_ok( 42.1, '==', 23, , ' ==' );
177 cmp_ok( 42, '!=', 42 , ' !=' );
178 cmp_ok( 1, '&&', 0 , ' &&' );
180 # Failed test 'cmp_ok eq'
202 cmp_ok( 42, 'eq', "foo", ' eq with numbers' );
204 # Failed test ' eq with numbers'
213 local $SIG{__WARN__} = sub { $warnings .= join '', @_ };
216 cmp_ok( 42, '==', "foo", ' == with strings' );
218 # Failed test ' == with strings'
223 My::Test::like $warnings,
224 qq[/^Argument "foo" isn't numeric in .* at $Filename line 211\\\.\n\$/];
229 # generate a $!, it changes its value by context.
231 my $Errno_Number = $!+0;
232 my $Errno_String = $!.'';
234 cmp_ok( $!, 'eq', '', ' eq with stringified errno' );
235 cmp_ok( $!, '==', -1, ' eq with numerified errno' );
237 # Failed test ' eq with stringified errno'
239 # got: '$Errno_String'
241 # Failed test ' eq with numerified errno'
248 use_ok('Hooble::mooble::yooble');
250 my $more_err_re = <<ERR;
251 # Failed test 'use Hooble::mooble::yooble;'
252 # in $Filename at line 84\\.
253 # Tried to use 'Hooble::mooble::yooble'.
254 # Error: Can't locate Hooble.* in \\\@INC .*
255 # BEGIN failed--compilation aborted at $Filename line 84.
258 My::Test::like($err->read, "/^$more_err_re/");
262 require_ok('ALL::YOUR::BASE::ARE::BELONG::TO::US::wibble');
263 $more_err_re = <<ERR;
264 # Failed test 'require ALL::YOUR::BASE::ARE::BELONG::TO::US::wibble;'
265 # in $Filename at line 85\\.
266 # Tried to require 'ALL::YOUR::BASE::ARE::BELONG::TO::US::wibble'.
267 # Error: Can't locate ALL.* in \\\@INC .*
270 My::Test::like($err->read, "/^$more_err_re/");
275 $TB->is_eq($$out, <<OUT, 'failing output');
279 not ok - undef is empty string?
281 not ok - empty string is 0?
282 not ok - foo isnt foo?
283 not ok - foo isn't foo?
284 not ok - undef isnt undef?
285 not ok - is foo like that
286 not ok - is foo unlike foo
287 not ok - regex with % in it
289 not ok - Mooble::Hooble::Yooble->can(...)
290 not ok - Mooble::Hooble::Yooble->can(...)
291 not ok - The object isa Wibble
292 not ok - My Wibble isa Wibble
293 not ok - Another Wibble isa Wibble
294 not ok - The object isa HASH
299 not ok - eq with numbers
300 not ok - == with strings
301 not ok - eq with stringified errno
302 not ok - eq with numerified errno
303 not ok - use Hooble::mooble::yooble;
304 not ok - require ALL::YOUR::BASE::ARE::BELONG::TO::US::wibble;
308 # Looks like you failed $Total tests of $Total.