Commit | Line | Data |
33459055 |
1 | #!perl -w |
2 | |
3 | BEGIN { |
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. |
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>); |
b8d190ff |
40 | close IN; |
4bd4e70a |
41 | |
33459055 |
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'); |