This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Bump version and other misc. changes. 3rd patch from:
[perl5.git] / lib / Test / Simple / t / fail-like.t
CommitLineData
3f2ec160
JH
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 ) {
30e302f8 5 print "1..0 # Skipped Test requires qr//\n";
3f2ec160
JH
6 exit(0);
7 }
8}
9
a9153838
MS
10BEGIN {
11 if( $ENV{PERL_CORE} ) {
12 chdir 't';
13 @INC = ('../lib', 'lib');
14 }
15 else {
16 unshift @INC, 't/lib';
17 }
18}
3f2ec160
JH
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
33459055 25
3f2ec160
JH
26# Can't use Test.pm, that's a 5.005 thing.
27package My::Test;
28
b1ddf169
RGS
29# This has to be a require or else the END block below runs before
30# Test::Builder's own and the ending diagnostics don't come out right.
31require Test::Builder;
32my $TB = Test::Builder->create;
33$TB->plan(tests => 2);
34
35
36require Test::Simple::Catch;
37my($out, $err) = Test::Simple::Catch::caught();
38local $ENV{HARNESS_ACTIVE} = 0;
3f2ec160
JH
39
40
41package main;
d020a79a 42
3f2ec160 43require Test::More;
3f2ec160
JH
44Test::More->import(tests => 1);
45
46eval q{ like( "foo", qr/that/, 'is foo like that' ); };
47
48
49END {
b1ddf169 50 $TB->is_eq($$out, <<OUT, 'failing output');
3f2ec160
JH
511..1
52not ok 1 - is foo like that
53OUT
54
55 my $err_re = <<ERR;
b1ddf169
RGS
56# Failed test 'is foo like that'
57# in .* at line 1\.
3f2ec160
JH
58# 'foo'
59# doesn't match '\\(\\?-xism:that\\)'
30e302f8 60# Looks like you failed 1 test of 1\\.
3f2ec160
JH
61ERR
62
63
b1ddf169 64 $TB->like($$err, qr/^$err_re$/, 'failing errors');
3f2ec160
JH
65
66 exit(0);
67}