genuine possible buffer problems spotted by flawfinder
[p5sagit/p5-mst-13.2.git] / lib / Test / Simple / t / diag.t
1 #!perl -w
2
3 BEGIN {
4     if( $ENV{PERL_CORE} ) {
5         chdir 't';
6         @INC = '../lib';
7     }
8 }
9
10 use strict;
11
12 use Test::More tests => 7;
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
20 # force diagnostic output to a filehandle, glad I added this to
21 # Test::Builder :)
22 my @lines;
23 my $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
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');
41 ok( !$ret, 'diag returns false' );
42
43 {
44     $Test->failure_output(\*FAKEOUT);
45     $output = '';
46     $ret = diag("# foo");
47 }
48 $Test->failure_output(\*STDERR);
49 is( $output, "# # foo\n",   "diag() adds a # even if there's one already" );
50 ok( !$ret,  'diag returns false' );
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 }