summaryrefslogtreecommitdiff
path: root/gnu/usr.bin/perl/lib/Test/Simple/t/diag.t
blob: 91ef58f588482d8e79ac8e4b47e909023da91054 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#!perl -w
# $Id$

BEGIN {
    if( $ENV{PERL_CORE} ) {
        chdir 't';
        @INC = ('../lib', 'lib');
    }
    else {
        unshift @INC, 't/lib';
    }
}


# Turn on threads here, if available, since this test tends to find
# lots of threading bugs.
use Config;
BEGIN {
    if( $] >= 5.008001 && $Config{useithreads} ) {
        require threads;
        'threads'->import;
    }
}


use strict;

use Test::More tests => 7;

my $test = Test::Builder->create;

# now make a filehandle where we can send data
use TieOut;
my $output = tie *FAKEOUT, 'TieOut';


# Test diag() goes to todo_output() in a todo test.
{
    $test->todo_start();
    $test->todo_output(\*FAKEOUT);

    $test->diag("a single line");
    is( $output->read, <<'DIAG',   'diag() with todo_output set' );
# a single line
DIAG

    my $ret = $test->diag("multiple\n", "lines");
    is( $output->read, <<'DIAG',   '  multi line' );
# multiple
# lines
DIAG
    ok( !$ret, 'diag returns false' );

    $test->todo_end();
}

$test->reset_outputs();


# Test diagnostic formatting
$test->failure_output(\*FAKEOUT);
{
    $test->diag("# foo");
    is( $output->read, "# # foo\n", "diag() adds # even if there's one already" );

    $test->diag("foo\n\nbar");
    is( $output->read, <<'DIAG', "  blank lines get escaped" );
# foo
# 
# bar
DIAG


    $test->diag("foo\n\nbar\n\n");
    is( $output->read, <<'DIAG', "  even at the end" );
# foo
# 
# bar
# 
DIAG
}


# [rt.cpan.org 8392]
{
    $test->diag(qw(one two));
}
is( $output->read, <<'DIAG' );
# onetwo
DIAG