Skip to content

Instantly share code, notes, and snippets.

@exodist
Last active June 17, 2016 02:30
Show Gist options
  • Save exodist/72fc7644259cead55c52b3ad7c993ac2 to your computer and use it in GitHub Desktop.
Save exodist/72fc7644259cead55c52b3ad7c993ac2 to your computer and use it in GitHub Desktop.
use Test2::API qw/context run_subtest intercept/;
use Test2::Tools::Basic;
use strict;
use warnings;
sub is_int { 1 }; # Stub
sub is_even {
my ($thing, $name) = @_;
my $ctx = context();
my $pass = run_subtest($name, sub {
my $st_ctx = context();
$st_ctx->ok(is_int($thing), 'Thing is an int');
$st_ctx->ok(!($thing % 2), "Thing is event");
$st_ctx->release;
}, {buffered => 1, inherit_trace => 1});
$ctx->release;
return $pass;
}
my $pass;
intercept { $pass = is_even(1, "1 is not even") };
ok(!$pass, "is_event(1) returned false");
ok(is_even(2, "2 is even"), "is_even(2) returned true");
done_testing;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment