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