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