Commit | Line | Data |
33459055 |
1 | #!perl -w |
ccbd73a4 |
2 | # $Id: /mirror/googlecode/test-more-trunk/t/todo.t 62094 2008-09-19T07:21:50.720642Z schwern $ |
33459055 |
3 | |
d020a79a |
4 | BEGIN { |
a9153838 |
5 | if( $ENV{PERL_CORE} ) { |
6 | chdir 't'; |
7 | @INC = '../lib'; |
8 | } |
33459055 |
9 | } |
10 | |
30e302f8 |
11 | use Test::More; |
12 | |
ccbd73a4 |
13 | plan tests => 36; |
30e302f8 |
14 | |
15 | |
d020a79a |
16 | $Why = 'Just testing the todo interface.'; |
17 | |
7483b81c |
18 | my $is_todo; |
d020a79a |
19 | TODO: { |
20 | local $TODO = $Why; |
21 | |
22 | fail("Expected failure"); |
23 | fail("Another expected failure"); |
d020a79a |
24 | |
7483b81c |
25 | $is_todo = Test::More->builder->todo; |
26 | } |
d020a79a |
27 | |
28 | pass("This is not todo"); |
7483b81c |
29 | ok( $is_todo, 'TB->todo' ); |
d020a79a |
30 | |
31 | |
32 | TODO: { |
33 | local $TODO = $Why; |
34 | |
35 | fail("Yet another failure"); |
36 | } |
37 | |
38 | pass("This is still not todo"); |
0cd946aa |
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 | } |
a9153838 |
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 | } |
0257f296 |
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; |
ccbd73a4 |
73 | #line 74 |
0257f296 |
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 ". |
ccbd73a4 |
78 | "block at $0 line 74\n", |
0257f296 |
79 | 'todo_skip without $how_many warning' ); |
80 | } |
705e6672 |
81 | |
ccbd73a4 |
82 | my $builder = Test::More->builder; |
83 | my $exported_to = $builder->exported_to; |
04955c14 |
84 | TODO: { |
ccbd73a4 |
85 | $builder->exported_to("Wibble"); |
04955c14 |
86 | |
87 | local $TODO = "testing \$TODO with an incorrect exported_to()"; |
88 | |
89 | fail("Just testing todo"); |
90 | } |
ccbd73a4 |
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 | } |