This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
91ef58f588482d8e79ac8e4b47e909023da91054
[perl5.git] / lib / Test / Simple / t / diag.t
1 #!perl -w
2 # $Id$
3
4 BEGIN {
5     if( $ENV{PERL_CORE} ) {
6         chdir 't';
7         @INC = ('../lib', 'lib');
8     }
9     else {
10         unshift @INC, 't/lib';
11     }
12 }
13
14
15 # Turn on threads here, if available, since this test tends to find
16 # lots of threading bugs.
17 use Config;
18 BEGIN {
19     if( $] >= 5.008001 && $Config{useithreads} ) {
20         require threads;
21         'threads'->import;
22     }
23 }
24
25
26 use strict;
27
28 use Test::More tests => 7;
29
30 my $test = Test::Builder->create;
31
32 # now make a filehandle where we can send data
33 use TieOut;
34 my $output = tie *FAKEOUT, 'TieOut';
35
36
37 # Test diag() goes to todo_output() in a todo test.
38 {
39     $test->todo_start();
40     $test->todo_output(\*FAKEOUT);
41
42     $test->diag("a single line");
43     is( $output->read, <<'DIAG',   'diag() with todo_output set' );
44 # a single line
45 DIAG
46
47     my $ret = $test->diag("multiple\n", "lines");
48     is( $output->read, <<'DIAG',   '  multi line' );
49 # multiple
50 # lines
51 DIAG
52     ok( !$ret, 'diag returns false' );
53
54     $test->todo_end();
55 }
56
57 $test->reset_outputs();
58
59
60 # Test diagnostic formatting
61 $test->failure_output(\*FAKEOUT);
62 {
63     $test->diag("# foo");
64     is( $output->read, "# # foo\n", "diag() adds # even if there's one already" );
65
66     $test->diag("foo\n\nbar");
67     is( $output->read, <<'DIAG', "  blank lines get escaped" );
68 # foo
69
70 # bar
71 DIAG
72
73
74     $test->diag("foo\n\nbar\n\n");
75     is( $output->read, <<'DIAG', "  even at the end" );
76 # foo
77
78 # bar
79
80 DIAG
81 }
82
83
84 # [rt.cpan.org 8392]
85 {
86     $test->diag(qw(one two));
87 }
88 is( $output->read, <<'DIAG' );
89 # onetwo
90 DIAG