sync a bunch of files with Test::Simple 0.86
[p5sagit/p5-mst-13.2.git] / lib / Test / Simple / t / Builder / output.t
1 #!perl -w
2 # $Id$
3
4 BEGIN {
5     if( $ENV{PERL_CORE} ) {
6         chdir 't';
7         @INC = ('../lib', 'lib');
8     }
9     else {
10         unshift @INC, 't/lib';
11     }
12 }
13 chdir 't';
14
15
16 # Can't use Test.pm, that's a 5.005 thing.
17 print "1..4\n";
18
19 my $test_num = 1;
20 # Utility testing functions.
21 sub ok ($;$) {
22     my($test, $name) = @_;
23     my $ok = '';
24     $ok .= "not " unless $test;
25     $ok .= "ok $test_num";
26     $ok .= " - $name" if defined $name;
27     $ok .= "\n";
28     print $ok;
29     $test_num++;
30
31     return $test;
32 }
33
34 use TieOut;
35 use Test::Builder;
36 my $Test = Test::Builder->new();
37
38 my $result;
39 my $tmpfile = 'foo.tmp';
40 my $out = $Test->output($tmpfile);
41 END { 1 while unlink($tmpfile) }
42
43 ok( defined $out );
44
45 print $out "hi!\n";
46 close *$out;
47
48 undef $out;
49 open(IN, $tmpfile) or die $!;
50 chomp(my $line = <IN>);
51 close IN;
52
53 ok($line eq 'hi!');
54
55 open(FOO, ">>$tmpfile") or die $!;
56 $out = $Test->output(\*FOO);
57 $old = select *$out;
58 print "Hello!\n";
59 close *$out;
60 undef $out;
61 select $old;
62 open(IN, $tmpfile) or die $!;
63 my @lines = <IN>;
64 close IN;
65
66 ok($lines[1] =~ /Hello!/);
67
68
69
70 # Ensure stray newline in name escaping works.
71 $out = tie *FAKEOUT, 'TieOut';
72 $Test->output(\*FAKEOUT);
73 $Test->exported_to(__PACKAGE__);
74 $Test->no_ending(1);
75 $Test->plan(tests => 5);
76
77 $Test->ok(1, "ok");
78 $Test->ok(1, "ok\n");
79 $Test->ok(1, "ok, like\nok");
80 $Test->skip("wibble\nmoof");
81 $Test->todo_skip("todo\nskip\n");
82
83 my $output = $out->read;
84 ok( $output eq <<OUTPUT ) || print STDERR $output;
85 1..5
86 ok 1 - ok
87 ok 2 - ok
88
89 ok 3 - ok, like
90 # ok
91 ok 4 # skip wibble
92 # moof
93 not ok 5 # TODO & SKIP todo
94 # skip
95
96 OUTPUT