From: Vincent Pit Date: Mon, 27 Dec 2010 21:48:17 +0000 (+0100) Subject: Add tap_stream()/diag_stream() X-Git-Tag: v0.01~15 X-Git-Url: http://git.vpit.fr/?p=perl%2Fmodules%2FTest-Leaner.git;a=commitdiff_plain;h=da6dd0b8533e32433851119428d3bc4e1959599c Add tap_stream()/diag_stream() --- diff --git a/lib/Test/Leaner.pm b/lib/Test/Leaner.pm index c1b8df4..92f386f 100644 --- a/lib/Test/Leaner.pm +++ b/lib/Test/Leaner.pm @@ -52,14 +52,7 @@ BEGIN { } } -my $TAP_STREAM = *STDOUT; -my $DIAG_STREAM = *STDERR; - -for ($TAP_STREAM, $DIAG_STREAM) { - my $fh = select $_; - $|++; - select $fh; -} +my ($TAP_STREAM, $DIAG_STREAM); my ($plan, $test, $failed, $no_diag, $done_testing); @@ -505,6 +498,58 @@ END { L, L, L, L, L, L, L and L are all guaranteed to return the truth value of the test. Their L counterparts behave the same, but it is not documented anywhere. +L also provides some functions of its own, which are never exported. + +=head2 C + +Read/write accessor for the filehandle to which the tests are outputted. +On write, it also turns autoflush on onto C<$fh>. + +Note that it can only be used as a write accessor before you start any thread, as L cannot reliably share filehandles. + +Defaults to C. + +=cut + +sub tap_stream (;*) { + if (@_) { + $TAP_STREAM = $_[0]; + + my $fh = select $TAP_STREAM; + $|++; + select $fh; + } + + return $TAP_STREAM; +} + +tap_stream *STDOUT; + +=head2 C + +Read/write accessor for the filehandle to which the diagnostics are printed. +On write, it also turns autoflush on onto C<$fh>. + +Just like L, it can only be used as a write accessor before you start any thread, as L cannot reliably share filehandles. + +Defaults to C. + +=cut + +sub diag_stream (;*) { + if (@_) { + $DIAG_STREAM = $_[0]; + + my $fh = select $DIAG_STREAM; + $|++; + select $fh; + } + + return $DIAG_STREAM; +} + +diag_stream *STDERR; + =head1 DEPENDENCIES L 5.6.