This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Add Test::More, from Michael G Schwern.
[perl5.git] / lib / Test / More / t / fail.t
CommitLineData
3f2ec160
JH
1use strict;
2
3# Can't use Test.pm, that's a 5.005 thing.
4package My::Test;
5
6print "1..2\n";
7
8my $test_num = 1;
9# Utility testing functions.
10sub ok ($;$) {
11 my($test, $name) = @_;
12 print "not " unless $test;
13 print "ok $test_num";
14 print " - $name" if defined $name;
15 print "\n";
16 $test_num++;
17}
18
19
20package main;
21require Test::More;
22
23push @INC, 'lib/Test/More/';
24require Catch;
25my($out, $err) = Catch::caught();
26
27Test::More->import(tests => 8);
28
29ok( 0, 'failing' );
30is( "foo", "bar", 'foo is bar?');
31isnt("foo", "foo", 'foo isnt foo?' );
32isn't("foo", "foo",'foo isn\'t foo?' );
33
34like( "foo", '/that/', 'is foo like that' );
35
36fail('fail()');
37
38use_ok('Hooble::mooble::yooble');
39require_ok('ALL::YOUR::BASE::ARE::BELONG::TO::US::wibble');
40
41END {
42 My::Test::ok($$out eq <<OUT, 'failing output');
431..8
44not ok 1 - failing
45not ok 2 - foo is bar?
46not ok 3 - foo isnt foo?
47not ok 4 - foo isn't foo?
48not ok 5 - is foo like that
49not ok 6 - fail()
50not ok 7 - use Hooble::mooble::yooble;
51not ok 8 - require ALL::YOUR::BASE::ARE::BELONG::TO::US::wibble;
52OUT
53
54 my $err_re = <<ERR;
55# Failed test ($0 at line 29)
56# Failed test ($0 at line 30)
57# got: 'foo'
58# expected: 'bar'
59# Failed test ($0 at line 31)
60# it should not be 'foo'
61# but it is.
62# Failed test ($0 at line 32)
63# it should not be 'foo'
64# but it is.
65# Failed test ($0 at line 34)
66# 'foo'
67# doesn't match '/that/'
68# Failed test ($0 at line 36)
69ERR
70
71 my $more_err_re = <<ERR;
72# Failed test \\($0 at line 38\\)
73# Tried to use 'Hooble::mooble::yooble'.
74# Error: Can't locate Hooble.* in \\\@INC .*
75
76# Failed test \\($0 at line 39\\)
77# Tried to require 'ALL::YOUR::BASE::ARE::BELONG::TO::US::wibble'.
78# Error: Can't locate ALL.* in \\\@INC .*
79
80# Looks like you failed 8 tests of 8.
81ERR
82
83 My::Test::ok($$err =~ /^\Q$err_re\E$more_err_re$/, 'failing errors');
84
85 exit(0);
86}