This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Move Test::Simple from lib to ext.
[perl5.git] / ext / Test-Simple / t / skip.t
1 #!perl -w
2
3 BEGIN {
4     if( $ENV{PERL_CORE} ) {
5         chdir 't';
6         @INC = '../lib';
7     }
8 }
9
10 use Test::More tests => 17;
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.
14 my $Why = "Just testing the skip interface.";
15
16 SKIP: {
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
28 SKIP: {
29     skip "We're not skipping", 2 if 0;
30
31     pass("Inside skip block");
32     pass("Another inside");
33 }
34
35
36 SKIP: {
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
46 SKIP: {
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
72 SKIP: {
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 {
88     my $warning = '';
89     local $SIG{__WARN__} = sub { $warning .= join "", @_ };
90
91     SKIP: {
92         skip 1, "This is backwards" if 1;
93
94         pass "This does not run";
95     }
96
97     like $warning, qr/^skip\(\) was passed a non-numeric number of tests/;
98 }