Commit | Line | Data |
a9153838 |
1 | #!perl -w |
2 | |
3 | BEGIN { |
4 | if( $ENV{PERL_CORE} ) { |
5 | chdir 't'; |
6 | @INC = '../lib'; |
7 | } |
8 | } |
9 | |
10 | use strict; |
a9153838 |
11 | |
89c1e84a |
12 | use Test::More tests => 7; |
a9153838 |
13 | |
14 | my $Test = Test::More->builder; |
15 | |
16 | # now make a filehandle where we can send data |
17 | my $output; |
18 | tie *FAKEOUT, 'FakeOut', \$output; |
19 | |
89c1e84a |
20 | # force diagnostic output to a filehandle, glad I added this to |
21 | # Test::Builder :) |
a9153838 |
22 | my @lines; |
89c1e84a |
23 | my $ret; |
a9153838 |
24 | { |
25 | local $TODO = 1; |
26 | $Test->todo_output(\*FAKEOUT); |
27 | |
28 | diag("a single line"); |
29 | |
30 | push @lines, $output; |
31 | $output = ''; |
32 | |
89c1e84a |
33 | $ret = diag("multiple\n", "lines"); |
a9153838 |
34 | push @lines, split(/\n/, $output); |
35 | } |
36 | |
37 | is( @lines, 3, 'diag() should send messages to its filehandle' ); |
38 | like( $lines[0], '/^#\s+/', ' should add comment mark to all lines' ); |
39 | is( $lines[0], "# a single line\n", ' should send exact message' ); |
40 | is( $output, "# multiple\n# lines\n", ' should append multi messages'); |
89c1e84a |
41 | ok( !$ret, 'diag returns false' ); |
a9153838 |
42 | |
43 | { |
89c1e84a |
44 | $Test->failure_output(\*FAKEOUT); |
a9153838 |
45 | $output = ''; |
89c1e84a |
46 | $ret = diag("# foo"); |
a9153838 |
47 | } |
89c1e84a |
48 | $Test->failure_output(\*STDERR); |
a9153838 |
49 | is( $output, "# # foo\n", "diag() adds a # even if there's one already" ); |
89c1e84a |
50 | ok( !$ret, 'diag returns false' ); |
a9153838 |
51 | |
52 | package FakeOut; |
53 | |
54 | sub TIEHANDLE { |
55 | bless( $_[1], $_[0] ); |
56 | } |
57 | |
58 | sub PRINT { |
59 | my $self = shift; |
60 | $$self .= join('', @_); |
61 | } |