1#!/usr/bin/perl -w
2# HARNESS-NO-STREAM
3
4BEGIN {
5    if( $ENV{PERL_CORE} ) {
6        chdir 't';
7        @INC = ('../lib', 'lib');
8    }
9    else {
10        unshift @INC, 't/lib';
11    }
12}
13
14use Test::More;
15use Test::Builder;
16my $Test = Test::Builder->new;
17
18$Test->plan( tests => 9 );
19$Test->level(0);
20
21my @Expected_Details;
22
23$Test->is_num( scalar $Test->summary(), 0,   'no tests yet, no summary' );
24push @Expected_Details, { 'ok'      => 1,
25                          actual_ok => 1,
26                          name      => 'no tests yet, no summary',
27                          type      => '',
28                          reason    => ''
29                        };
30
31# Inline TODO tests will confuse pre 1.20 Test::Harness, so we
32# should just avoid the problem and not print it out.
33my $start_test = $Test->current_test + 1;
34
35my $output = '';
36$Test->output(\$output);
37$Test->todo_output(\$output);
38
39SKIP: {
40    $Test->skip( 'just testing skip' );
41}
42push @Expected_Details, { 'ok'      => 1,
43                          actual_ok => 1,
44                          name      => '',
45                          type      => 'skip',
46                          reason    => 'just testing skip',
47                        };
48
49TODO: {
50    local $TODO = 'i need a todo';
51    $Test->ok( 0, 'a test to todo!' );
52
53    push @Expected_Details, { 'ok'       => 1,
54                              actual_ok  => 0,
55                              name       => 'a test to todo!',
56                              type       => 'todo',
57                              reason     => 'i need a todo',
58                            };
59
60    $Test->todo_skip( 'i need both' );
61}
62push @Expected_Details, { 'ok'      => 1,
63                          actual_ok => 0,
64                          name      => '',
65                          type      => 'todo_skip',
66                          reason    => 'i need both'
67                        };
68
69for ($start_test..$Test->current_test) { print "ok $_\n" }
70$Test->reset_outputs;
71
72$Test->is_num( scalar $Test->summary(), 4,   'summary' );
73push @Expected_Details, { 'ok'      => 1,
74                          actual_ok => 1,
75                          name      => 'summary',
76                          type      => '',
77                          reason    => '',
78                        };
79
80$Test->current_test(6);
81print "ok 6 - current_test incremented\n";
82push @Expected_Details, { 'ok'      => 1,
83                          actual_ok => undef,
84                          name      => undef,
85                          type      => 'unknown',
86                          reason    => 'incrementing test number',
87                        };
88
89my @details = $Test->details();
90$Test->is_num( scalar @details, 6,
91    'details() should return a list of all test details');
92
93$Test->level(1);
94is_deeply( \@details, \@Expected_Details );
95
96
97# This test has to come last because it thrashes the test details.
98{
99    my $curr_test = $Test->current_test;
100    $Test->current_test(4);
101    my @details = $Test->details();
102
103    $Test->current_test($curr_test);
104    $Test->is_num( scalar @details, 4 );
105}
106