1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
|
#!perl -w
# $Id: output.t,v 1.1 2009/05/16 21:42:58 simon Exp $
BEGIN {
if( $ENV{PERL_CORE} ) {
chdir 't';
@INC = ('../lib', 'lib');
}
else {
unshift @INC, 't/lib';
}
}
chdir 't';
# Can't use Test.pm, that's a 5.005 thing.
print "1..4\n";
my $test_num = 1;
# Utility testing functions.
sub ok ($;$) {
my($test, $name) = @_;
my $ok = '';
$ok .= "not " unless $test;
$ok .= "ok $test_num";
$ok .= " - $name" if defined $name;
$ok .= "\n";
print $ok;
$test_num++;
return $test;
}
use TieOut;
use Test::Builder;
my $Test = Test::Builder->new();
my $result;
my $tmpfile = 'foo.tmp';
my $out = $Test->output($tmpfile);
END { 1 while unlink($tmpfile) }
ok( defined $out );
print $out "hi!\n";
close *$out;
undef $out;
open(IN, $tmpfile) or die $!;
chomp(my $line = <IN>);
close IN;
ok($line eq 'hi!');
open(FOO, ">>$tmpfile") or die $!;
$out = $Test->output(\*FOO);
$old = select *$out;
print "Hello!\n";
close *$out;
undef $out;
select $old;
open(IN, $tmpfile) or die $!;
my @lines = <IN>;
close IN;
ok($lines[1] =~ /Hello!/);
# Ensure stray newline in name escaping works.
$out = tie *FAKEOUT, 'TieOut';
$Test->output(\*FAKEOUT);
$Test->exported_to(__PACKAGE__);
$Test->no_ending(1);
$Test->plan(tests => 5);
$Test->ok(1, "ok");
$Test->ok(1, "ok\n");
$Test->ok(1, "ok, like\nok");
$Test->skip("wibble\nmoof");
$Test->todo_skip("todo\nskip\n");
my $output = $out->read;
ok( $output eq <<OUTPUT ) || print STDERR $output;
1..5
ok 1 - ok
ok 2 - ok
#
ok 3 - ok, like
# ok
ok 4 # skip wibble
# moof
not ok 5 # TODO & SKIP todo
# skip
#
OUTPUT
|