Debian Codegraph @

t/integration/failure_cases.t

raw
1 use Test2::V0;
2 # HARNESS-DURATION-LONG
3
4 use App::Yath::Tester qw/yath/;
5 use File::Spec;
6
7 my $dir = __FILE__;
8 $dir =~ s{\.t$}{}g;
9 $dir =~ s{^\./}{};
10
11 # Timeouts short enough that the failing run does not sit out the default
12 # ones. These apply to the failing run only: the passing run has nothing to
13 # wait for, and a slow or loaded machine can easily take longer than 2 seconds
14 # to get a test started, which would kill a test that was going to pass.
15 my %CUSTOM = (
16 "timeout.tx" => ['--et', 2],
17 "post_exit_timeout.tx" => ['--pet', 2],
18 "noplan.tx" => ['--pet', 2],
19 );
20
21 opendir(my $DH, $dir) or die "Could not open directory $dir: $!";
22 my @files = sort grep { -f File::Spec->canonpath("$dir/$_") } readdir($DH);
23 closedir($DH);
24
25 my @plain = grep { !$CUSTOM{$_} } @files;
26
27 sub path_for { File::Spec->canonpath("$dir/$_[0]") }
28
29 # One run for every fixture that needs no special handling, rather than one
30 # run per fixture: starting yath costs far more than the assertions do. Each
31 # file is checked by name in the output, which is more than the per-file runs
32 # asserted -- they only looked at the exit code, which any one failure sets.
33 yath(
34 command => 'test',
35 args => ['-j4', map { path_for($_) } @plain],
36 env => {FAILURE_DO_PASS => 0},
37 exit => T(),
38 test => sub {
39 my $out = shift;
40 like($out->{output}, qr{FAILED.*\Q$_\E}, "$_ failed") for @plain;
41 },
42 );
43
44 # These three have to wait out a timeout, and the option that shortens it is
45 # global, so they keep a run each rather than imposing one file's timeout on
46 # another's failure mode.
47 for my $file (sort keys %CUSTOM) {
48 yath(
49 command => 'test',
50 args => [@{$CUSTOM{$file}}, path_for($file)],
51 env => {FAILURE_DO_PASS => 0},
52 exit => T(),
53 test => sub {
54 my $out = shift;
55 like($out->{output}, qr{FAILED.*\Q$file\E}, "$file failed");
56 },
57 );
58 }
59
60 # Every fixture passes when told to, including the three above: with nothing
61 # to wait for they need no custom timeouts.
62 yath(
63 command => 'test',
64 args => ['-j4', map { path_for($_) } @files],
65 env => {FAILURE_DO_PASS => 1},
66 exit => F(),
67 );
68
69 done_testing;