Commit | Line | Data |
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 |
4 | BEGIN { |
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 |
17 | use strict; |
33459055 |
18 | |
33459055 |
19 | |
3f2ec160 |
20 | # Can't use Test.pm, that's a 5.005 thing. |
21 | package 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. |
25 | require Test::Builder; |
26 | my $TB = Test::Builder->create; |
ccbd73a4 |
27 | $TB->plan(tests => 4); |
b1ddf169 |
28 | |
29 | |
30 | require Test::Simple::Catch; |
31 | my($out, $err) = Test::Simple::Catch::caught(); |
32 | local $ENV{HARNESS_ACTIVE} = 0; |
3f2ec160 |
33 | |
34 | |
35 | package main; |
d020a79a |
36 | |
3f2ec160 |
37 | require Test::More; |
3f2ec160 |
38 | Test::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 |
44 | 1..1 |
45 | not ok 1 - is foo like that |
46 | OUT |
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 |
53 | ERR |
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); |
62 | not ok 2 |
63 | OUT |
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. |
68 | OUT |
69 | |
70 | } |
71 | |
72 | END { |
73 | # Test::More thinks it failed. Override that. |
74 | exit(scalar grep { !$_ } $TB->summary); |
3f2ec160 |
75 | } |