Skip to content

Instantly share code, notes, and snippets.

@koko-u
Created September 16, 2012 05:28
Show Gist options
  • Save koko-u/3731122 to your computer and use it in GitHub Desktop.
Save koko-u/3731122 to your computer and use it in GitHub Desktop.
Use of Hook::LexWrap in Test::More for testBefore alternatives
use warnings;
use strict;
use utf8;
use Test::Most;
my $builder = Test::More->builder;
binmode $builder->output, ":utf8";
binmode $builder->failure_output, ":utf8";
binmode $builder->todo_output, ":utf8";
use Hook::LexWrap;
subtest "description" => sub {
subtest "context1" => sub {
my $before = wrap subtest, pre => sub { note "before hook" };
subtest "first test" => sub {
pass "test1";
pass "test2";
};
subtest "second test" => sub {
pass "test3";
pass "test4";
};
};
subtest "context2" => sub {
my $before = wrap subtest, pre => sub { note "another hook" };
subtest "exceptional test1" => sub {
pass "test a";
pass "test b";
};
subtest "exceptional test2" => sub {
pass "test c";
pass "test d";
};
};
};
done_testing;
@koko-u
Copy link
Author

koko-u commented Sep 16, 2012

To use various hooks depending on the various contexts, set the hook to lexical variables.
Exiting the subtest scope, then disappear the hook which used that context.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment