Add standard core test header to Test::Builder::Tester tests.
[p5sagit/p5-mst-13.2.git] / lib / Test / Simple / t / output.t
CommitLineData
33459055 1#!perl -w
2
3BEGIN {
a9153838 4 if( $ENV{PERL_CORE} ) {
5 chdir 't';
89c1e84a 6 @INC = ('../lib', 'lib');
7 }
8 else {
9 unshift @INC, 't/lib';
a9153838 10 }
33459055 11}
30e302f8 12chdir 't';
13
33459055 14
15# Can't use Test.pm, that's a 5.005 thing.
89c1e84a 16print "1..4\n";
33459055 17
18my $test_num = 1;
19# Utility testing functions.
20sub 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++;
89c1e84a 29
30 return $test;
33459055 31}
32
89c1e84a 33use TieOut;
33459055 34use Test::Builder;
35my $Test = Test::Builder->new();
36
37my $result;
30e302f8 38my $tmpfile = 'foo.tmp';
39my $out = $Test->output($tmpfile);
40END { unlink($tmpfile) }
33459055 41
42ok( defined $out );
43
44print $out "hi!\n";
45close *$out;
46
47undef $out;
30e302f8 48open(IN, $tmpfile) or die $!;
33459055 49chomp(my $line = <IN>);
b8d190ff 50close IN;
4bd4e70a 51
33459055 52ok($line eq 'hi!');
53
30e302f8 54open(FOO, ">>$tmpfile") or die $!;
33459055 55$out = $Test->output(\*FOO);
56$old = select *$out;
57print "Hello!\n";
58close *$out;
59undef $out;
60select $old;
30e302f8 61open(IN, $tmpfile) or die $!;
33459055 62my @lines = <IN>;
63close IN;
64
65ok($lines[1] =~ /Hello!/);
66
89c1e84a 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
82my $output = $out->read;
83ok( $output eq <<OUTPUT ) || print STDERR $output;
841..5
85ok 1 - ok
86ok 2 - ok
87#
88ok 3 - ok, like
89# ok
90ok 4 # skip wibble
91# moof
92not ok 5 # TODO & SKIP todo
93# skip
94#
95OUTPUT