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