File Coverage

File:t/more.coverage.t
Coverage:98.4%

linestmtbrancondsubtimecode
1#!/usr/bin/env perl
2
3
1
1
1
1329
1
13
use strict;
4
1
1
1
2
0
28
use warnings FATAL => 'all';
5
1
413
require 5.010;
6
1
1
1
1
0
47
use feature 'say';
7
1
1
1
206
28901
3
use Test::More;
8
1
1
1
173
847
1
use Test::Exception;
9
1
1
1
319
4882
20
use File::Temp 'tempfile';
10
1
1
1
98
1
20061
use SimpleFlow qw(task say2);
11
12# Portability setup consistent with 01.t
13
1
2
my $PERL = qq{"$^X"};
14
5
5
7
8
sub perl_cmd { my $code = shift; return qq{$PERL -e "$code"} }
15
16# --- 1. say2: Invalid Filehandle --------------------------------------------
17dies_ok {
18
1
13
  say2('This should die', 'not_a_valid_filehandle');
19
1
2
} 'say2 dies when provided an invalid filehandle';
20
21# --- 2. task(): Argument Parsing Branches -----------------------------------
22# Test the elsif (@_ % 2 == 0) branch
23
1
406
my $t = task(cmd => perl_cmd('exit 0'), 'dry.run' => 1);
24
1
2
is($t->{'dry.run'}, 1, 'task() successfully parses a flat key/value list');
25
26# Test the else (odd-length list) branch
27dies_ok {
28
1
10
  task('cmd', perl_cmd('exit 0'), 'odd_arg_without_value');
29
1
93
} 'task() dies when given an odd-length flat list';
30
31# --- 3. task(): Invalid Reference Types for Files ---------------------------
32# input.files else { die ... } branch
33dies_ok {
34
1
8
  task({ cmd => perl_cmd('exit 0'), 'input.files' => { bad => 'hash' } });
35
1
334
} 'task() dies when input.files is an unsupported reference type (HASH)';
36
37# output.files else { die ... } branch
38dies_ok {
39
1
13
  task({ cmd => perl_cmd('exit 0'), 'output.files' => { bad => 'hash' } });
40
1
413
} 'task() dies when output.files is an unsupported reference type (HASH)';
41
42# --- 4. task(): Missing Scalar Input File -----------------------------------
43# (01.t covered the ARRAY branch for missing input files, this hits the scalar branch)
44dies_ok {
45
1
10
  task({ cmd => perl_cmd('exit 0'), 'input.files' => 'definitely_does_not_exist.txt' });
46
1
381
} 'task() dies when a scalar input.files does not exist';
47
48# --- 5. task(): 0-Byte Output File Warning ----------------------------------
49
1
359
my (undef, $empty_out) = tempfile(UNLINK => 1, SUFFIX => '.empty');
50
1
177
my $warn_caught = 0;
51
52# Temporarily trap warnings to verify the exact text is emitted
53local $SIG{__WARN__} = sub {
54
1
1
  my $msg = shift;
55
1
6
  $warn_caught = 1 if $msg =~ /the above output files have 0 size/i;
56
1
3
};
57
58
1
1
$t = task(# Touch a file without writing data to it
59  cmd            => qq{$PERL -e "open(my \\\$fh, '>', '$empty_out'); close \\\$fh;"},
60  'output.files' => [$empty_out],
61  overwrite      => 1,
62  die            => 0
63);
64
65
1
4
ok($warn_caught, 'task() triggers a warning when an output file is exactly 0 bytes');
66
67
1
173
done_testing();