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