Browse files

Add Test::IO::Capture. With tests for itself :)

  • Loading branch information...
1 parent 9d93929 commit 2a4a279f2771490c0d3f0f5924106aae5bb49d10 @tadzik tadzik committed Apr 16, 2012
Showing with 26 additions and 0 deletions.
  1. +16 −0 lib/Test/IO/Capture.pm
  2. +10 −0 t/test-io-capture/01-basic.t
View
16 lib/Test/IO/Capture.pm
@@ -0,0 +1,16 @@
+use Test;
+use IO::Capture::Simple;
+
+module Test::IO::Capture;
+
+sub prints-stdout-ok (Callable $code, $expected as Str, $reason = '')
+is export {
+ my $out = capture_stdout $code;
+ is $out, $expected, $reason;
+}
+
+sub prints-stderr-ok (Callable $code, $expected as Str, $reason = '')
+is export {
+ my $out = capture_stderr $code;
+ is $out, $expected, $reason;
+}
View
10 t/test-io-capture/01-basic.t
@@ -0,0 +1,10 @@
+use Test::IO::Capture;
+use Test;
+
+plan 3;
+
+prints-stdout-ok { say 'zebra!' }, "zebra!\n", 'prints-stdout-ok';
+
+prints-stderr-ok { note 'giraffe!' }, "giraffe!\n", 'prints-stderr-ok';
+
+pass 'if this works, then stdout is back to normal';

0 comments on commit 2a4a279

Please sign in to comment.