1Test2::Tools::Subtest(3U)ser Contributed Perl DocumentatiToenst2::Tools::Subtest(3)
2
3
4

NAME

6       Test2::Tools::Subtest - Tools for writing subtests
7

DESCRIPTION

9       This package exports subs that let you write subtests.
10
11       There are two types of subtests, buffered and streamed. Streamed
12       subtests mimic subtests from Test::More in that they render all events
13       as soon as they are produced. Buffered subtests wait until the subtest
14       completes before rendering any results.
15
16       The main difference is that streamed subtests are unreadable when
17       combined with concurrency. Buffered subtests look fine with any number
18       of concurrent threads and processes.
19

SYNOPSIS

21   BUFFERED
22           use Test2::Tools::Subtest qw/subtest_buffered/;
23
24           subtest_buffered my_test => sub {
25               ok(1, "subtest event A");
26               ok(1, "subtest event B");
27           };
28
29       This will produce output like this:
30
31           ok 1 - my_test {
32               ok 1 - subtest event A
33               ok 2 - subtest event B
34               1..2
35           }
36
37   STREAMED
38       The default option is 'buffered'. If you want streamed subtests, the
39       way Test::Builder does it, use this:
40
41           use Test2::Tools::Subtest qw/subtest_streamed/;
42
43           subtest_streamed my_test => sub {
44               ok(1, "subtest event A");
45               ok(1, "subtest event B");
46           };
47
48       This will produce output like this:
49
50           # Subtest: my_test
51               ok 1 - subtest event A
52               ok 2 - subtest event B
53               1..2
54           ok 1 - Subtest: my_test
55

IMPORTANT NOTE

57       You can use "bail_out" or "skip_all" in a subtest, but not in a BEGIN
58       block or "use" statement. This is due to the way flow control works
59       within a BEGIN block. This is not normally an issue, but can happen in
60       rare conditions using eval, or script files as subtests.
61

EXPORTS

63       subtest_streamed $name => $sub
64       subtest_streamed($name, $sub, @args)
65       subtest_streamed $name => \%params, $sub
66       subtest_streamed($name, \%params, $sub, @args)
67           Run subtest coderef, stream events as they happen.
68
69           "\%params" is a hashref with any arguments you wish to pass into
70           hub construction.
71
72       subtest_buffered $name => $sub
73       subtest_buffered($name, $sub, @args)
74       subtest_buffered $name => \%params, $sub
75       subtest_buffered($name, \%params, $sub, @args)
76           Run subtest coderef, render events all at once when subtest is
77           complete.
78
79           "\%params" is a hashref with any arguments you wish to pass into
80           hub construction.
81

SOURCE

83       The source code repository for Test2-Suite can be found at
84       https://github.com/Test-More/Test2-Suite/.
85

MAINTAINERS

87       Chad Granum <exodist@cpan.org>
88

AUTHORS

90       Chad Granum <exodist@cpan.org>
91
93       Copyright 2018 Chad Granum <exodist@cpan.org>.
94
95       This program is free software; you can redistribute it and/or modify it
96       under the same terms as Perl itself.
97
98       See http://dev.perl.org/licenses/
99
100
101
102perl v5.38.0                      2023-07-21          Test2::Tools::Subtest(3)
Impressum