Upgrade to Test-Simple-0.82.
[p5sagit/p5-mst-13.2.git] / lib / Test / Simple / t / todo.t
1 #!perl -w
2 # $Id: /mirror/googlecode/test-more-trunk/t/todo.t 62094 2008-09-19T07:21:50.720642Z schwern  $
3
4 BEGIN {
5     if( $ENV{PERL_CORE} ) {
6         chdir 't';
7         @INC = '../lib';
8     }
9 }
10
11 use Test::More;
12
13 plan tests => 36;
14
15
16 $Why = 'Just testing the todo interface.';
17
18 my $is_todo;
19 TODO: {
20     local $TODO = $Why;
21
22     fail("Expected failure");
23     fail("Another expected failure");
24
25     $is_todo = Test::More->builder->todo;
26 }
27
28 pass("This is not todo");
29 ok( $is_todo, 'TB->todo' );
30
31
32 TODO: {
33     local $TODO = $Why;
34
35     fail("Yet another failure");
36 }
37
38 pass("This is still not todo");
39
40
41 TODO: {
42     local $TODO = "testing that error messages don't leak out of todo";
43
44     ok( 'this' eq 'that',   'ok' );
45
46     like( 'this', '/that/', 'like' );
47     is(   'this', 'that',   'is' );
48     isnt( 'this', 'this',   'isnt' );
49
50     can_ok('Fooble', 'yarble');
51     isa_ok('Fooble', 'yarble');
52     use_ok('Fooble');
53     require_ok('Fooble');
54 }
55
56
57 TODO: {
58     todo_skip "Just testing todo_skip", 2;
59
60     fail("Just testing todo");
61     die "todo_skip should prevent this";
62     pass("Again");
63 }
64
65
66 {
67     my $warning;
68     local $SIG{__WARN__} = sub { $warning = join "", @_ };
69     TODO: {
70         # perl gets the line number a little wrong on the first
71         # statement inside a block.
72         1 == 1;
73 #line 74
74         todo_skip "Just testing todo_skip";
75         fail("So very failed");
76     }
77     is( $warning, "todo_skip() needs to know \$how_many tests are in the ".
78                   "block at $0 line 74\n",
79         'todo_skip without $how_many warning' );
80 }
81
82 my $builder = Test::More->builder;
83 my $exported_to = $builder->exported_to;
84 TODO: {
85     $builder->exported_to("Wibble");
86     
87     local $TODO = "testing \$TODO with an incorrect exported_to()";
88     
89     fail("Just testing todo");
90 }
91
92 $builder->exported_to($exported_to);
93
94 $builder->todo_start('Expected failures');
95 fail('Testing todo_start()');
96 ok 0, 'Testing todo_start() with more than one failure';
97 $is_todo = $builder->todo;
98 $builder->todo_end;
99 is $is_todo, 'Expected failures',
100   'todo_start should have the correct TODO message';
101 ok 1, 'todo_end() should not leak TODO behavior';
102
103 my @nested_todo;
104 my ( $level1, $level2 ) = ( 'failure level 1', 'failure_level 2' );
105 TODO: {
106     local $TODO = 'Nesting TODO';
107     fail('fail 1');
108
109     $builder->todo_start($level1);
110     fail('fail 2');
111
112     push @nested_todo => $builder->todo;
113     $builder->todo_start($level2);
114     fail('fail 3');
115
116     push @nested_todo => $builder->todo;
117     $builder->todo_end;
118     fail('fail 4');
119
120     push @nested_todo => $builder->todo;
121     $builder->todo_end;
122     $is_todo = $builder->todo;
123     fail('fail 4');
124 }
125 is_deeply \@nested_todo, [ $level1, $level2, $level1 ],
126   'Nested TODO message should be correct';
127 is $is_todo, 'Nesting TODO',
128   '... and original TODO message should be correct';
129
130 {
131     $builder->todo_start;
132     fail("testing todo_start() with no message");
133     my $reason  = $builder->todo;
134     my $in_todo = $builder->in_todo;
135     $builder->todo_end;
136
137     is $reason, '', "  todo() reports no reason";
138     ok $in_todo,    "  but we're in_todo()";
139 }
140
141 eval {
142     $builder->todo_end;
143 };
144 is $@, sprintf "todo_end() called without todo_start() at %s line %d.\n", $0, __LINE__ - 2;
145
146
147 {
148     my($reason, $in_todo);
149
150     TODO: {
151         local $TODO = '';
152         $reason  = $builder->todo;
153         $in_todo = $builder->in_todo;
154     }
155
156     is $reason, '';
157     ok !$in_todo, '$TODO = "" is not considered TODO';
158 }