Created
September 16, 2012 05:28
-
-
Save koko-u/3731122 to your computer and use it in GitHub Desktop.
Use of Hook::LexWrap in Test::More for testBefore alternatives
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.