Skip to content
This repository has been archived by the owner on Oct 17, 2023. It is now read-only.

Commit

Permalink
stderr
Browse files Browse the repository at this point in the history
  • Loading branch information
Filip Sergot committed Apr 15, 2012
1 parent a839819 commit 9d93929
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 3 deletions.
27 changes: 25 additions & 2 deletions lib/IO/Capture/Simple.pm
@@ -1,6 +1,7 @@
module IO::Capture::Simple; module IO::Capture::Simple;


my $stdout = $*OUT; my $stdout = $*OUT;
my $stderr = $*ERR;


multi sub capture(Block $code) is export { multi sub capture(Block $code) is export {
... ...
Expand Down Expand Up @@ -29,13 +30,35 @@ multi sub capture_stdout($target is rw) {
} }


multi sub capture_stderr(Block $code) is export { multi sub capture_stderr(Block $code) is export {
... my $result;

my $*ERR = class {
method print(*@args) {
$result ~= @args.join;
}
}

$code.();

$result;
}

multi sub capture_stderr($target is rw) is export {
$*ERR = class {
method print(*@args) {
$target ~= @args.join;
}
}
} }


multi sub capture_stdin(Block $code) is export { multi sub capture_stdin(Block $code) is export {
... ...
} }


sub stdout_off is export { sub capture_stdout_off is export {
$*OUT = $stdout; $*OUT = $stdout;
} }

sub capture_stderr_off is export {
$*ERR = $stderr;
}
2 changes: 1 addition & 1 deletion t/t0.p6
Expand Up @@ -12,5 +12,5 @@ $r = '';


capture_stdout($r); capture_stdout($r);
print $test; print $test;
stdout_off; capture_stdout_off;
ok $r ~~ $test; ok $r ~~ $test;
18 changes: 18 additions & 0 deletions t/t1.p6
@@ -0,0 +1,18 @@
use IO::Capture::Simple;
use Test;

plan 2;

my $test = "OH HAI!";

my $r = capture_stderr { note $test }

ok $r ~~ /$test/;

$r = '';

capture_stderr($r);
note $test;
capture_stderr_off;

ok $r ~~ /$test/;

0 comments on commit 9d93929

Please sign in to comment.