line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Test2::Tools::AfterSubtest; |
2
|
1
|
|
|
1
|
|
104525
|
use strict; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
21
|
|
3
|
1
|
|
|
1
|
|
3
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
19
|
|
4
|
1
|
|
|
1
|
|
3
|
use base 'Exporter'; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
52
|
|
5
|
1
|
|
|
1
|
|
3
|
use Test2::API qw/context_do/; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
105
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
our @EXPORT = qw/after_subtest/; |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
sub after_subtest { |
10
|
|
|
|
|
|
|
context_do { |
11
|
1
|
|
|
1
|
|
3717
|
my ($ctx, $cb) = @_; |
12
|
|
|
|
|
|
|
$ctx->hub->listen(sub { |
13
|
7
|
100
|
|
|
|
2380
|
$cb->() if ref($_[1]) eq 'Test2::Event::Subtest'; |
14
|
1
|
|
|
|
|
4
|
}, inherit => 1); |
15
|
1
|
|
|
1
|
0
|
70
|
} @_; |
16
|
|
|
|
|
|
|
} |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
=pod |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
=encoding UTF-8 |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
=head1 NAME |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
Test2::Tools::AfterSubtest - Test2 after_subtest callback |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
=head1 DESCRIPTION |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
Exports an C function that can be passed a callback to be |
29
|
|
|
|
|
|
|
executed after every subtest. |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
Useful for things like cleaning up the database after each test. |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
=head1 SYNOPSIS |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
use Test2::Bundle::More; |
36
|
|
|
|
|
|
|
use Test2::Tools::AfterSubtest; |
37
|
|
|
|
|
|
|
after_subtest(sub { |
38
|
|
|
|
|
|
|
diag 'Subtest has finished; |
39
|
|
|
|
|
|
|
}); |
40
|
|
|
|
|
|
|
subtest 'test' => sub { |
41
|
|
|
|
|
|
|
ok('subtest runs'); |
42
|
|
|
|
|
|
|
}; |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
=cut |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
1; |