Move Test::Simple from lib to ext.
[p5sagit/p5-mst-13.2.git] / ext / Test-Simple / t / todo.t
CommitLineData
33459055 1#!perl -w
2
d020a79a 3BEGIN {
a9153838 4 if( $ENV{PERL_CORE} ) {
5 chdir 't';
6 @INC = '../lib';
7 }
33459055 8}
9
30e302f8 10use Test::More;
11
ccbd73a4 12plan tests => 36;
30e302f8 13
14
d020a79a 15$Why = 'Just testing the todo interface.';
16
7483b81c 17my $is_todo;
d020a79a 18TODO: {
19 local $TODO = $Why;
20
21 fail("Expected failure");
22 fail("Another expected failure");
d020a79a 23
7483b81c 24 $is_todo = Test::More->builder->todo;
25}
d020a79a 26
27pass("This is not todo");
7483b81c 28ok( $is_todo, 'TB->todo' );
d020a79a 29
30
31TODO: {
32 local $TODO = $Why;
33
34 fail("Yet another failure");
35}
36
37pass("This is still not todo");
0cd946aa 38
39
40TODO: {
41 local $TODO = "testing that error messages don't leak out of todo";
42
43 ok( 'this' eq 'that', 'ok' );
44
3e887aae 45 like( 'this', qr/that/, 'like' );
0cd946aa 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}
a9153838 54
55
56TODO: {
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}
0257f296 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;
ccbd73a4 72#line 74
0257f296 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 ".
ccbd73a4 77 "block at $0 line 74\n",
0257f296 78 'todo_skip without $how_many warning' );
79}
705e6672 80
ccbd73a4 81my $builder = Test::More->builder;
82my $exported_to = $builder->exported_to;
04955c14 83TODO: {
ccbd73a4 84 $builder->exported_to("Wibble");
04955c14 85
86 local $TODO = "testing \$TODO with an incorrect exported_to()";
87
88 fail("Just testing todo");
89}
ccbd73a4 90
91$builder->exported_to($exported_to);
92
93$builder->todo_start('Expected failures');
94fail('Testing todo_start()');
95ok 0, 'Testing todo_start() with more than one failure';
96$is_todo = $builder->todo;
97$builder->todo_end;
98is $is_todo, 'Expected failures',
99 'todo_start should have the correct TODO message';
100ok 1, 'todo_end() should not leak TODO behavior';
101
102my @nested_todo;
103my ( $level1, $level2 ) = ( 'failure level 1', 'failure_level 2' );
104TODO: {
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}
124is_deeply \@nested_todo, [ $level1, $level2, $level1 ],
125 'Nested TODO message should be correct';
126is $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
140eval {
141 $builder->todo_end;
142};
143is $@, 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}