xref: /openbsd-src/gnu/usr.bin/perl/cpan/Test-Simple/t/Test2/behavior/Subtest_callback.t (revision 5759b3d249badf144a6240f7eec4dcf9df003e6b)
1use strict;
2use warnings;
3
4use Test2::Tools::Tiny;
5
6use Test2::API qw/run_subtest intercept/;
7
8my $step = 0;
9my @callback_calls = ();
10Test2::API::test2_add_callback_pre_subtest(
11    sub {
12        is(
13            $step,
14            0,
15            'pre-subtest callbacks should be invoked before the subtest',
16        );
17        ++$step;
18        push @callback_calls, [@_];
19    },
20);
21
22run_subtest(
23    (my $subtest_name='some subtest'),
24    (my $subtest_code=sub {
25         is(
26             $step,
27             1,
28             'subtest should be run after the pre-subtest callbacks',
29         );
30         ++$step;
31     }),
32    undef,
33    (my @subtest_args = (1,2,3)),
34);
35
36is_deeply(
37    \@callback_calls,
38    [[$subtest_name,$subtest_code,@subtest_args]],
39    'pre-subtest callbacks should be invoked with the expected arguments',
40);
41
42is(
43    $step,
44    2,
45    'the subtest should be run',
46);
47
48done_testing;
49