Commit | Line | Data |
a9153838 |
1 | #!perl -w |
2 | |
3 | BEGIN { |
4 | if( $ENV{PERL_CORE} ) { |
5 | chdir 't'; |
7483b81c |
6 | @INC = ('../lib', 'lib'); |
7 | } |
8 | else { |
9 | unshift @INC, 't/lib'; |
a9153838 |
10 | } |
11 | } |
12 | |
30e302f8 |
13 | |
14 | # Turn on threads here, if available, since this test tends to find |
15 | # lots of threading bugs. |
16 | use Config; |
17 | BEGIN { |
b7f9bbeb |
18 | if( $] >= 5.008001 && $Config{useithreads} ) { |
30e302f8 |
19 | require threads; |
20 | 'threads'->import; |
21 | } |
22 | } |
23 | |
24 | |
a9153838 |
25 | use strict; |
a9153838 |
26 | |
3e887aae |
27 | use Test::Builder::NoOutput; |
82d700dc |
28 | use Test::More tests => 7; |
a9153838 |
29 | |
3e887aae |
30 | my $test = Test::Builder::NoOutput->create; |
a9153838 |
31 | |
82d700dc |
32 | # Test diag() goes to todo_output() in a todo test. |
33 | { |
34 | $test->todo_start(); |
a9153838 |
35 | |
82d700dc |
36 | $test->diag("a single line"); |
3e887aae |
37 | is( $test->read('todo'), <<'DIAG', 'diag() with todo_output set' ); |
7483b81c |
38 | # a single line |
82d700dc |
39 | DIAG |
40 | |
41 | my $ret = $test->diag("multiple\n", "lines"); |
3e887aae |
42 | is( $test->read('todo'), <<'DIAG', ' multi line' ); |
7483b81c |
43 | # multiple |
44 | # lines |
45 | DIAG |
82d700dc |
46 | ok( !$ret, 'diag returns false' ); |
7483b81c |
47 | |
82d700dc |
48 | $test->todo_end(); |
49 | } |
a9153838 |
50 | |
82d700dc |
51 | |
52 | # Test diagnostic formatting |
a9153838 |
53 | { |
82d700dc |
54 | $test->diag("# foo"); |
3e887aae |
55 | is( $test->read('err'), "# # foo\n", "diag() adds # even if there's one already" ); |
82d700dc |
56 | |
57 | $test->diag("foo\n\nbar"); |
3e887aae |
58 | is( $test->read('err'), <<'DIAG', " blank lines get escaped" ); |
82d700dc |
59 | # foo |
60 | # |
61 | # bar |
62 | DIAG |
63 | |
82d700dc |
64 | $test->diag("foo\n\nbar\n\n"); |
3e887aae |
65 | is( $test->read('err'), <<'DIAG', " even at the end" ); |
82d700dc |
66 | # foo |
67 | # |
68 | # bar |
69 | # |
70 | DIAG |
a9153838 |
71 | } |
a9153838 |
72 | |
a9153838 |
73 | |
3e887aae |
74 | # [rt.cpan.org 8392] diag(@list) emulates print |
7483b81c |
75 | { |
82d700dc |
76 | $test->diag(qw(one two)); |
3e887aae |
77 | |
78 | is( $test->read('err'), <<'DIAG' ); |
7483b81c |
79 | # onetwo |
80 | DIAG |
3e887aae |
81 | } |