]> git.vpit.fr Git - perl/modules/Test-Leaner.git/commitdiff
Add tap_stream()/diag_stream()
authorVincent Pit <vince@profvince.com>
Mon, 27 Dec 2010 21:48:17 +0000 (22:48 +0100)
committerVincent Pit <vince@profvince.com>
Mon, 27 Dec 2010 22:35:19 +0000 (23:35 +0100)
lib/Test/Leaner.pm

index c1b8df4b712334a900802ec34b9260407b905f2e..92f386f6402913e7bfd40a71d3e8a2ac5870c507 100644 (file)
@@ -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);
 
 
 my ($plan, $test, $failed, $no_diag, $done_testing);
 
@@ -505,6 +498,58 @@ END {
 L</pass>, L</fail>, L</ok>, L</is>, L</isnt>, L</like>, L</unlike> and L</cmp_ok> are all guaranteed to return the truth value of the test.
 Their L<Test::More> counterparts behave the same, but it is not documented anywhere.
 
 L</pass>, L</fail>, L</ok>, L</is>, L</isnt>, L</like>, L</unlike> and L</cmp_ok> are all guaranteed to return the truth value of the test.
 Their L<Test::More> counterparts behave the same, but it is not documented anywhere.
 
+L<Test::Leaner> also provides some functions of its own, which are never exported.
+
+=head2 C<tap_stream [ $fh ]>
+
+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<threads::shared> cannot reliably share filehandles.
+
+Defaults to C<STDOUT>.
+
+=cut
+
+sub tap_stream (;*) {
+ if (@_) {
+  $TAP_STREAM = $_[0];
+
+  my $fh = select $TAP_STREAM;
+  $|++;
+  select $fh;
+ }
+
+ return $TAP_STREAM;
+}
+
+tap_stream *STDOUT;
+
+=head2 C<diag_stream [ $fh ]>
+
+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</tap_stream>, it can only be used as a write accessor before you start any thread, as L<threads::shared> cannot reliably share filehandles.
+
+Defaults to C<STDERR>.
+
+=cut
+
+sub diag_stream (;*) {
+ if (@_) {
+  $DIAG_STREAM = $_[0];
+
+  my $fh = select $DIAG_STREAM;
+  $|++;
+  select $fh;
+ }
+
+ return $DIAG_STREAM;
+}
+
+diag_stream *STDERR;
+
 =head1 DEPENDENCIES
 
 L<perl> 5.6.
 =head1 DEPENDENCIES
 
 L<perl> 5.6.