1 package Test::Builder::NoOutput;
6 use base qw(Test::Builder);
11 Test::Builder::NoOutput - A subclass of Test::Builder which prints nothing
15 use Test::Builder::NoOutput;
17 my $tb = Test::Builder::NoOutput->new;
21 my $output = $tb->read;
25 This is a subclass of Test::Builder which traps all its output.
26 It is mostly useful for testing Test::Builder.
30 my $all_output = $tb->read;
31 my $output = $tb->read($stream);
33 Returns all the output (including failure and todo output) collected
34 so far. It is destructive, each call to read clears the output
37 If $stream is given it will return just the output from that stream.
49 my $Test = __PACKAGE__->new;
53 my $self = $class->SUPER::create(@_);
61 $self->{_outputs} = \%outputs;
63 tie *OUT, "Test::Builder::NoOutput::Tee", \$outputs{all}, \$outputs{out};
64 tie *ERR, "Test::Builder::NoOutput::Tee", \$outputs{all}, \$outputs{err};
65 tie *TODO, "Test::Builder::NoOutput::Tee", \$outputs{all}, \$outputs{todo};
68 $self->failure_output(*ERR);
69 $self->todo_output(*TODO);
76 my $stream = @_ ? shift : 'all';
78 my $out = $self->{_outputs}{$stream};
80 $self->{_outputs}{$stream} = '';
82 # Clear all the streams if 'all' is read.
83 if( $stream eq 'all' ) {
84 my @keys = keys %{$self->{_outputs}};
85 $self->{_outputs}{$_} = '' for @keys;
92 package Test::Builder::NoOutput::Tee;
94 # A cheap implementation of IO::Tee.
97 my($class, @refs) = @_;
100 for my $ref (@refs) {
101 my $fh = Test::Builder->_new_fh($ref);
106 return bless $self, $class;
112 print $_ @_ for @$self;
119 printf $_ @_ for @$self;