Test::Simple/More/Builder/Tutorial 0.41
[p5sagit/p5-mst-13.2.git] / lib / Test / Simple / t / fail-like.t
CommitLineData
3f2ec160 1# qr// was introduced in 5.004-devel. Skip this test if we're not
2# of high enough version.
3BEGIN {
4 if( $] < 5.005 ) {
5 print "1..0\n";
6 exit(0);
7 }
8}
9
a9153838 10BEGIN {
11 if( $ENV{PERL_CORE} ) {
12 chdir 't';
13 @INC = ('../lib', 'lib');
14 }
15 else {
16 unshift @INC, 't/lib';
17 }
18}
3f2ec160 19
20# There was a bug with like() involving a qr// not failing properly.
21# This tests against that.
22
33459055 23use strict;
33459055 24
25require Test::Simple::Catch;
26my($out, $err) = Test::Simple::Catch::caught();
27
28
3f2ec160 29# Can't use Test.pm, that's a 5.005 thing.
30package My::Test;
31
32print "1..2\n";
33
34my $test_num = 1;
35# Utility testing functions.
36sub ok ($;$) {
37 my($test, $name) = @_;
1af51bd3 38 my $ok = '';
39 $ok .= "not " unless $test;
40 $ok .= "ok $test_num";
41 $ok .= " - $name" if defined $name;
42 $ok .= "\n";
43 print $ok;
3f2ec160 44 $test_num++;
45}
46
47
48package main;
d020a79a 49
3f2ec160 50require Test::More;
3f2ec160 51Test::More->import(tests => 1);
52
53eval q{ like( "foo", qr/that/, 'is foo like that' ); };
54
55
56END {
57 My::Test::ok($$out eq <<OUT, 'failing output');
581..1
59not ok 1 - is foo like that
60OUT
61
62 my $err_re = <<ERR;
63# Failed test \\(.*\\)
64# 'foo'
65# doesn't match '\\(\\?-xism:that\\)'
66# Looks like you failed 1 tests of 1\\.
67ERR
68
69
70 My::Test::ok($$err =~ /^$err_re$/, 'failing errors');
71
72 exit(0);
73}