1#!/usr/bin/perl -w
2
3use strict;
4use lib 't/lib';
5
6# We're going to need to override exit() later
7BEGIN {
8    require Test2::Hub;
9    no warnings 'redefine';
10    *Test2::Hub::terminate = sub {
11        my $status = @_ ? 0 : shift;
12        CORE::exit $status;
13    };
14}
15
16use Test::More;
17use Test::Builder;
18use Test::Builder::NoOutput;
19
20{
21    my $tb = Test::Builder::NoOutput->create;
22    ok $tb->is_passing, "a fresh TB object is passing";
23
24    $tb->ok(1);
25    ok $tb->is_passing, "  still passing after a test";
26
27    $tb->ok(0);
28    ok !$tb->is_passing, "  not passing after a failing test";
29
30    $tb->ok(1);
31    ok !$tb->is_passing, "  a passing test doesn't resurrect it";
32
33    $tb->done_testing(3);
34    ok !$tb->is_passing, "  a successful plan doesn't help either";
35}
36
37
38# See if is_passing() notices a plan overrun
39{
40    my $tb = Test::Builder::NoOutput->create;
41    $tb->plan( tests => 1 );
42    $tb->ok(1);
43    ok $tb->is_passing, "Passing with a plan";
44
45    $tb->ok(1);
46    ok !$tb->is_passing, "  passing test, but it overran the plan";
47}
48
49
50# is_passing() vs no_plan
51{
52    my $tb = Test::Builder::NoOutput->create;
53    $tb->plan( "no_plan" );
54    ok $tb->is_passing, "Passing with no_plan";
55
56    $tb->ok(1);
57    ok $tb->is_passing, "  still passing after a test";
58
59    $tb->ok(1);
60    ok $tb->is_passing, "  and another test";
61
62    $tb->_ending;
63    ok $tb->is_passing, "  and after the ending";
64}
65
66# is_passing() vs skip_all
67{
68    my $tb = Test::Builder::NoOutput->create;
69
70    {
71        no warnings 'redefine';
72        local *Test2::Hub::terminate = sub { 1 };
73
74        $tb->plan( "skip_all" );
75    }
76    ok $tb->is_passing, "Passing with skip_all";
77}
78
79# is_passing() vs done_testing(#)
80{
81    my $tb = Test::Builder::NoOutput->create;
82    $tb->ok(1);
83    $tb->done_testing(2);
84    ok !$tb->is_passing, "All tests passed but done_testing() does not match";
85}
86
87
88# is_passing() with no tests run vs done_testing()
89{
90    my $tb = Test::Builder::NoOutput->create;
91    $tb->done_testing();
92    ok !$tb->is_passing, "No tests run with done_testing()";
93}
94
95
96# is_passing() with no tests run vs done_testing()
97{
98    my $tb = Test::Builder::NoOutput->create;
99    $tb->ok(1);
100    $tb->done_testing();
101    ok $tb->is_passing, "All tests passed with done_testing()";
102}
103
104
105done_testing();
106