Elaborate a bit on Storable.
[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 => 5;
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 Test::Builder :)
21 my @lines;
22 {
23     local $TODO = 1;
24     $Test->todo_output(\*FAKEOUT);
25
26     diag("a single line");
27
28     push @lines, $output;
29     $output = '';
30
31     diag("multiple\n", "lines");
32     push @lines, split(/\n/, $output);
33 }
34
35 is( @lines, 3,              'diag() should send messages to its filehandle' );
36 like( $lines[0], '/^#\s+/', '    should add comment mark to all lines' );
37 is( $lines[0], "# a single line\n",   '    should send exact message' );
38 is( $output, "# multiple\n# lines\n", '    should append multi messages');
39
40 {
41     local $TODO = 1;
42     $output = '';
43     diag("# foo");
44 }
45 is( $output, "# # foo\n",   "diag() adds a # even if there's one already" );
46
47
48 package FakeOut;
49
50 sub TIEHANDLE {
51         bless( $_[1], $_[0] );
52 }
53
54 sub PRINT {
55         my $self = shift;
56         $$self .= join('', @_);
57 }