summaryrefslogtreecommitdiffstats
path: root/gnu/usr.bin/perl/cpan/Test-Simple/t/regression/721-nested-streamed-subtest.t
blob: a8a82870596b1152abd337f78c4b620dab8dffa8 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
use strict;
use warnings;

use Test2::Tools::Tiny;

# This module's exports interfere with the ones in t/tools.pl
use Test::More ();
use Test::Builder::Formatter();
use Test2::API qw/run_subtest test2_stack/;

{
    test2_stack->top;
    my $temp_hub = test2_stack->new_hub();
    $temp_hub->format(Test::Builder::Formatter->new());

    my $output = capture {
        run_subtest(
            'parent',
            sub {
                run_subtest(
                    'buffered',
                    sub {
                        ok(1, 'b1');
                        ok(1, 'b2');
                    },
                    {buffered => 1},
                );
                run_subtest(
                    'streamed',
                    sub {
                        ok(1, 's1');
                        ok(1, 's2');
                    },
                    {buffered => 0},
                );
            },
            {buffered => 1},
        );
    };

    test2_stack->pop($temp_hub);

    Test::More::subtest(
        'Test2::API::run_subtest',
        sub {
            is($output->{STDERR}, q{}, 'no output on stderr');
            like($output->{STDOUT}, qr/ +ok 1 - b1/, 'got ok output for tests in buffered subtest');
            like($output->{STDOUT}, qr/ +ok 2 - b2/, 'got ok output for tests in buffered subtest');
            like($output->{STDOUT}, qr/ +ok 1 - s1/, 'got ok output for tests in streamed subtest');
            like($output->{STDOUT}, qr/ +ok 2 - s2/, 'got ok output for tests in streamed subtest');
        }
    );
}

{
    test2_stack->top;
    my $temp_hub = test2_stack->new_hub();
    $temp_hub->format(Test::Builder::Formatter->new());

    my $output = capture {
        run_subtest(
            'parent',
            sub {
                run_subtest(
                    'buffered',
                    sub {
                        ok(1, 'b1');
                        ok(1, 'b2');
                    },
                    {buffered => 1},
                );
                Test::More::subtest(
                    'streamed',
                    sub {
                        ok(1, 's1');
                        ok(1, 's2');
                    },
                    {buffered => 0},
                );
            },
            {buffered => 1},
        );
    };

    test2_stack->pop($temp_hub);

    Test::More::subtest(
        'Test::More::subtest and Test2::API::run_subtest',
        sub {
            is($output->{STDERR}, q{}, 'no output on stderr');
            like($output->{STDOUT}, qr/ +ok 1 - b1/, 'got ok output for tests in buffered subtest');
            like($output->{STDOUT}, qr/ +ok 2 - b2/, 'got ok output for tests in buffered subtest');
            like($output->{STDOUT}, qr/ +ok 1 - s1/, 'got ok output for tests in streamed subtest');
            like($output->{STDOUT}, qr/ +ok 2 - s2/, 'got ok output for tests in streamed subtest');
        }
    );
}

done_testing;