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