Skip to content

Instantly share code, notes, and snippets.

@zoffixznet
Created January 7, 2016 18:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zoffixznet/468cde2b29e869b8c687 to your computer and use it in GitHub Desktop.
Save zoffixznet/468cde2b29e869b8c687 to your computer and use it in GitHub Desktop.
unit module Test::Output;
my class IO::Capture::Single is IO::Handle {
has @.contents;
method print (*@what) { @.contents.push: @what.join: ''; }
method print-nl { self.print($.nl-out); }
method Str (*@what) { return @.contents.join: ''; }
}
sub output-is (&code, Regex $expected, $test-name = 'output matches' )
is export
{
my $out = IO::Capture::Single.new;
my $err = IO::Capture::Single.new;
{
my $*OUT = $out;
my $*ERR = $err;
&code();
}
say "Output is $out";
say "STDERR is $err";
return :out(~$out), :err(~$err);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment