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