1#!perl -w 2 3BEGIN { 4 if( $ENV{PERL_CORE} ) { 5 chdir 't'; 6 @INC = '../lib'; 7 } 8} 9 10use Test::More; 11 12plan tests => 36; 13 14 15$Why = 'Just testing the todo interface.'; 16 17my $is_todo; 18TODO: { 19 local $TODO = $Why; 20 21 fail("Expected failure"); 22 fail("Another expected failure"); 23 24 $is_todo = Test::More->builder->todo; 25} 26 27pass("This is not todo"); 28ok( $is_todo, 'TB->todo' ); 29 30 31TODO: { 32 local $TODO = $Why; 33 34 fail("Yet another failure"); 35} 36 37pass("This is still not todo"); 38 39 40TODO: { 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 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} 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 81my $builder = Test::More->builder; 82my $exported_to = $builder->exported_to; 83TODO: { 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'); 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__ - 3; 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} 158