File: teardown-when-test-dies.t

package info (click to toggle)
libtest-class-perl 0.52-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, forky, sid, trixie
  • size: 540 kB
  • sloc: perl: 1,706; makefile: 2
file content (28 lines) | stat: -rw-r--r-- 729 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
use strict;
use warnings;
$ENV{TEST_VERBOSE}=0;

my $line;
{
    package TeardownWhenTestDies;
    use base qw(Test::Class);
    use Test::More;

    sub setup_that_runs : Test( setup => 1 ) { ok(1, "setup works"); }

    sub my_test_method : Tests {
        BEGIN { $line = __LINE__ } die "oops!";
    }

    sub teardown_that_runs : Test( teardown => 1 ) {
        ok(1, 'teardown is run');
    }
}

use Test::Builder::Tester tests => 1;

test_out("ok 1 - setup works\nnot ok 2 - my_test_method died (oops! at ${\ __FILE__ } line $line.)\nok 3 - teardown is run");
test_fail( +2 );
test_err( "#   (in TeardownWhenTestDies->my_test_method)" );
Test::Class->runtests;
test_test("exception in method, but teardown is still run");