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