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