1#!perl -w
2# HARNESS-NO-PRELOAD
3
4BEGIN {
5    if( $ENV{PERL_CORE} ) {
6        chdir 't';
7        @INC = '../lib';
8    }
9}
10
11use Test::More tests => 17;
12
13# If we skip with the same name, Test::Harness will report it back and
14# we won't get lots of false bug reports.
15my $Why = "Just testing the skip interface.";
16
17SKIP: {
18    skip $Why, 2 
19      unless Pigs->can('fly');
20
21    my $pig = Pigs->new;
22    $pig->takeoff;
23
24    ok( $pig->altitude > 0,         'Pig is airborne' );
25    ok( $pig->airspeed > 0,         '  and moving'    );
26}
27
28
29SKIP: {
30    skip "We're not skipping", 2 if 0;
31
32    pass("Inside skip block");
33    pass("Another inside");
34}
35
36
37SKIP: {
38    skip "Again, not skipping", 2 if 0;
39
40    my($pack, $file, $line) = caller;
41    is( $pack || '', '',      'calling package not interfered with' );
42    is( $file || '', '',      '  or file' );
43    is( $line || '', '',      '  or line' );
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{
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}
99