0f3c31de5b136756fb20824b8c2460bc370786b3
[perl.git] / lib / Test / Simple / t / Builder / details.t
1 #!/usr/bin/perl -w
2 # $Id: /mirror/googlecode/test-more/t/Builder/details.t 60332 2008-09-09T12:24:03.060291Z schwern  $
3
4 BEGIN {
5     if( $ENV{PERL_CORE} ) {
6         chdir 't';
7         @INC = ('../lib', 'lib');
8     }
9     else {
10         unshift @INC, 't/lib';
11     }
12 }
13
14 use Test::More;
15 use Test::Builder;
16 my $Test = Test::Builder->new;
17
18 $Test->plan( tests => 9 );
19 $Test->level(0);
20
21 my @Expected_Details;
22
23 $Test->is_num( scalar $Test->summary(), 0,   'no tests yet, no summary' );
24 push @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.
33 my $out_fh  = $Test->output;
34 my $todo_fh = $Test->todo_output;
35 my $start_test = $Test->current_test + 1;
36 require TieOut;
37 tie *FH, 'TieOut';
38 $Test->output(\*FH);
39 $Test->todo_output(\*FH);
40
41 SKIP: {
42     $Test->skip( 'just testing skip' );
43 }
44 push @Expected_Details, { 'ok'      => 1,
45                           actual_ok => 1,
46                           name      => '',
47                           type      => 'skip',
48                           reason    => 'just testing skip',
49                         };
50
51 TODO: {
52     local $TODO = 'i need a todo';
53     $Test->ok( 0, 'a test to todo!' );
54
55     push @Expected_Details, { 'ok'       => 1,
56                               actual_ok  => 0,
57                               name       => 'a test to todo!',
58                               type       => 'todo',
59                               reason     => 'i need a todo',
60                             };
61
62     $Test->todo_skip( 'i need both' );
63 }
64 push @Expected_Details, { 'ok'      => 1,
65                           actual_ok => 0,
66                           name      => '',
67                           type      => 'todo_skip',
68                           reason    => 'i need both'
69                         };
70
71 for ($start_test..$Test->current_test) { print "ok $_\n" }
72 $Test->output($out_fh);
73 $Test->todo_output($todo_fh);
74
75 $Test->is_num( scalar $Test->summary(), 4,   'summary' );
76 push @Expected_Details, { 'ok'      => 1,
77                           actual_ok => 1,
78                           name      => 'summary',
79                           type      => '',
80                           reason    => '',
81                         };
82
83 $Test->current_test(6);
84 print "ok 6 - current_test incremented\n";
85 push @Expected_Details, { 'ok'      => 1,
86                           actual_ok => undef,
87                           name      => undef,
88                           type      => 'unknown',
89                           reason    => 'incrementing test number',
90                         };
91
92 my @details = $Test->details();
93 $Test->is_num( scalar @details, 6,
94     'details() should return a list of all test details');
95
96 $Test->level(1);
97 is_deeply( \@details, \@Expected_Details );
98
99
100 # This test has to come last because it thrashes the test details.
101 {
102     my $curr_test = $Test->current_test;
103     $Test->current_test(4);
104     my @details = $Test->details();
105
106     $Test->current_test($curr_test);
107     $Test->is_num( scalar @details, 4 );
108 }