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