Upgrade to Test-Simple-0.64_02
[p5sagit/p5-mst-13.2.git] / lib / 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;
27$TB->plan(tests => 17);
28
29sub like ($$;$) {
30 $TB->like(@_);
3f2ec160 31}
32
b1ddf169 33sub is ($$;$) {
34 $TB->is_eq(@_);
35}
3f2ec160 36
0257f296 37sub main::err_ok ($) {
30e302f8 38 my($expect) = @_;
39 my $got = $err->read;
40
b1ddf169 41 return $TB->is_eq( $got, $expect );
30e302f8 42}
43
44
3f2ec160 45package main;
d020a79a 46
3f2ec160 47require Test::More;
68938d83 48my $Total = 29;
a9153838 49Test::More->import(tests => $Total);
3f2ec160 50
30e302f8 51my $tb = Test::More->builder;
52$tb->use_numbers(0);
53
b1ddf169 54my $Filename = quotemeta $0;
55
d020a79a 56# Preserve the line numbers.
33459055 57#line 38
3f2ec160 58ok( 0, 'failing' );
0257f296 59err_ok( <<ERR );
b1ddf169 60# Failed test 'failing'
b7f9bbeb 61# at $0 line 38.
30e302f8 62ERR
a9153838 63
64#line 40
65is( "foo", "bar", 'foo is bar?');
66is( undef, '', 'undef is empty string?');
67is( undef, 0, 'undef is 0?');
68is( '', 0, 'empty string is 0?' );
0257f296 69err_ok( <<ERR );
b1ddf169 70# Failed test 'foo is bar?'
b7f9bbeb 71# at $0 line 40.
3f2ec160 72# got: 'foo'
73# expected: 'bar'
b1ddf169 74# Failed test 'undef is empty string?'
b7f9bbeb 75# at $0 line 41.
a9153838 76# got: undef
77# expected: ''
b1ddf169 78# Failed test 'undef is 0?'
b7f9bbeb 79# at $0 line 42.
a9153838 80# got: undef
81# expected: '0'
b1ddf169 82# Failed test 'empty string is 0?'
b7f9bbeb 83# at $0 line 43.
a9153838 84# got: ''
85# expected: '0'
30e302f8 86ERR
87
88#line 45
89isnt("foo", "foo", 'foo isnt foo?' );
90isn't("foo", "foo",'foo isn\'t foo?' );
91isnt(undef, undef, 'undef isnt undef?');
0257f296 92err_ok( <<ERR );
b1ddf169 93# Failed test 'foo isnt foo?'
b7f9bbeb 94# at $0 line 45.
a9153838 95# 'foo'
96# ne
97# 'foo'
b1ddf169 98# Failed test 'foo isn\'t foo?'
b7f9bbeb 99# at $0 line 46.
a9153838 100# 'foo'
101# ne
102# 'foo'
b1ddf169 103# Failed test 'undef isnt undef?'
b7f9bbeb 104# at $0 line 47.
30e302f8 105# undef
106# ne
107# undef
108ERR
109
110#line 48
111like( "foo", '/that/', 'is foo like that' );
112unlike( "foo", '/foo/', 'is foo unlike foo' );
0257f296 113err_ok( <<ERR );
b1ddf169 114# Failed test 'is foo like that'
b7f9bbeb 115# at $0 line 48.
3f2ec160 116# 'foo'
117# doesn't match '/that/'
b1ddf169 118# Failed test 'is foo unlike foo'
b7f9bbeb 119# at $0 line 49.
a9153838 120# 'foo'
121# matches '/foo/'
30e302f8 122ERR
123
124# Nick Clark found this was a bug. Fixed in 0.40.
b1ddf169 125# line 60
30e302f8 126like( "bug", '/(%)/', 'regex with % in it' );
0257f296 127err_ok( <<ERR );
b1ddf169 128# Failed test 'regex with % in it'
b7f9bbeb 129# at $0 line 60.
a9153838 130# 'bug'
131# doesn't match '/(%)/'
30e302f8 132ERR
133
b1ddf169 134#line 67
30e302f8 135fail('fail()');
0257f296 136err_ok( <<ERR );
b1ddf169 137# Failed test 'fail()'
b7f9bbeb 138# at $0 line 67.
30e302f8 139ERR
140
141#line 52
142can_ok('Mooble::Hooble::Yooble', qw(this that));
143can_ok('Mooble::Hooble::Yooble', ());
68938d83 144can_ok(undef, undef);
0257f296 145err_ok( <<ERR );
b1ddf169 146# Failed test 'Mooble::Hooble::Yooble->can(...)'
b7f9bbeb 147# at $0 line 52.
d020a79a 148# Mooble::Hooble::Yooble->can('this') failed
149# Mooble::Hooble::Yooble->can('that') failed
b1ddf169 150# Failed test 'Mooble::Hooble::Yooble->can(...)'
b7f9bbeb 151# at $0 line 53.
a9153838 152# can_ok() called with no methods
68938d83 153# Failed test '->can(...)'
b7f9bbeb 154# at $0 line 54.
68938d83 155# can_ok() called with empty class or reference
30e302f8 156ERR
157
158#line 55
159isa_ok(bless([], "Foo"), "Wibble");
160isa_ok(42, "Wibble", "My Wibble");
161isa_ok(undef, "Wibble", "Another Wibble");
162isa_ok([], "HASH");
0257f296 163err_ok( <<ERR );
b1ddf169 164# Failed test 'The object isa Wibble'
b7f9bbeb 165# at $0 line 55.
6686786d 166# The object isn't a 'Wibble' it's a 'Foo'
b1ddf169 167# Failed test 'My Wibble isa Wibble'
b7f9bbeb 168# at $0 line 56.
33459055 169# My Wibble isn't a reference
b1ddf169 170# Failed test 'Another Wibble isa Wibble'
b7f9bbeb 171# at $0 line 57.
33459055 172# Another Wibble isn't defined
b1ddf169 173# Failed test 'The object isa HASH'
b7f9bbeb 174# at $0 line 58.
6686786d 175# The object isn't a 'HASH' it's a 'ARRAY'
30e302f8 176ERR
177
178#line 68
179cmp_ok( 'foo', 'eq', 'bar', 'cmp_ok eq' );
180cmp_ok( 42.1, '==', 23, , ' ==' );
181cmp_ok( 42, '!=', 42 , ' !=' );
182cmp_ok( 1, '&&', 0 , ' &&' );
0257f296 183err_ok( <<ERR );
b1ddf169 184# Failed test 'cmp_ok eq'
b7f9bbeb 185# at $0 line 68.
a9153838 186# got: 'foo'
187# expected: 'bar'
b1ddf169 188# Failed test ' =='
b7f9bbeb 189# at $0 line 69.
a9153838 190# got: 42.1
191# expected: 23
b1ddf169 192# Failed test ' !='
b7f9bbeb 193# at $0 line 70.
a9153838 194# '42'
195# !=
196# '42'
b1ddf169 197# Failed test ' &&'
b7f9bbeb 198# at $0 line 71.
a9153838 199# '1'
200# &&
201# '0'
b1ddf169 202ERR
203
204
205# line 196
206cmp_ok( 42, 'eq', "foo", ' eq with numbers' );
207err_ok( <<ERR );
208# Failed test ' eq with numbers'
b7f9bbeb 209# at $0 line 196.
a9153838 210# got: '42'
211# expected: 'foo'
30e302f8 212ERR
213
b1ddf169 214
215{
216 my $warnings;
217 local $SIG{__WARN__} = sub { $warnings .= join '', @_ };
218
219# line 211
220 cmp_ok( 42, '==', "foo", ' == with strings' );
221 err_ok( <<ERR );
222# Failed test ' == with strings'
b7f9bbeb 223# at $0 line 211.
b1ddf169 224# got: 42
225# expected: foo
226ERR
227 My::Test::like $warnings,
228 qq[/^Argument "foo" isn't numeric in .* at $Filename line 211\\\.\n\$/];
229
230}
231
232
30e302f8 233# generate a $!, it changes its value by context.
234-e "wibblehibble";
235my $Errno_Number = $!+0;
236my $Errno_String = $!.'';
237#line 80
238cmp_ok( $!, 'eq', '', ' eq with stringified errno' );
239cmp_ok( $!, '==', -1, ' eq with numerified errno' );
0257f296 240err_ok( <<ERR );
b1ddf169 241# Failed test ' eq with stringified errno'
b7f9bbeb 242# at $0 line 80.
a9153838 243# got: '$Errno_String'
244# expected: ''
b1ddf169 245# Failed test ' eq with numerified errno'
b7f9bbeb 246# at $0 line 81.
a9153838 247# got: $Errno_Number
248# expected: -1
3f2ec160 249ERR
250
30e302f8 251#line 84
252use_ok('Hooble::mooble::yooble');
b1ddf169 253
254my $more_err_re = <<ERR;
255# Failed test 'use Hooble::mooble::yooble;'
b7f9bbeb 256# at $Filename line 84\\.
b1ddf169 257# Tried to use 'Hooble::mooble::yooble'.
258# Error: Can't locate Hooble.* in \\\@INC .*
259# BEGIN failed--compilation aborted at $Filename line 84.
260ERR
261
262My::Test::like($err->read, "/^$more_err_re/");
263
264
265#line 85
30e302f8 266require_ok('ALL::YOUR::BASE::ARE::BELONG::TO::US::wibble');
b1ddf169 267$more_err_re = <<ERR;
268# Failed test 'require ALL::YOUR::BASE::ARE::BELONG::TO::US::wibble;'
b7f9bbeb 269# at $Filename line 85\\.
b1ddf169 270# Tried to require 'ALL::YOUR::BASE::ARE::BELONG::TO::US::wibble'.
271# Error: Can't locate ALL.* in \\\@INC .*
272ERR
273
274My::Test::like($err->read, "/^$more_err_re/");
275
30e302f8 276
277#line 88
278END {
b1ddf169 279 $TB->is_eq($$out, <<OUT, 'failing output');
30e302f8 2801..$Total
281not ok - failing
282not ok - foo is bar?
283not ok - undef is empty string?
284not ok - undef is 0?
285not ok - empty string is 0?
286not ok - foo isnt foo?
287not ok - foo isn't foo?
288not ok - undef isnt undef?
289not ok - is foo like that
290not ok - is foo unlike foo
291not ok - regex with % in it
292not ok - fail()
293not ok - Mooble::Hooble::Yooble->can(...)
294not ok - Mooble::Hooble::Yooble->can(...)
68938d83 295not ok - ->can(...)
30e302f8 296not ok - The object isa Wibble
297not ok - My Wibble isa Wibble
298not ok - Another Wibble isa Wibble
299not ok - The object isa HASH
300not ok - cmp_ok eq
301not ok - ==
302not ok - !=
303not ok - &&
30e302f8 304not ok - eq with numbers
b1ddf169 305not ok - == with strings
30e302f8 306not ok - eq with stringified errno
307not ok - eq with numerified errno
308not ok - use Hooble::mooble::yooble;
309not ok - require ALL::YOUR::BASE::ARE::BELONG::TO::US::wibble;
310OUT
311
b1ddf169 312err_ok( <<ERR );
a9153838 313# Looks like you failed $Total tests of $Total.
3f2ec160 314ERR
315
3f2ec160 316 exit(0);
317}