1#!perl -w 2 3BEGIN { 4 if( $ENV{PERL_CORE} ) { 5 chdir 't'; 6 @INC = '../lib'; 7 } 8} 9 10use Test::More tests => 15; 11 12# If we skip with the same name, Test::Harness will report it back and 13# we won't get lots of false bug reports. 14my $Why = "Just testing the skip interface."; 15 16SKIP: { 17 skip $Why, 2 18 unless Pigs->can('fly'); 19 20 my $pig = Pigs->new; 21 $pig->takeoff; 22 23 ok( $pig->altitude > 0, 'Pig is airborne' ); 24 ok( $pig->airspeed > 0, ' and moving' ); 25} 26 27 28SKIP: { 29 skip "We're not skipping", 2 if 0; 30 31 pass("Inside skip block"); 32 pass("Another inside"); 33} 34 35 36SKIP: { 37 skip "Again, not skipping", 2 if 0; 38 39 my($pack, $file, $line) = caller; 40 is( $pack || '', '', 'calling package not interfered with' ); 41 is( $file || '', '', ' or file' ); 42 is( $line || '', '', ' or line' ); 43} 44 45 46SKIP: { 47 skip $Why, 2 if 1; 48 49 die "A horrible death"; 50 fail("Deliberate failure"); 51 fail("And again"); 52} 53 54 55{ 56 my $warning; 57 local $SIG{__WARN__} = sub { $warning = join "", @_ }; 58 SKIP: { 59 # perl gets the line number a little wrong on the first 60 # statement inside a block. 61 1 == 1; 62#line 56 63 skip $Why; 64 fail("So very failed"); 65 } 66 is( $warning, "skip() needs to know \$how_many tests are in the ". 67 "block at $0 line 56\n", 68 'skip without $how_many warning' ); 69} 70 71 72SKIP: { 73 skip "Not skipping here.", 4 if 0; 74 75 pass("This is supposed to run"); 76 77 # Testing out nested skips. 78 SKIP: { 79 skip $Why, 2; 80 fail("AHHH!"); 81 fail("You're a failure"); 82 } 83 84 pass("This is supposed to run, too"); 85} 86 87