Upgrade to Test-Simple-0.82.
[p5sagit/p5-mst-13.2.git] / lib / Test / Simple / t / fail-like.t
CommitLineData
ccbd73a4 1#!/usr/bin/perl -w
2# $Id: /mirror/googlecode/test-more/t/fail-like.t 60310 2008-09-07T23:47:22.837229Z schwern $
3f2ec160 3
a9153838 4BEGIN {
5 if( $ENV{PERL_CORE} ) {
6 chdir 't';
7 @INC = ('../lib', 'lib');
8 }
9 else {
10 unshift @INC, 't/lib';
11 }
12}
3f2ec160 13
14# There was a bug with like() involving a qr// not failing properly.
15# This tests against that.
16
33459055 17use strict;
33459055 18
33459055 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;
ccbd73a4 27$TB->plan(tests => 4);
b1ddf169 28
29
30require Test::Simple::Catch;
31my($out, $err) = Test::Simple::Catch::caught();
32local $ENV{HARNESS_ACTIVE} = 0;
3f2ec160 33
34
35package main;
d020a79a 36
3f2ec160 37require Test::More;
3f2ec160 38Test::More->import(tests => 1);
39
ccbd73a4 40{
41 eval q{ like( "foo", qr/that/, 'is foo like that' ); };
3f2ec160 42
ccbd73a4 43 $TB->is_eq($out->read, <<OUT, 'failing output');
3f2ec160 441..1
45not ok 1 - is foo like that
46OUT
47
48 my $err_re = <<ERR;
b1ddf169 49# Failed test 'is foo like that'
b7f9bbeb 50# at .* line 1\.
3f2ec160 51# 'foo'
52# doesn't match '\\(\\?-xism:that\\)'
3f2ec160 53ERR
54
ccbd73a4 55 $TB->like($err->read, qr/^$err_re$/, 'failing errors');
56}
3f2ec160 57
ccbd73a4 58{
59 # line 60
60 like("foo", "not a regex");
61 $TB->is_eq($out->read, <<OUT);
62not ok 2
63OUT
3f2ec160 64
ccbd73a4 65 $TB->is_eq($err->read, <<OUT);
66# Failed test at $0 line 60.
67# 'not a regex' doesn't look much like a regex to me.
68OUT
69
70}
71
72END {
73 # Test::More thinks it failed. Override that.
74 exit(scalar grep { !$_ } $TB->summary);
3f2ec160 75}