Upgrade to Test::Simple 0.33.
[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;
4bd4e70a 39
33459055 40ok($line eq 'hi!');
41
42open(FOO, ">>foo") or die $!;
43$out = $Test->output(\*FOO);
44$old = select *$out;
45print "Hello!\n";
46close *$out;
47undef $out;
48select $old;
49open(IN, 'foo') or die $!;
50my @lines = <IN>;
51close IN;
52
53ok($lines[1] =~ /Hello!/);
54
55unlink('foo');