This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Revert #15200 for backwards compatiblity reasons.
[perl5.git] / lib / Test / Simple / t / fail-more.t
CommitLineData
33459055 1#!perl -w
3f2ec160 2
15db8fc4 3BEGIN {
a9153838
MS
4 if( $ENV{PERL_CORE} ) {
5 chdir 't';
6 @INC = ('../lib', 'lib');
7 }
8 else {
9 unshift @INC, 't/lib';
10 }
15db8fc4
JH
11}
12
33459055 13use strict;
33459055
MS
14
15require Test::Simple::Catch;
16my($out, $err) = Test::Simple::Catch::caught();
17
18
3f2ec160
JH
19# Can't use Test.pm, that's a 5.005 thing.
20package My::Test;
21
22print "1..2\n";
23
24my $test_num = 1;
25# Utility testing functions.
26sub ok ($;$) {
27 my($test, $name) = @_;
1af51bd3
JH
28 my $ok = '';
29 $ok .= "not " unless $test;
30 $ok .= "ok $test_num";
31 $ok .= " - $name" if defined $name;
32 $ok .= "\n";
33 print $ok;
3f2ec160 34 $test_num++;
d020a79a
JH
35
36 return $test;
3f2ec160
JH
37}
38
39
40package main;
d020a79a 41
3f2ec160 42require Test::More;
a9153838
MS
43my $Total = 28;
44Test::More->import(tests => $Total);
3f2ec160 45
d020a79a 46# Preserve the line numbers.
33459055 47#line 38
3f2ec160 48ok( 0, 'failing' );
a9153838
MS
49
50#line 40
51is( "foo", "bar", 'foo is bar?');
52is( undef, '', 'undef is empty string?');
53is( undef, 0, 'undef is 0?');
54is( '', 0, 'empty string is 0?' );
55
3f2ec160
JH
56isnt("foo", "foo", 'foo isnt foo?' );
57isn't("foo", "foo",'foo isn\'t foo?' );
58
59like( "foo", '/that/', 'is foo like that' );
a9153838
MS
60unlike( "foo", '/foo/', 'is foo unlike foo' );
61
62# Nick Clark found this was a bug. Fixed in 0.40.
63like( "bug", '/(%)/', 'regex with % in it' );
3f2ec160
JH
64
65fail('fail()');
66
a9153838 67#line 52
d020a79a 68can_ok('Mooble::Hooble::Yooble', qw(this that));
a9153838
MS
69can_ok('Mooble::Hooble::Yooble', ());
70
d020a79a 71isa_ok(bless([], "Foo"), "Wibble");
33459055
MS
72isa_ok(42, "Wibble", "My Wibble");
73isa_ok(undef, "Wibble", "Another Wibble");
a9153838
MS
74isa_ok([], "HASH");
75
76#line 68
77cmp_ok( 'foo', 'eq', 'bar', 'cmp_ok eq' );
78cmp_ok( 42.1, '==', 23, , ' ==' );
79cmp_ok( 42, '!=', 42 , ' !=' );
80cmp_ok( 1, '&&', 0 , ' &&' );
81cmp_ok( 42, '==', "foo", ' == with strings' );
82cmp_ok( 42, 'eq', "foo", ' eq with numbers' );
83cmp_ok( undef, 'eq', 'foo', ' eq with undef' );
84
85# generate a $!, it changes its value by context.
86-e "wibblehibble";
87my $Errno_Number = $!+0;
88my $Errno_String = $!.'';
89cmp_ok( $!, 'eq', '', ' eq with stringified errno' );
90cmp_ok( $!, '==', -1, ' eq with numerified errno' );
91
92#line 84
3f2ec160
JH
93use_ok('Hooble::mooble::yooble');
94require_ok('ALL::YOUR::BASE::ARE::BELONG::TO::US::wibble');
95
a9153838 96#line 88
3f2ec160
JH
97END {
98 My::Test::ok($$out eq <<OUT, 'failing output');
a9153838 991..$Total
3f2ec160
JH
100not ok 1 - failing
101not ok 2 - foo is bar?
a9153838
MS
102not ok 3 - undef is empty string?
103not ok 4 - undef is 0?
104not ok 5 - empty string is 0?
105not ok 6 - foo isnt foo?
106not ok 7 - foo isn't foo?
107not ok 8 - is foo like that
108not ok 9 - is foo unlike foo
109not ok 10 - regex with % in it
110not ok 11 - fail()
111not ok 12 - Mooble::Hooble::Yooble->can(...)
112not ok 13 - Mooble::Hooble::Yooble->can(...)
113not ok 14 - The object isa Wibble
114not ok 15 - My Wibble isa Wibble
115not ok 16 - Another Wibble isa Wibble
116not ok 17 - The object isa HASH
117not ok 18 - cmp_ok eq
118not ok 19 - ==
119not ok 20 - !=
120not ok 21 - &&
121not ok 22 - == with strings
122not ok 23 - eq with numbers
123not ok 24 - eq with undef
124not ok 25 - eq with stringified errno
125not ok 26 - eq with numerified errno
126not ok 27 - use Hooble::mooble::yooble;
127not ok 28 - require ALL::YOUR::BASE::ARE::BELONG::TO::US::wibble;
3f2ec160
JH
128OUT
129
130 my $err_re = <<ERR;
33459055 131# Failed test ($0 at line 38)
a9153838 132# Failed test ($0 at line 40)
3f2ec160
JH
133# got: 'foo'
134# expected: 'bar'
33459055 135# Failed test ($0 at line 41)
a9153838
MS
136# got: undef
137# expected: ''
138# Failed test ($0 at line 42)
139# got: undef
140# expected: '0'
33459055 141# Failed test ($0 at line 43)
a9153838
MS
142# got: ''
143# expected: '0'
144# Failed test ($0 at line 45)
145# 'foo'
146# ne
147# 'foo'
148# Failed test ($0 at line 46)
149# 'foo'
150# ne
151# 'foo'
152# Failed test ($0 at line 48)
3f2ec160
JH
153# 'foo'
154# doesn't match '/that/'
a9153838
MS
155# Failed test ($0 at line 49)
156# 'foo'
157# matches '/foo/'
158# Failed test ($0 at line 52)
159# 'bug'
160# doesn't match '/(%)/'
161# Failed test ($0 at line 54)
162# Failed test ($0 at line 52)
d020a79a
JH
163# Mooble::Hooble::Yooble->can('this') failed
164# Mooble::Hooble::Yooble->can('that') failed
a9153838
MS
165# Failed test ($0 at line 53)
166# can_ok() called with no methods
167# Failed test ($0 at line 55)
6686786d 168# The object isn't a 'Wibble' it's a 'Foo'
a9153838 169# Failed test ($0 at line 56)
33459055 170# My Wibble isn't a reference
a9153838 171# Failed test ($0 at line 57)
33459055 172# Another Wibble isn't defined
a9153838 173# Failed test ($0 at line 58)
6686786d 174# The object isn't a 'HASH' it's a 'ARRAY'
a9153838
MS
175# Failed test ($0 at line 68)
176# got: 'foo'
177# expected: 'bar'
178# Failed test ($0 at line 69)
179# got: 42.1
180# expected: 23
181# Failed test ($0 at line 70)
182# '42'
183# !=
184# '42'
185# Failed test ($0 at line 71)
186# '1'
187# &&
188# '0'
189# Failed test ($0 at line 72)
190# got: 42
191# expected: 0
192# Failed test ($0 at line 73)
193# got: '42'
194# expected: 'foo'
195# Failed test ($0 at line 74)
196# got: undef
197# expected: 'foo'
198# Failed test ($0 at line 80)
199# got: '$Errno_String'
200# expected: ''
201# Failed test ($0 at line 81)
202# got: $Errno_Number
203# expected: -1
3f2ec160
JH
204ERR
205
1af51bd3 206 my $filename = quotemeta $0;
3f2ec160 207 my $more_err_re = <<ERR;
a9153838 208# Failed test \\($filename at line 84\\)
3f2ec160 209# Tried to use 'Hooble::mooble::yooble'.
ea071790 210# Error: Can't locate Hooble.* in \\\@INC .*
a9153838 211# Failed test \\($filename at line 85\\)
3f2ec160 212# Tried to require 'ALL::YOUR::BASE::ARE::BELONG::TO::US::wibble'.
ea071790 213# Error: Can't locate ALL.* in \\\@INC .*
a9153838 214# Looks like you failed $Total tests of $Total.
3f2ec160
JH
215ERR
216
d020a79a
JH
217 unless( My::Test::ok($$err =~ /^\Q$err_re\E$more_err_re$/,
218 'failing errors') ) {
a9153838 219 print $$err;
d020a79a 220 }
3f2ec160
JH
221
222 exit(0);
223}