This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Be sure to find the vmsish pragma for one-liners in exit.t.
[perl5.git] / lib / Test / Simple / t / fail-like.t
CommitLineData
ccbd73a4 1#!/usr/bin/perl -w
3f2ec160 2
a9153838
MS
3BEGIN {
4 if( $ENV{PERL_CORE} ) {
5 chdir 't';
6 @INC = ('../lib', 'lib');
7 }
8 else {
9 unshift @INC, 't/lib';
10 }
11}
3f2ec160
JH
12
13# There was a bug with like() involving a qr// not failing properly.
14# This tests against that.
15
33459055 16use strict;
33459055 17
33459055 18
3f2ec160
JH
19# Can't use Test.pm, that's a 5.005 thing.
20package My::Test;
21
b1ddf169
RGS
22# This has to be a require or else the END block below runs before
23# Test::Builder's own and the ending diagnostics don't come out right.
24require Test::Builder;
25my $TB = Test::Builder->create;
ccbd73a4 26$TB->plan(tests => 4);
b1ddf169
RGS
27
28
29require Test::Simple::Catch;
30my($out, $err) = Test::Simple::Catch::caught();
31local $ENV{HARNESS_ACTIVE} = 0;
3f2ec160
JH
32
33
34package main;
d020a79a 35
3f2ec160 36require Test::More;
3f2ec160
JH
37Test::More->import(tests => 1);
38
ccbd73a4
SP
39{
40 eval q{ like( "foo", qr/that/, 'is foo like that' ); };
3f2ec160 41
ccbd73a4 42 $TB->is_eq($out->read, <<OUT, 'failing output');
3f2ec160
JH
431..1
44not ok 1 - is foo like that
45OUT
46
47 my $err_re = <<ERR;
b1ddf169 48# Failed test 'is foo like that'
b7f9bbeb 49# at .* line 1\.
3f2ec160
JH
50# 'foo'
51# doesn't match '\\(\\?-xism:that\\)'
3f2ec160
JH
52ERR
53
ccbd73a4
SP
54 $TB->like($err->read, qr/^$err_re$/, 'failing errors');
55}
3f2ec160 56
ccbd73a4 57{
3e887aae 58 # line 59
ccbd73a4
SP
59 like("foo", "not a regex");
60 $TB->is_eq($out->read, <<OUT);
61not ok 2
62OUT
3f2ec160 63
ccbd73a4 64 $TB->is_eq($err->read, <<OUT);
3e887aae 65# Failed test at $0 line 59.
ccbd73a4
SP
66# 'not a regex' doesn't look much like a regex to me.
67OUT
68
69}
70
71END {
72 # Test::More thinks it failed. Override that.
73 exit(scalar grep { !$_ } $TB->summary);
3f2ec160 74}