1#!/usr/bin/perl -w
2
3# What happens when a subtest dies?
4
5use lib 't/lib';
6
7use strict;
8use Test::More;
9use Test::Builder;
10use Test2::API;
11
12my $Test = Test::Builder->new;
13
14my $step = 0;
15my @callback_calls = ();
16Test2::API::test2_add_callback_pre_subtest(
17    sub {
18        $Test->is_num(
19            $step,
20            0,
21            'pre-subtest callbacks should be invoked before the subtest',
22        );
23        ++$step;
24        push @callback_calls, [@_];
25    },
26);
27
28$Test->subtest(
29    (my $subtest_name='some subtest'),
30    (my $subtest_code=sub {
31         $Test->is_num(
32             $step,
33             1,
34             'subtest should be run after the pre-subtest callbacks',
35         );
36         ++$step;
37     }),
38    (my @subtest_args = (1,2,3)),
39);
40
41is_deeply(
42    \@callback_calls,
43    [[$subtest_name,$subtest_code,@subtest_args]],
44    'pre-subtest callbacks should be invoked with the expected arguments',
45);
46
47$Test->is_num(
48    $step,
49    2,
50    'the subtest should be run',
51);
52
53$Test->done_testing();
54