genuine possible buffer problems spotted by flawfinder
[p5sagit/p5-mst-13.2.git] / lib / Test / Simple / t / diag.t
CommitLineData
a9153838 1#!perl -w
2
3BEGIN {
4 if( $ENV{PERL_CORE} ) {
5 chdir 't';
6 @INC = '../lib';
7 }
8}
9
10use strict;
a9153838 11
89c1e84a 12use Test::More tests => 7;
a9153838 13
14my $Test = Test::More->builder;
15
16# now make a filehandle where we can send data
17my $output;
18tie *FAKEOUT, 'FakeOut', \$output;
19
89c1e84a 20# force diagnostic output to a filehandle, glad I added this to
21# Test::Builder :)
a9153838 22my @lines;
89c1e84a 23my $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
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');
89c1e84a 41ok( !$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 49is( $output, "# # foo\n", "diag() adds a # even if there's one already" );
89c1e84a 50ok( !$ret, 'diag returns false' );
a9153838 51
52package FakeOut;
53
54sub TIEHANDLE {
55 bless( $_[1], $_[0] );
56}
57
58sub PRINT {
59 my $self = shift;
60 $$self .= join('', @_);
61}