Add contact information for Sullivan Beck
[p5sagit/p5-mst-13.2.git] / cpan / Test-Simple / t / fail-more.t
CommitLineData
33459055 1#!perl -w
3f2ec160 2
15db8fc4 3BEGIN {
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 13use strict;
33459055 14
15require Test::Simple::Catch;
16my($out, $err) = Test::Simple::Catch::caught();
30e302f8 17local $ENV{HARNESS_ACTIVE} = 0;
33459055 18
19
3f2ec160 20# Can't use Test.pm, that's a 5.005 thing.
21package My::Test;
22
b1ddf169 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.
25require Test::Builder;
26my $TB = Test::Builder->create;
2c4d5b9b 27$TB->plan(tests => 80);
b1ddf169 28
29sub like ($$;$) {
30 $TB->like(@_);
3f2ec160 31}
32
b1ddf169 33sub is ($$;$) {
34 $TB->is_eq(@_);
35}
3f2ec160 36
3e887aae 37sub main::out_ok ($$) {
38 $TB->is_eq( $out->read, shift );
39 $TB->is_eq( $err->read, shift );
30e302f8 40}
41
3e887aae 42sub main::out_like ($$) {
43 my($output, $failure) = @_;
ccbd73a4 44
3e887aae 45 $TB->like( $out->read, qr/$output/ );
46 $TB->like( $err->read, qr/$failure/ );
ccbd73a4 47}
48
30e302f8 49
3f2ec160 50package main;
d020a79a 51
3f2ec160 52require Test::More;
3e887aae 53our $TODO;
2c4d5b9b 54my $Total = 38;
a9153838 55Test::More->import(tests => $Total);
3e887aae 56$out->read; # clear the plan from $out
3f2ec160 57
c00d8759 58# This should all work in the presence of a __DIE__ handler.
59local $SIG{__DIE__} = sub { $TB->ok(0, "DIE handler called: ".join "", @_); };
60
61
30e302f8 62my $tb = Test::More->builder;
63$tb->use_numbers(0);
64
b1ddf169 65my $Filename = quotemeta $0;
66
3e887aae 67
33459055 68#line 38
3f2ec160 69ok( 0, 'failing' );
3e887aae 70out_ok( <<OUT, <<ERR );
71not ok - failing
72OUT
b1ddf169 73# Failed test 'failing'
b7f9bbeb 74# at $0 line 38.
30e302f8 75ERR
a9153838 76
3e887aae 77
a9153838 78#line 40
79is( "foo", "bar", 'foo is bar?');
3e887aae 80out_ok( <<OUT, <<ERR );
81not ok - foo is bar?
82OUT
b1ddf169 83# Failed test 'foo is bar?'
b7f9bbeb 84# at $0 line 40.
3f2ec160 85# got: 'foo'
86# expected: 'bar'
3e887aae 87ERR
88
89#line 89
90is( undef, '', 'undef is empty string?');
91out_ok( <<OUT, <<ERR );
92not ok - undef is empty string?
93OUT
b1ddf169 94# Failed test 'undef is empty string?'
3e887aae 95# at $0 line 89.
a9153838 96# got: undef
97# expected: ''
3e887aae 98ERR
99
100#line 99
101is( undef, 0, 'undef is 0?');
102out_ok( <<OUT, <<ERR );
103not ok - undef is 0?
104OUT
b1ddf169 105# Failed test 'undef is 0?'
3e887aae 106# at $0 line 99.
a9153838 107# got: undef
108# expected: '0'
3e887aae 109ERR
110
111#line 110
112is( '', 0, 'empty string is 0?' );
113out_ok( <<OUT, <<ERR );
114not ok - empty string is 0?
115OUT
b1ddf169 116# Failed test 'empty string is 0?'
3e887aae 117# at $0 line 110.
a9153838 118# got: ''
119# expected: '0'
30e302f8 120ERR
121
3e887aae 122#line 121
30e302f8 123isnt("foo", "foo", 'foo isnt foo?' );
3e887aae 124out_ok( <<OUT, <<ERR );
125not ok - foo isnt foo?
126OUT
b1ddf169 127# Failed test 'foo isnt foo?'
3e887aae 128# at $0 line 121.
ccbd73a4 129# got: 'foo'
130# expected: anything else
3e887aae 131ERR
132
133#line 132
134isn't("foo", "foo",'foo isn\'t foo?' );
135out_ok( <<OUT, <<ERR );
136not ok - foo isn't foo?
137OUT
b1ddf169 138# Failed test 'foo isn\'t foo?'
3e887aae 139# at $0 line 132.
ccbd73a4 140# got: 'foo'
141# expected: anything else
3e887aae 142ERR
143
144#line 143
145isnt(undef, undef, 'undef isnt undef?');
146out_ok( <<OUT, <<ERR );
147not ok - undef isnt undef?
148OUT
b1ddf169 149# Failed test 'undef isnt undef?'
3e887aae 150# at $0 line 143.
ccbd73a4 151# got: undef
152# expected: anything else
30e302f8 153ERR
154
3e887aae 155#line 154
30e302f8 156like( "foo", '/that/', 'is foo like that' );
3e887aae 157out_ok( <<OUT, <<ERR );
158not ok - is foo like that
159OUT
b1ddf169 160# Failed test 'is foo like that'
3e887aae 161# at $0 line 154.
3f2ec160 162# 'foo'
163# doesn't match '/that/'
3e887aae 164ERR
165
166#line 165
167unlike( "foo", '/foo/', 'is foo unlike foo' );
168out_ok( <<OUT, <<ERR );
169not ok - is foo unlike foo
170OUT
b1ddf169 171# Failed test 'is foo unlike foo'
3e887aae 172# at $0 line 165.
a9153838 173# 'foo'
174# matches '/foo/'
30e302f8 175ERR
176
177# Nick Clark found this was a bug. Fixed in 0.40.
3e887aae 178# line 177
30e302f8 179like( "bug", '/(%)/', 'regex with % in it' );
3e887aae 180out_ok( <<OUT, <<ERR );
181not ok - regex with % in it
182OUT
b1ddf169 183# Failed test 'regex with % in it'
3e887aae 184# at $0 line 177.
a9153838 185# 'bug'
186# doesn't match '/(%)/'
30e302f8 187ERR
188
3e887aae 189#line 188
30e302f8 190fail('fail()');
3e887aae 191out_ok( <<OUT, <<ERR );
192not ok - fail()
193OUT
b1ddf169 194# Failed test 'fail()'
3e887aae 195# at $0 line 188.
30e302f8 196ERR
197
3e887aae 198#line 197
30e302f8 199can_ok('Mooble::Hooble::Yooble', qw(this that));
3e887aae 200out_ok( <<OUT, <<ERR );
201not ok - Mooble::Hooble::Yooble->can(...)
202OUT
b1ddf169 203# Failed test 'Mooble::Hooble::Yooble->can(...)'
3e887aae 204# at $0 line 197.
d020a79a 205# Mooble::Hooble::Yooble->can('this') failed
206# Mooble::Hooble::Yooble->can('that') failed
3e887aae 207ERR
208
209#line 208
210can_ok('Mooble::Hooble::Yooble', ());
211out_ok( <<OUT, <<ERR );
212not ok - Mooble::Hooble::Yooble->can(...)
213OUT
b1ddf169 214# Failed test 'Mooble::Hooble::Yooble->can(...)'
3e887aae 215# at $0 line 208.
a9153838 216# can_ok() called with no methods
3e887aae 217ERR
218
219#line 218
220can_ok(undef, undef);
221out_ok( <<OUT, <<ERR );
222not ok - ->can(...)
223OUT
68938d83 224# Failed test '->can(...)'
3e887aae 225# at $0 line 218.
68938d83 226# can_ok() called with empty class or reference
3e887aae 227ERR
228
229#line 228
230can_ok([], "foo");
231out_ok( <<OUT, <<ERR );
232not ok - ARRAY->can('foo')
233OUT
c00d8759 234# Failed test 'ARRAY->can('foo')'
3e887aae 235# at $0 line 228.
c00d8759 236# ARRAY->can('foo') failed
30e302f8 237ERR
238
3e887aae 239#line 238
30e302f8 240isa_ok(bless([], "Foo"), "Wibble");
3e887aae 241out_ok( <<OUT, <<ERR );
242not ok - The object isa Wibble
243OUT
b1ddf169 244# Failed test 'The object isa Wibble'
3e887aae 245# at $0 line 238.
6686786d 246# The object isn't a 'Wibble' it's a 'Foo'
3e887aae 247ERR
248
249#line 248
250isa_ok(42, "Wibble", "My Wibble");
251out_ok( <<OUT, <<ERR );
252not ok - My Wibble isa Wibble
253OUT
b1ddf169 254# Failed test 'My Wibble isa Wibble'
3e887aae 255# at $0 line 248.
256# My Wibble isn't a class or reference
257ERR
258
2c4d5b9b 259#line 248
260isa_ok(42, "Wibble");
261out_ok( <<OUT, <<ERR );
262not ok - The thing isa Wibble
263OUT
264# Failed test 'The thing isa Wibble'
265# at $0 line 248.
266# The thing isn't a class or reference
267ERR
268
3e887aae 269#line 258
270isa_ok(undef, "Wibble", "Another Wibble");
271out_ok( <<OUT, <<ERR );
272not ok - Another Wibble isa Wibble
273OUT
b1ddf169 274# Failed test 'Another Wibble isa Wibble'
3e887aae 275# at $0 line 258.
33459055 276# Another Wibble isn't defined
30e302f8 277ERR
278
3e887aae 279#line 268
280isa_ok([], "HASH");
281out_ok( <<OUT, <<ERR );
282not ok - The reference isa HASH
283OUT
284# Failed test 'The reference isa HASH'
285# at $0 line 268.
286# The reference isn't a 'HASH' it's a 'ARRAY'
287ERR
ccbd73a4 288
3e887aae 289#line 278
ccbd73a4 290new_ok(undef);
3e887aae 291out_like( <<OUT, <<ERR );
292not ok - new\\(\\) died
293OUT
ccbd73a4 294# Failed test 'new\\(\\) died'
3e887aae 295# at $Filename line 278.
ccbd73a4 296# Error was: Can't call method "new" on an undefined value at .*
297ERR
298
3e887aae 299#line 288
ccbd73a4 300new_ok( "Does::Not::Exist" );
3e887aae 301out_like( <<OUT, <<ERR );
302not ok - new\\(\\) died
303OUT
ccbd73a4 304# Failed test 'new\\(\\) died'
3e887aae 305# at $Filename line 288.
ccbd73a4 306# Error was: Can't locate object method "new" via package "Does::Not::Exist" .*
307ERR
308
3e887aae 309
ccbd73a4 310{ package Foo; sub new { } }
311{ package Bar; sub new { {} } }
312{ package Baz; sub new { bless {}, "Wibble" } }
313
3e887aae 314#line 303
ccbd73a4 315new_ok( "Foo" );
3e887aae 316out_ok( <<OUT, <<ERR );
317not ok - The object isa Foo
318OUT
ccbd73a4 319# Failed test 'The object isa Foo'
3e887aae 320# at $0 line 303.
ccbd73a4 321# The object isn't defined
322ERR
323
3e887aae 324# line 313
ccbd73a4 325new_ok( "Bar" );
3e887aae 326out_ok( <<OUT, <<ERR );
327not ok - The object isa Bar
328OUT
ccbd73a4 329# Failed test 'The object isa Bar'
3e887aae 330# at $0 line 313.
ccbd73a4 331# The object isn't a 'Bar' it's a 'HASH'
332ERR
333
3e887aae 334#line 323
ccbd73a4 335new_ok( "Baz" );
3e887aae 336out_ok( <<OUT, <<ERR );
337not ok - The object isa Baz
338OUT
ccbd73a4 339# Failed test 'The object isa Baz'
3e887aae 340# at $0 line 323.
ccbd73a4 341# The object isn't a 'Baz' it's a 'Wibble'
342ERR
343
3e887aae 344#line 333
ccbd73a4 345new_ok( "Baz", [], "no args" );
3e887aae 346out_ok( <<OUT, <<ERR );
347not ok - no args isa Baz
348OUT
ccbd73a4 349# Failed test 'no args isa Baz'
3e887aae 350# at $0 line 333.
ccbd73a4 351# no args isn't a 'Baz' it's a 'Wibble'
352ERR
353
3e887aae 354#line 343
30e302f8 355cmp_ok( 'foo', 'eq', 'bar', 'cmp_ok eq' );
3e887aae 356out_ok( <<OUT, <<ERR );
357not ok - cmp_ok eq
358OUT
b1ddf169 359# Failed test 'cmp_ok eq'
3e887aae 360# at $0 line 343.
a9153838 361# got: 'foo'
362# expected: 'bar'
3e887aae 363ERR
364
365#line 354
366cmp_ok( 42.1, '==', 23, , ' ==' );
367out_ok( <<OUT, <<ERR );
368not ok - ==
369OUT
b1ddf169 370# Failed test ' =='
3e887aae 371# at $0 line 354.
a9153838 372# got: 42.1
373# expected: 23
3e887aae 374ERR
375
376#line 365
377cmp_ok( 42, '!=', 42 , ' !=' );
378out_ok( <<OUT, <<ERR );
379not ok - !=
380OUT
b1ddf169 381# Failed test ' !='
3e887aae 382# at $0 line 365.
ccbd73a4 383# got: 42
384# expected: anything else
3e887aae 385ERR
386
387#line 376
388cmp_ok( 1, '&&', 0 , ' &&' );
389out_ok( <<OUT, <<ERR );
390not ok - &&
391OUT
b1ddf169 392# Failed test ' &&'
3e887aae 393# at $0 line 376.
a9153838 394# '1'
395# &&
396# '0'
b1ddf169 397ERR
398
3e887aae 399# line 388
b1ddf169 400cmp_ok( 42, 'eq', "foo", ' eq with numbers' );
3e887aae 401out_ok( <<OUT, <<ERR );
402not ok - eq with numbers
403OUT
b1ddf169 404# Failed test ' eq with numbers'
3e887aae 405# at $0 line 388.
a9153838 406# got: '42'
407# expected: 'foo'
30e302f8 408ERR
409
b1ddf169 410{
3e887aae 411 my $warnings = '';
b1ddf169 412 local $SIG{__WARN__} = sub { $warnings .= join '', @_ };
413
3e887aae 414# line 404
b1ddf169 415 cmp_ok( 42, '==', "foo", ' == with strings' );
3e887aae 416 out_ok( <<OUT, <<ERR );
417not ok - == with strings
418OUT
b1ddf169 419# Failed test ' == with strings'
3e887aae 420# at $0 line 404.
b1ddf169 421# got: 42
422# expected: foo
423ERR
3e887aae 424 My::Test::like(
425 $warnings,
426 qr/^Argument "foo" isn't numeric in .* at cmp_ok \[from $Filename line 404\] line 1\.\n$/
427 );
428 $warnings = '';
429}
b1ddf169 430
3e887aae 431
432{
433 my $warnings = '';
434 local $SIG{__WARN__} = sub { $warnings .= join '', @_ };
435
436#line 426
437 cmp_ok( undef, "ne", "", "undef ne empty string" );
438
439 $TB->is_eq( $out->read, <<OUT );
440not ok - undef ne empty string
441OUT
442
443 TODO: {
444 local $::TODO = 'cmp_ok() gives the wrong "expected" for undef';
445
446 $TB->is_eq( $err->read, <<ERR );
447# Failed test 'undef ne empty string'
448# at $0 line 426.
449# got: undef
450# expected: ''
451ERR
452 }
453
454 My::Test::like(
455 $warnings,
456 qr/^Use of uninitialized value.* in string ne at cmp_ok \[from $Filename line 426\] line 1\.\n\z/
457 );
b1ddf169 458}
459
460
30e302f8 461# generate a $!, it changes its value by context.
462-e "wibblehibble";
463my $Errno_Number = $!+0;
464my $Errno_String = $!.'';
3e887aae 465#line 425
30e302f8 466cmp_ok( $!, 'eq', '', ' eq with stringified errno' );
3e887aae 467out_ok( <<OUT, <<ERR );
468not ok - eq with stringified errno
469OUT
b1ddf169 470# Failed test ' eq with stringified errno'
3e887aae 471# at $0 line 425.
a9153838 472# got: '$Errno_String'
473# expected: ''
3e887aae 474ERR
475
476#line 436
477cmp_ok( $!, '==', -1, ' eq with numerified errno' );
478out_ok( <<OUT, <<ERR );
479not ok - eq with numerified errno
480OUT
b1ddf169 481# Failed test ' eq with numerified errno'
3e887aae 482# at $0 line 436.
a9153838 483# got: $Errno_Number
484# expected: -1
3f2ec160 485ERR
486
3e887aae 487#line 447
30e302f8 488use_ok('Hooble::mooble::yooble');
b1ddf169 489my $more_err_re = <<ERR;
490# Failed test 'use Hooble::mooble::yooble;'
3e887aae 491# at $Filename line 447\\.
b1ddf169 492# Tried to use 'Hooble::mooble::yooble'.
493# Error: Can't locate Hooble.* in \\\@INC .*
b1ddf169 494ERR
3e887aae 495out_like(
496 qr/^\Qnot ok - use Hooble::mooble::yooble;\E\n\z/,
497 qr/^$more_err_re/
498);
b1ddf169 499
3e887aae 500#line 460
30e302f8 501require_ok('ALL::YOUR::BASE::ARE::BELONG::TO::US::wibble');
b1ddf169 502$more_err_re = <<ERR;
503# Failed test 'require ALL::YOUR::BASE::ARE::BELONG::TO::US::wibble;'
3e887aae 504# at $Filename line 460\\.
b1ddf169 505# Tried to require 'ALL::YOUR::BASE::ARE::BELONG::TO::US::wibble'.
506# Error: Can't locate ALL.* in \\\@INC .*
507ERR
3e887aae 508out_like(
509 qr/^\Qnot ok - require ALL::YOUR::BASE::ARE::BELONG::TO::US::wibble;\E\n\z/,
510 qr/^$more_err_re/
511);
b1ddf169 512
30e302f8 513
30e302f8 514END {
3e887aae 515 out_like( <<OUT, <<ERR );
30e302f8 516OUT
a9153838 517# Looks like you failed $Total tests of $Total.
3f2ec160 518ERR
519
3f2ec160 520 exit(0);
521}