Debian lenny version packages
[pkg-perl] / deb-src / libtest-simple-perl / libtest-simple-perl-0.80 / t / fail-like.t
1 # qr// was introduced in 5.004-devel.  Skip this test if we're not
2 # of high enough version.
3 BEGIN { 
4     if( $] < 5.005 ) {
5         print "1..0 # Skipped Test requires qr//\n";
6         exit(0);
7     }
8 }
9
10 BEGIN {
11     if( $ENV{PERL_CORE} ) {
12         chdir 't';
13         @INC = ('../lib', 'lib');
14     }
15     else {
16         unshift @INC, 't/lib';
17     }
18 }
19
20 # There was a bug with like() involving a qr// not failing properly.
21 # This tests against that.
22
23 use strict;
24
25
26 # Can't use Test.pm, that's a 5.005 thing.
27 package My::Test;
28
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.
31 require Test::Builder;
32 my $TB = Test::Builder->create;
33 $TB->plan(tests => 2);
34
35
36 require Test::Simple::Catch;
37 my($out, $err) = Test::Simple::Catch::caught();
38 local $ENV{HARNESS_ACTIVE} = 0;
39
40
41 package main;
42
43 require Test::More;
44 Test::More->import(tests => 1);
45
46 eval q{ like( "foo", qr/that/, 'is foo like that' ); };
47
48
49 END {
50     $TB->is_eq($$out, <<OUT, 'failing output');
51 1..1
52 not ok 1 - is foo like that
53 OUT
54
55     my $err_re = <<ERR;
56 #   Failed test 'is foo like that'
57 #   at .* line 1\.
58 #                   'foo'
59 #     doesn't match '\\(\\?-xism:that\\)'
60 # Looks like you failed 1 test of 1\\.
61 ERR
62
63
64     $TB->like($$err, qr/^$err_re$/, 'failing errors');
65
66     exit(0);
67 }