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