Upgrade to Test::Harness 1.26.
[p5sagit/p5-mst-13.2.git] / lib / Test / Simple / t / output.t
CommitLineData
33459055 1#!perl -w
2
3BEGIN {
4 chdir 't' if -d 't';
5 @INC = '../lib';
6}
7
8# Can't use Test.pm, that's a 5.005 thing.
9print "1..3\n";
10
11my $test_num = 1;
12# Utility testing functions.
13sub ok ($;$) {
14 my($test, $name) = @_;
15 my $ok = '';
16 $ok .= "not " unless $test;
17 $ok .= "ok $test_num";
18 $ok .= " - $name" if defined $name;
19 $ok .= "\n";
20 print $ok;
21 $test_num++;
22}
23
24use Test::Builder;
25my $Test = Test::Builder->new();
26
27my $result;
28my $out = $Test->output('foo');
29
30ok( defined $out );
31
32print $out "hi!\n";
33close *$out;
34
35undef $out;
36open(IN, 'foo') or die $!;
37chomp(my $line = <IN>);
b8d190ff 38close IN;
33459055 39ok($line eq 'hi!');
40
41open(FOO, ">>foo") or die $!;
42$out = $Test->output(\*FOO);
43$old = select *$out;
44print "Hello!\n";
45close *$out;
46undef $out;
47select $old;
48open(IN, 'foo') or die $!;
49my @lines = <IN>;
50close IN;
51
52ok($lines[1] =~ /Hello!/);
53
54unlink('foo');