lib/Proc/ShellSpawn.pm

filter: Statementstmt 93.3% 1033 / 1107 Branchbran 78.1% 577 / 738 Conditioncond 66.7% 395 / 592 MC/DCmcdc 44.2% 143 / 323 Subroutinesub 92.7% 192 / 207 Podpod 0.0% 0 / 79 totaltotal 76.8% 2340 / 3046 CC 608 SCAR 33.0
CC
608
Cov
82%
sh_main
380.0
__ANON__
63.5
spawn
59.9
CRAP 27.1
« lib/Proc/ShellSubset/Large.pm ↑ Summary lib/Proc/ShellSubset.pm »
1 package Proc::ShellSpawn;
2 # Runs Proc::ShellSubset parse trees with posix_spawn(3), in the simplest scenario:
3 # this module is the only code that starts child processes, and it owns
4 # SIGCHLD while it runs. No fork in Perl: compound commands, pipelines of
5 # them, subshells, $( ), loops and background chains run in this process as
6 # continuations driven by one event loop. This is the shell layer only: the
7 # loop and the starting of children are Proc::Spawner's, the ends and the
8 # process nodes (with the continuation each runs when it ends) Proc::Spawner::Graph's.
9 # Aim: what dash and bash do alike (the parsers reject what they do differently); where the two differ only at
10 # run time, as dash does (rule A5, doc/large-subset/large-subset-spec.md). Every program started is a child of this
11 # Perl process, never a grandchild.
12 #
13 # Process-wide state flipped for a while, so bullet-proof only in non-threaded execution: Perl's umask,
14 # set to the shell's while a redirection's file is opened (open_end); SIGINT, SIGQUIT and SIGPIPE,
15 # ignored while run() runs (ignoring_int); traps, set in %SIG while run() runs and put back after it
16 # (Proc::ShellSpawn::Large, b_trap); SIGCHLD between run() calls while background jobs remain (idle, K3);
17 # and Proc::Spawner's own (umask in start, SIGCHLD in wait_until).
18 483 ▶use strict; use warnings; use feature 'current_sub';
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
19 483 ▶use POSIX ();
Subroutine BEGIN: called CC=1 SCAR=0.0
20 483 ▶use File::Glob ();
Subroutine BEGIN: called CC=1 SCAR=0.0
21 483 ▶use Cwd ();
Subroutine BEGIN: called CC=1 SCAR=0.0
22 483 ▶use Proc::Spawner;
Subroutine BEGIN: called CC=1 SCAR=0.0
23 483 ▶use Proc::Spawner::Graph;
Subroutine BEGIN: called CC=1 SCAR=0.0
24 483 ▶use Scalar::Util qw(weaken);
Subroutine BEGIN: called CC=1 SCAR=0.0
25  
26 481 our $VERSION = '0.11';
27 481 our $TRACE; *TRACE = \$Proc::Spawner::TRACE; # undef, or a code ref given one line per fd or process operation
28 481 our %PARSE = map +($_ => 1), qw(assign param_ops if while for case read empty); # options for Proc::ShellSubset and Proc::ShellSubset::Large
29 # (empty, post4-0.04: a string with no command, or only comments, runs as nothing, status 0, as in both shells; also eval '')
30 # The parser for run(STRING): run(STRING, parser => CODE), CODE->(TEXT) returning a tree or an error hash.
31 # Default (EXPERIMENTAL, awaiting approval): the largest of Proc::ShellSubset::Large, Proc::ShellSubset, Proc::ShellSubset::Small that the
32 # caller has loaded; if none is, Proc::ShellSubset is loaded. The executor itself loads no parser otherwise.
33 482 ▶sub default_parser {
Subroutine default_parser: called CC=4 SCAR=19.7
Pod undocumented
34 515 ▶ defined &Proc::ShellSubset::Large::parse ? sub { Proc::ShellSubset::Large::parse($_[0], %PARSE, @_[1 .. $#_]) }
Subroutine __ANON__: called CC=1 SCAR=0.0
35 3 ▶ : defined &Proc::ShellSubset::parse ? sub { Proc::ShellSubset::parse($_[0], %PARSE) }
Subroutine __ANON__: not called CC=1 SCAR=0.0
36 : defined &Proc::ShellSubset::Small::parse ? \&Proc::ShellSubset::Small::parse
37 0 ▶ : do { require Proc::ShellSubset; sub { Proc::ShellSubset::parse($_[0], %PARSE) } } }
Subroutine __ANON__: called CC=1 SCAR=2.9
Branch: 3 branches
BranchTrueFalseTotal
defined &Proc::ShellSubset::Large::parse ? : 482 0 482
defined &Proc::ShellSubset::parse ? : 0 0 0
defined &Proc::ShellSubset::Small::parse ? : 0 0 0
38 481 our $NAME = 'sh'; # prefix of error messages, as sh's "$0"
39 # EXPERIMENTAL (item N9): with TRACE=dot, one Graphviz picture per event (a start, an exit, an end
40 # closed) as trace-001.dot, ... in the directory TRACE_DIR (default: the current one).
41 481 ▶our $DOT = ($ENV{TRACE} // '') eq 'dot' ? $ENV{TRACE_DIR} // '.' : undef;
Branch: 1 branch
BranchTrueFalseTotal
($ENV{'TRACE'} // '') eq 'dot' ? : 0 481 481
Condition25%1/4
$ENV{"TRACE"} // ""
l!l
0481
$ENV{"TRACE_DIR"} // "."
l!l
00
MC/DC0%0/1
$ENV{"TRACE"} // ""
$ENV{"TRACE"}
MC/DC0%0/1
$ENV{"TRACE_DIR"} // "."
$ENV{"TRACE_DIR"}
Truth table50%1/2
A
A= $ENV{"TRACE"}
Aresult
11
00
Truth table0%0/2
A
A= $ENV{"TRACE_DIR"}
Aresult
11
00
42  
43 656 ▶sub tr_ { $TRACE->(join '', @_) if $TRACE }
Subroutine tr_: called CC=2 SCAR=7.6
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
if $Proc::ShellSpawn::TRACE 0 650 650
44 481 our $G = Proc::Spawner::Graph->new(dot => $DOT); # our children and our own reads and writes, now
45  
46 # ------------------------------------------------------------------ extension points (EXPERIMENTAL, awaiting approval)
47 # Handlers are named by fully qualified sub names, resolved (and their module loaded) at first use:
48 # a command node { ext => NAME, ... }, or one with a key of %KIND: NAME->(CONTEXT, NODE, TAIL, K)
49 # a command name in %CMD (or the shell's own table, for functions): NAME->(CONTEXT, ARGV, ENV, K, DATA)
50 # a Part [ext => NAME, ...] of a Word: NAME->(CONTEXT, PART, K) with K->(TEXT)
51 # Each calls K exactly once (or ends the shell with leave), maybe later, and never waits (D2).
52 481 our %KIND = map +($_ => "Proc::ShellSpawn::Large::x_$_"), qw(func export readonly local exec);
53 481 our %CMD = ((map +($_ => ['Proc::ShellSpawn::builtin']), ':', qw(exit break continue read)),
54 (map +($_ => ["Proc::ShellSpawn::Large::b_$_"]), qw(return shift set eval trap wait umask command getopts unset kill pwd)),
55 '.' => ['Proc::ShellSpawn::Large::b_dot'], (map +($_ => ['Proc::ShellSpawn::Large::b_test']), '[', 'test'));
56 481 our $ONBUILTIN; # undef, or a code ref called (HANDLER, [ARGV], {SETTINGS}) for each command where no program runs: before a
57 # builtin or function runs (cd: x_cd; export, readonly, local: x_NAME, after), a command not found ('not found',
58 # 'denied'), settings alone (x_set, ARGV empty, after)
59 481 our %A4; # builtins left to sh: A4 (status 248) when one is named at run time
60 # B2 of "Shell Corpus Gaps": the tables of command names, searched in order; a module adds its own with
61 # unshift @Proc::ShellSpawn::CMDS, \%MINE (Proc::ShellSpawn::Builtins does). %A4 stays last.
62 481 our @CMDS = (\%CMD, \%A4);
63 1251 ▶sub cmd_of { my $n = shift; for (@CMDS) { return $_->{$n} if exists $_->{$n} } undef }
Subroutine cmd_of: called CC=3 SCAR=11.0
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
if exists $_->{$n} 404 2876 3280
64 480 ▶sub a4 { $A4{$_} //= ['Proc::ShellSpawn::Large::b_unsupported'] for keys %Proc::ShellSubset::BI }
Subroutine a4: called CC=3 SCAR=11.0
Pod undocumented
Condition100%2/2
$Proc::ShellSpawn::A4{$_} //= ["Proc::ShellSpawn::Large::b_unsupported"]
l!l
5024050
MC/DC100%1/1
$Proc::ShellSpawn::A4{$_} //= ["Proc::ShellSpawn::Large::b_unsupported"]
$Proc::ShellSpawn::A4{$_}
Truth table100%2/2
A
A= $Proc::ShellSpawn::A4{$_}
Aresult
11
00
65 481 our $SIGNALLED; # after run(): the signal of 'kill ... $$' that ended the string, if any
66 481 our %TRAPSAVE; # signals the trap builtin changed during run(), with their old settings
67 481 our %SPECIAL = map +($_ => 1), qw(: break continue . eval exec exit export readonly return set shift times trap unset);
68 483 ▶BEGIN { *handler = \&Proc::Spawner::Graph::handler }
Subroutine BEGIN: called CC=1 SCAR=0.0
69 26 ▶sub fail { # stop this shell with $st, after the message $text if given
Subroutine fail: called CC=2 SCAR=7.0
Pod undocumented
70 26 ▶ my ($c, $st, $text) = @_; defined $text ? msg($c, $text, sub { leave($c, $st) }) : defer(\&leave, $c, $st); return }
Subroutine __ANON__: called CC=1 SCAR=0.0
Branch: 1 branch
BranchTrueFalseTotal
defined $text ? : 26 0 26
71  
72 # ------------------------------------------------------------------ ends
73 # The ends (Proc::Spawner::Graph) are what a context maps its fds to; each context holds the ends of
74 # its map, and the last release closes one.
75 1428 ▶sub own_fd { $G->parent_end(shift) }
Subroutine own_fd: called CC=1 SCAR=0.0
Pod undocumented
76 1434 ▶sub is_open { my $d = POSIX::dup($_[0]) // return 0; POSIX::close($d); 1 } # without touching its flags
Subroutine is_open: called CC=2 SCAR=7.1
Pod undocumented
Condition50%1/2
POSIX::dup($_[0]) // (return 0)
l!l
14400
MC/DC0%0/1
POSIX::dup($_[0]) // (return 0)
POSIX::dup($_[0])
Truth table50%1/2
A
A= POSIX::dup($_[0])
Aresult
11
00
77 3 ▶sub visible { # open and not close-on-exec: an fd sh would have inherited (not ours, nor the caller's handles)
Subroutine visible: called CC=1 SCAR=0.0
Pod undocumented
78 7 Proc::Spawner::__fd_cloexec(shift) == 0 } # fcntl F_GETFD (until 0.05: /proc/self/fdinfo, Linux only; RT #182479)
79 164 ▶sub new_pipe { $G->new_pipe }
Subroutine new_pipe: called CC=1 SCAR=0.0
Pod undocumented
80  
81 # ------------------------------------------------------------------ paths
82 # POSIX, and Windows (post-0.10): there a path is absolute with a drive (C:/x, C:\x) or as a UNC name (//server/share);
83 # /x is the current drive's root; \ separates as / does; PATH is split at $Config{path_sep} (;, Proc::Spawner::path_split)
84 # and a command is looked up with the extensions of PATHEXT first; /dev/null is NUL. The shell's own directory keeps
85 # Perl's form (C:/x/y).
86 481 our $WIN = $Proc::Spawner::WIN;
87 481 ▶my $SEP = $WIN ? qr{[/\\]+} : qr{/+};
Branch: 1 branch
BranchTrueFalseTotal
$Proc::ShellSpawn::WIN ? : 0 481 481
88 532 ▶sub is_abs { $WIN ? $_[0] =~ m{^(?:[A-Za-z]:)?[/\\]} : $_[0] =~ m{^/} }
Subroutine is_abs: called CC=2 SCAR=7.6
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
$Proc::ShellSpawn::WIN ? : 0 515 515
89 575 ▶sub has_dir { $WIN ? $_[0] =~ m{[/\\]} : $_[0] =~ m{/} } # a command name with a directory: no PATH lookup
Subroutine has_dir: called CC=2 SCAR=7.6
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
$Proc::ShellSpawn::WIN ? : 0 579 579
90 2320 ▶sub path_in { # PATH from the shell's directory
Subroutine path_in: called CC=6 SCAR=21.2
Pod undocumented
91 2318 my ($c, $p) = @_;
92 2320 ▶ return $p if $WIN ? $p =~ m{^[A-Za-z]:[/\\]|^[/\\]{2}} : $p =~ m{^/};
Branch: 2 branches
BranchTrueFalseTotal
if $Proc::ShellSpawn::WIN ? $p =~ m(^[A-Za-z]:[/\\]|^[/\\]{2}) : $p =~ m[^/] 2289 48 2337
$Proc::ShellSpawn::WIN ? : 0 2337 2337
93 48 ▶ return ($c->{sh}{cwd} =~ m{^([A-Za-z]:|[/\\]{2}[^/\\]+[/\\][^/\\]+)} ? $1 : '') . $p if $WIN && $p =~ m{^[/\\]}; # (the drive, or the UNC share)
Branch: 2 branches
BranchTrueFalseTotal
if $Proc::ShellSpawn::WIN and $p =~ m(^[/\\]) 0 48 48
$c->{'sh'}{'cwd'} =~ m(^([A-Za-z]:|[/\\]{2}[^/\\]+[/\\][^/\\]+)) ? : 0 0 0
Condition33%1/3
$Proc::ShellSpawn::WIN and $p =~ m(^[/\\])
!ll&&!rl&&r
4800
MC/DC0%0/2
$Proc::ShellSpawn::WIN and $p =~ m(^[/\\])
$Proc::ShellSpawn::WIN $p =~ m(^[/\\])
Truth table33%1/3
A and B
A= $Proc::ShellSpawn::WINB= $p =~ m(^[/\\])
ABresult
0X0
100
111
94 48 "$c->{sh}{cwd}/$p" }
95 264 ▶sub path_list { Proc::Spawner::path_split(@_) } # a PATH value's directories (an empty one: the current directory, POSIX)
Subroutine path_list: called CC=1 SCAR=0.0
Pod undocumented
96 3 ▶sub win_home { # ~user on Windows (post-0.10, the user's follow-up (b) to WS1): one's own name is %USERPROFILE%; another
Subroutine win_home: called CC=6 SCAR=32.3
Pod undocumented
97 # is its sibling of that name, if that is a directory (profiles are usually siblings; not always: the registry's
98 # ProfileList has the real ones, a domain profile may be user.DOMAIN); else undef (~user stays as written)
99 0 ▶ my $n = shift; my $up = $ENV{USERPROFILE} // return; return if $n =~ /^\.\.?\z/;
Branch: 1 branch
BranchTrueFalseTotal
if $n =~ /^\.\.?\z/ 0 0 0
Condition0%0/2
$ENV{"USERPROFILE"} // (return)
l!l
00
MC/DC0%0/1
$ENV{"USERPROFILE"} // (return)
$ENV{"USERPROFILE"}
Truth table0%0/2
A
A= $ENV{"USERPROFILE"}
Aresult
11
00
100 3 ▶ return $up if lc $n eq lc($ENV{USERNAME} // '');
Branch: 1 branch
BranchTrueFalseTotal
if lc $n eq lc($ENV{"USERNAME"} // "") 0 0 0
Condition0%0/2
$ENV{"USERNAME"} // ""
l!l
00
MC/DC0%0/1
$ENV{"USERNAME"} // ""
$ENV{"USERNAME"}
Truth table0%0/2
A
A= $ENV{"USERNAME"}
Aresult
11
00
101 3 ▶ my $d = ($up =~ s{[^/\\]+[/\\]*\z}{}r) . $n; -d $d ? $d : undef }
Branch: 1 branch
BranchTrueFalseTotal
-d $d ? : 0 0 0
102 107 ▶sub os_path { my $p = shift; $WIN && $p eq '/dev/null' ? 'NUL' : $p } # a redirection's file name, as the system has it
Subroutine os_path: called CC=3 SCAR=13.1
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
$Proc::ShellSpawn::WIN && $p eq '/dev/null' ? : 0 107 107
Condition33%1/3
$Proc::ShellSpawn::WIN and $p eq "/dev/null"
!ll&&!rl&&r
10700
MC/DC0%0/2
$Proc::ShellSpawn::WIN and $p eq "/dev/null"
$Proc::ShellSpawn::WIN $p eq "/dev/null"
Truth table33%1/3
A and B
A= $Proc::ShellSpawn::WINB= $p eq "/dev/null"
ABresult
0X0
100
111
103  
104 106 ▶sub open_end { # an end on a file, or undef with $!
Subroutine open_end: called CC=5 SCAR=16.1
Pod undocumented
105 107 my ($c, $name, $op) = @_;
106 107 my $path = path_in($c, os_path($name));
107 107 ▶ return $! = POSIX::EEXIST(), undef if $op eq '>' && $c->{sh}{opt}{C} && -f $path; # set -C
Branch: 1 branch
BranchTrueFalseTotal
if $op eq ">" and $c->{"sh"}{"opt"}{"C"} and -f $path 1 106 107
Condition100%6/6
$op eq ">" and $c->{"sh"}{"opt"}{"C"} and -f $path
!ll&&!rl&&r
10511
$op eq ">" and $c->{"sh"}{"opt"}{"C"}
!ll&&!rl&&r
44612
MC/DC100%3/3
$op eq ">" and $c->{"sh"}{"opt"}{"C"} and -f $path
$op eq ">" $c->{"sh"}{"opt"}{"C"} -f $path
Truth table100%4/4
A and B and C
A= $op eq ">"B= $c->{"sh"}{"opt"}{"C"}C= -f $path
ABCresult
0XX0
10X0
1100
1111
108 106 my $um = umask $c->{sh}{umask};
109 106 my $ok = sysopen my $fh, $path, $Proc::Spawner::Graph::OPEN{$op}, 0666; my $err = $!; umask $um;
110 105 ▶ $! = $err, return unless $ok;
Branch: 1 branch
BranchTrueFalseTotal
unless $ok 17 89 106
111 88 $G->file_end($fh, $op, $name) }
112  
113 # ------------------------------------------------------------------ contexts
114 # A context: what the commands run in it get.
115 # map => { CHILD_FD => end, or undef for closed }; fds not listed are ours, inherited as they are
116 # sh => the shell state: vars, exp(orted names), cwd, q ($?), bang ($!), qsub
117 # loops => [ { brk => K, cont => K, scope => [contexts] }, ... ] of the enclosing loops
118 # shell => { exit => K, scope => [contexts] } for exit
119 # held => 1 if this context holds its map's ends; released by release_ctx, once
120 756 ▶sub derive { # a context with its own map, which it holds
Subroutine derive: called CC=7 SCAR=19.5
Pod undocumented
121 758 my ($c, $map, %o) = @_;
122 758 my $d = { %$c, map => $map, held => 1, released => 0, root => !!$o{shell}, late => 0 };
123 758 ▶ if (my $k = $o{shell}) { # a new shell: copies of the state; exit and loops start afresh;
Branch: 1 branch
BranchTrueFalseTotal
if (my $k = $o{"shell"}) 296 462 758
124 296 my $sh = $c->{sh}; # leaving it releases every context made in it
125 296 $d->{sh} = { %$sh, main => $sh->{main} // $sh, vars => { %{$sh->{vars}} }, exp => { %{$sh->{exp}} }, args => [@{$sh->{args}}],
126 294 ▶ opt => { %{$sh->{opt}} }, cmd => { %{$sh->{cmd}} }, ro => { %{$sh->{ro}} }, jobl => [],
Branch: 1 branch
BranchTrueFalseTotal
$o{'jobs'} ? : 229 67 296
127 231 ▶ ljobs => $o{jobs} ? [@{$sh->{ljobs} // []}, @{$sh->{jobl}}] : [], # jobs listed in a pipeline or $( ) (rule E)
Condition100%2/2
$sh->{"ljobs"} // []
l!l
31198
MC/DC100%1/1
$sh->{"ljobs"} // []
$sh->{"ljobs"}
Truth table100%2/2
A
A= $sh->{"ljobs"}
Aresult
11
00
128 pend => [], twait => [], tbusy => 0, # the caught signals belong to the shell whose trap caught them (X19)
129 296 ▶ trap => { map +($_ => ''), grep $sh->{trap}{$_} eq '', keys %{$sh->{trap}} } }; # sh: only ignored traps stay
Condition66%2/3
$sh->{"main"} // $sh
l!l&&r!l&&!r
532430
MC/DC0%0/2
$sh->{"main"} // $sh
$sh->{"main"} $sh
Truth table66%2/3
A // B
A= $sh->{"main"}B= $sh
ABresult
1X1
011
000
130 296 my $scope = [];
131 296 $d->{loops} = []; delete @$d{qw(frame cond)}; $d->{shell} = { scope => $scope, exit => shell_exit($d, $scope, $k) } }
132 758 hold($_) for values %$map;
133 758 ▶ push @{ @{$d->{loops}} ? $d->{loops}[-1]{scope} : $d->{shell}{scope} }, $d;
Branch: 1 branch
BranchTrueFalseTotal
@{$d->{'loops'};} ? : 67 691 758
134 756 $d }
135 58 ▶sub leave { my ($c, $st) = @_; release_all(map $_->{scope}, @{$c->{loops}}); $c->{shell}{exit}->($st) } # exit
Subroutine leave: called CC=1 SCAR=0.0
Pod undocumented
136 772 ▶sub shell_exit { # the end of a shell: its EXIT trap first (once; an exit inside the trap ends it there)
Subroutine shell_exit: called CC=1 SCAR=0.0
Pod undocumented
137 772 my ($c, $scope, $k) = @_; weaken($c); my $state = 0;
138 773 ▶ sub { my $st = shift;
Subroutine __ANON__: called CC=7 SCAR=19.6
139 769 ▶ return if $state == 2;
Branch: 1 branch
BranchTrueFalseTotal
if $state == 2 0 773 773
140 769 ▶ my $a = $state == 0 && $c && delete $c->{sh}{trap}{EXIT};
Condition83%5/6
$state == 0 && $c && delete $c->{'sh'}{'trap'}{'EXIT'}
!ll&&!rl&&r
17648
$state == 0 and $c
!ll&&!rl&&r
10772
MC/DC66%2/3
$state == 0 && $c && delete $c->{'sh'}{'trap'}{'EXIT'}
$state == 0 $c delete $c->{'sh'}{'trap'}{'EXIT'}
Truth table75%3/4
A and B && C
A= $state == 0B= $cC= delete $c->{'sh'}{'trap'}{'EXIT'}
ABCresult
0XX0
10X0
1100
1111
141 769 ▶ if (defined $a && $a ne '' and ref(my $t = $c->{sh}{parse}->($a, nolineno => 1)) eq 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $a and $a ne "" and ref(my $t = $c->{"sh"}{"parse"}->($a, "nolineno", 1)) eq "ARRAY") 8 765 773
Condition83%5/6
defined $a and $a ne "" and ref(my $t = $c->{"sh"}{"parse"}->($a, "nolineno", 1)) eq "ARRAY"
!ll&&!rl&&r
76508
defined $a and $a ne ""
!ll&&!rl&&r
76418
MC/DC66%2/3
defined $a and $a ne "" and ref(my $t = $c->{"sh"}{"parse"}->($a, "nolineno", 1)) eq "ARRAY"
defined $a $a ne "" ref(my $t = $c->{"sh"}{"parse"}->($a, "nolineno", 1)) eq "ARRAY"
Truth table75%3/4
A and B and C
A= defined $aB= $a ne ""C= ref(my $t = $c->{"sh"}{"parse"}->($a, "nolineno", 1)) eq "ARRAY"
ABCresult
0XX0
10X0
1100
1111
142 12 $state = 1; my $tc = { %$c, loops => [], held => 0, cond => undef, frame => undef };
143 12 ▶ return x_list($tc, $t, undef, sub { return if $state == 2; $state = 2; late($c); release_all($scope); $k->($st) }) }
Subroutine __ANON__: called CC=2 SCAR=7.0
Branch: 1 branch
BranchTrueFalseTotal
if $state == 2 0 7 7
144 772 $state = 2; late($c); release_all($scope); $k->($st) } }
145 772 ▶sub late { my $c = shift; release_ctx($c) if $c && $c->{late} } # the release a trap postponed (the trap is gone by now)
Subroutine late: called CC=3 SCAR=11.1
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
if $c and $c->{"late"} 3 769 772
Condition66%2/3
$c and $c->{"late"}
!ll&&!rl&&r
07693
MC/DC50%1/2
$c and $c->{"late"}
$c $c->{"late"}
Truth table66%2/3
A and B
A= $cB= $c->{"late"}
ABresult
0X0
100
111
146 1428 ▶sub release_ctx {
Subroutine release_ctx: called CC=7 SCAR=19.5
Pod undocumented
147 1426 ▶ my $c = shift; return if !$c->{held} or $c->{released};
Branch: 1 branch
BranchTrueFalseTotal
if not $c->{"held"} or $c->{"released"} 665 763 1428
Condition66%2/3
not $c->{"held"} or $c->{"released"}
l!l&&r!l&&!r
0665763
MC/DC50%1/2
not $c->{"held"} or $c->{"released"}
not $c->{"held"} $c->{"released"}
Truth table66%2/3
not(A) or B
A= not $c->{"held"}B= $c->{"released"}
ABresult
1X1
011
000
148 763 ▶ return $c->{late} = 1 if $c->{root} && ($c->{sh}{trap}{EXIT} // '') ne ''; # its EXIT trap still needs them (L5)
Branch: 1 branch
BranchTrueFalseTotal
if $c->{"root"} and ($c->{"sh"}{"trap"}{"EXIT"} // "") ne "" 3 760 763
Condition100%5/5
$c->{"root"} and ($c->{"sh"}{"trap"}{"EXIT"} // "") ne ""
!ll&&!rl&&r
4642963
$c->{"sh"}{"trap"}{"EXIT"} // ""
l!l
3296
MC/DC100%2/2
$c->{"root"} and ($c->{"sh"}{"trap"}{"EXIT"} // "") ne ""
$c->{"root"} $c->{"sh"}{"trap"}{"EXIT"}
Truth table100%3/3
A and B
A= $c->{"root"}B= $c->{"sh"}{"trap"}{"EXIT"}
ABresult
0X0
100
111
149 762 $c->{released} = 1; release($_) for values %{$c->{map}} }
150 977 ▶sub release_all { for my $s (@_) { release_ctx($_) for @$s; @$s = () } } # also breaks the cycles through the scopes
Subroutine release_all: called CC=3 SCAR=11.0
Pod undocumented
151  
152 # ------------------------------------------------------------------ the loop and the graph
153 # Proc::Spawner runs the loop; every continuation runs from its queue, one at a time, and never waits.
154 # Our children and our own reads and writes are nodes of the graph $G (Proc::Spawner::Graph); a
155 # child's node carries its continuation as on_exit ['Proc::ShellSpawn::resume', K].
156 483 ▶BEGIN { *defer = \&Proc::Spawner::defer; *hold = \&Proc::Spawner::Graph::hold; *release = \&Proc::Spawner::Graph::release }
Subroutine BEGIN: called CC=1 SCAR=0.0
157 483 ▶sub loop_until { Proc::Spawner::wait_until(@_) }
Subroutine loop_until: called CC=1 SCAR=0.0
Pod undocumented
158 1807 ▶sub on_read { my ($e, $n, $cb) = @_; $G->perl_read($e, $n, sub { $cb->($_[1]) }) } # one read of end $e: $cb->(BYTES), or undef at end of file
Subroutine __ANON__: called CC=1 SCAR=0.0
Subroutine on_read: called CC=1 SCAR=0.0
Pod undocumented
159 768 ▶sub on_write { my ($e, $bytes, $cb) = @_; $G->perl_write($e, $bytes, $cb) } # Perl writes BYTES to end $e without blocking
Subroutine on_write: called CC=1 SCAR=0.0
Pod undocumented
160  
161 272 ▶sub status_of { # a wait status as sh's $?
Subroutine status_of: called CC=2 SCAR=6.9
Pod undocumented
162 272 my $w = shift;
163 266 ▶ $w & 127 ? 128 + ($w & 127) : $w >> 8 } # (by hand: Windows' POSIX has no WIFSIGNALED; Perl's $? is the same there)
Branch: 1 branch
BranchTrueFalseTotal
$w & 127 ? : 6 262 268
164  
165 # Background jobs left running when run() returns go on between calls too (idle, below); at exit we finish them.
166 481 my %JOBS;
167 # As Perl's system: SIGINT and SIGQUIT are ignored here while commands run (a foreground child gets
168 # them back by sigdefault; a background child keeps them ignored, as POSIX asks of an asynchronous list).
169 492 ▶sub ignoring_int { local @SIG{qw(INT QUIT PIPE)} = ('IGNORE') x 3; $_[0]->() } # PIPE: a here-document's reader may go away
Subroutine ignoring_int: called CC=1 SCAR=0.0
Pod undocumented
170 10 ▶sub wait_all { idle(0); ignoring_int(sub { loop_until(sub { !%JOBS }) }) if %JOBS }
Subroutine __ANON__: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=1 SCAR=0.0
Subroutine wait_all: called CC=2 SCAR=6.9
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
if %JOBS 9 474 483
171 482 ▶END { local $?; wait_all() }
Subroutine END: called CC=1 SCAR=0.0
172 # Between run() calls (K3, the user's choice B, post-0.04): while background jobs remain, a deferred SIGCHLD
173 # handler moves them on when a child ends, whatever Perl is doing (a chain's next command starts at once).
174 # Its cost, documented: the program's own sleep and select return early when a child ends, and the
175 # program's own $SIG{CHLD} is called by ours (a CODE handler; set afterwards, it replaces ours).
176 481 our $RUNNING = 0; # inside run(): the loop there does it
177 481 my ($IDLE_ON, $IDLE_OLD);
178 479 ▶sub idle_pass {
Subroutine idle_pass: called CC=4 SCAR=13.9
Pod undocumented
179 479 ▶ return if $RUNNING || !%JOBS;
Branch: 1 branch
BranchTrueFalseTotal
if $Proc::ShellSpawn::RUNNING or not %JOBS 465 13 478
Condition66%2/3
$Proc::ShellSpawn::RUNNING or not %JOBS
l!l&&r!l&&!r
046513
MC/DC50%1/2
$Proc::ShellSpawn::RUNNING or not %JOBS
$Proc::ShellSpawn::RUNNING not %JOBS
Truth table66%2/3
A or not(B)
A= $Proc::ShellSpawn::RUNNINGB= not %JOBS
ABresult
1X1
011
000
180 14 ignoring_int(\&Proc::Spawner::poll);
181 14 ▶ idle(0) unless %JOBS }
Branch: 1 branch
BranchTrueFalseTotal
unless %JOBS 2 11 13
182 958 ▶sub idle { # 1: install the handler (if jobs remain), 0: put the previous one back
Subroutine idle: called CC=8 SCAR=22.2
Pod undocumented
183 958 my $on = shift;
184 958 ▶ return if $WIN; # (no SIGCHLD there: background jobs move on at the next run, wait or poll)
Branch: 1 branch
BranchTrueFalseTotal
if $Proc::ShellSpawn::WIN 0 961 961
185 958 ▶ if ($on && %JOBS && !$IDLE_ON) {
Branch: 2 branches
BranchTrueFalseTotal
if ($on and %JOBS and not $IDLE_ON) { } 11 950 961
elsif (not $on and $IDLE_ON) { } 11 1404 1415
Condition83%5/6
$on and %JOBS and not $IDLE_ON
!ll&&!rl&&r
950011
$on and %JOBS
!ll&&!rl&&r
48546511
MC/DC66%2/3
$on and %JOBS and not $IDLE_ON
$on %JOBS not $IDLE_ON
Truth table75%3/4
A and B and not(C)
A= $onB= %JOBSC= not $IDLE_ON
ABCresult
0XX0
10X0
1100
1111
186 11 $IDLE_OLD = POSIX::SigAction->new;
187 0 ▶ my $a = POSIX::SigAction->new(sub { idle_pass(); my $h = $IDLE_OLD && $IDLE_OLD->{HANDLER}; $h->(@_) if ref $h eq 'CODE' },
Subroutine __ANON__: not called CC=3 SCAR=19.2
Branch: 1 branch
BranchTrueFalseTotal
if ref $h eq "CODE" 0 2 2
Condition33%1/3
$IDLE_OLD && $IDLE_OLD->{'HANDLER'}
!ll&&!rl&&r
002
MC/DC0%0/2
$IDLE_OLD && $IDLE_OLD->{'HANDLER'}
$IDLE_OLD $IDLE_OLD->{'HANDLER'}
Truth table33%1/3
A && B
A= $IDLE_OLDB= $IDLE_OLD->{'HANDLER'}
ABresult
0X0
100
111
188 11 POSIX::SigSet->new, POSIX::SA_RESTART());
189 11 $a->safe(1); # deferred: runs between Perl operations, never inside the signal (S2)
190 11 ▶ POSIX::sigaction(POSIX::SIGCHLD(), $a, $IDLE_OLD) and $IDLE_ON = 1 }
Branch: 1 branch
BranchTrueFalseTotal
POSIX::sigaction(17, $a, $IDLE_OLD) and $IDLE_ON = 1 11 0 11
191 11 ▶ elsif (!$on && $IDLE_ON) { POSIX::sigaction(POSIX::SIGCHLD(), $IDLE_OLD); $IDLE_ON = 0 } }
Condition100%3/3
not $on and $IDLE_ON
!ll&&!rl&&r
46547411
MC/DC100%2/2
not $on and $IDLE_ON
not $on $IDLE_ON
Truth table100%3/3
not(A) and B
A= not $onB= $IDLE_ON
ABresult
0X0
100
111
192  
193 # ------------------------------------------------------------------ spawning
194 # Signals ignored when we were loaded stay ignored in children, as sh keeps the ones ignored on entry.
195 # SIGFPE as Perl's own exec would pass it: Perl may ignore it for itself at startup, and puts back
196 # the disposition it found then (PERL_FPU_PRE_EXEC, PL_sigfpe_saved; fpe_at_exec() reads it).
197 481 my $FPE = Proc::Spawner::fpe_at_exec();
198 481 ▶my %IGN0 = map +($_ => 1), grep +($SIG{$_} // '') eq 'IGNORE' && ($_ ne 'FPE' || $FPE == 1), keys %SIG;
Condition62%5/8
($SIG{$_} // '') eq 'IGNORE' && ($_ ne 'FPE' || $FPE == 1)
!ll&&!rl&&r
317464810
$SIG{$_} // ""
l!l
48131746
$_ ne "FPE" or $FPE == 1
l!l&&r!l&&!r
00481
MC/DC0%0/3
($SIG{$_} // '') eq 'IGNORE' && ($_ ne 'FPE' || $FPE == 1)
$SIG{$_} $_ ne "FPE" $FPE == 1
Truth table50%2/4
A && B or C
A= $SIG{$_}B= $_ ne "FPE"C= $FPE == 1
ABCresult
0XX0
1000
11X1
1011
199  
200 190 ▶sub put { # Perl writes $t to the context's fd $fd, then $then->(); never waits (L10). Callers go on only
Subroutine put: called CC=3 SCAR=11.3
Pod undocumented
201 # in $then, so nothing started later overtakes the text.
202 190 ▶ my ($c, $fd, $t, $then) = @_; $then //= sub {};
Subroutine __ANON__: not called CC=1 SCAR=0.6
Condition33%1/3
$then //= sub { }
l!l&&r!l&&!r
19000
MC/DC0%0/2
$then //= sub { }
$then sub { }
Truth table33%1/3
A //= B
A= $thenB= sub { }
ABresult
1X1
011
000
203 190 my $e = $c->{map}{$fd};
204 190 ▶ $e ? do { hold($e); on_write($e, $t, sub { release($e); $then->() }) } : defer($then); return }
Subroutine __ANON__: called CC=1 SCAR=0.0
Branch: 1 branch
BranchTrueFalseTotal
$e ? : 190 0 190
205 84 ▶sub msg { my ($c, $text, $then) = @_; put($c, 2, "$NAME: $text\n", $then) } # an error message, to fd 2
Subroutine msg: called CC=1 SCAR=0.0
Pod undocumented
206 566 ▶sub write_fd { # as put, then $k->(ERRNO or undef): EBADF when the fd is closed (and there is something to write)
Subroutine write_fd: called CC=3 SCAR=11.0
Pod undocumented
207 566 my ($c, $fd, $t, $k) = @_; my $e = $c->{map}{$fd};
208 566 ▶ return defer($k, undef) if $t eq ''; return defer($k, POSIX::EBADF()) unless $e;
Branch: 2 branches
BranchTrueFalseTotal
if $t eq "" 0 566 566
unless $e 1 565 566
209 565 ▶ hold($e); on_write($e, $t, sub { my $err = $! + 0; release($e); $k->($err || undef) }); return }
Subroutine __ANON__: called CC=2 SCAR=6.9
Condition100%2/2
$err || undef
l!l
3562
MC/DC100%1/1
$err || undef
$err
Truth table100%2/2
A
A= $err
Aresult
11
00
210  
211 # Programs run inside this process (Proc::ShellSpawn::Programs, after coreutils 9.4), by name (X21). Decision IP1 (the
212 # user, 2026-11-08: "when a well-debugged builtin is already present, use it. (By default; Configurable.)"): echo
213 # printf test [ true false, and since post-0.10 pwd (b_pwd runs it as 'pwd -L', X23), on every platform; PROC_SHELLSPAWN_INPROC changes the default (none: the programs; names:
214 # only these; all), and %INPROC can be changed at run time. A name with a '/' is always a program.
215 481 our @INPROC = qw(echo printf test [ true false pwd);
216 our %INPROC = map +($_ => 1), map $_ eq 'all' ? @INPROC : $_ eq 'none' ? () : $_,
217 481 ▶ split ' ', $ENV{PROC_SHELLSPAWN_INPROC} // 'all';
Branch: 2 branches
BranchTrueFalseTotal
$_ eq 'all' ? : 472 9 481
$_ eq 'none' ? : 9 0 9
Condition100%2/2
$ENV{"PROC_SHELLSPAWN_INPROC"} // "all"
l!l
18463
MC/DC100%1/1
$ENV{"PROC_SHELLSPAWN_INPROC"} // "all"
$ENV{"PROC_SHELLSPAWN_INPROC"}
Truth table100%2/2
A
A= $ENV{"PROC_SHELLSPAWN_INPROC"}
Aresult
11
00
218 # Whose echo the in-process echo is (decision EC1, the user, 2026-11-09): coreutils (the default; it heeds POSIXLY_CORRECT),
219 # dash or bash (their builtins, which do not); $ECHO can be changed at run time. The program echo (not in %INPROC) is not
220 # affected.
221 481 ▶our $ECHO = $ENV{PROC_SHELLSPAWN_ECHO} || 'coreutils';
Condition100%2/2
$ENV{'PROC_SHELLSPAWN_ECHO'} || 'coreutils'
l!l
44239
MC/DC100%1/1
$ENV{'PROC_SHELLSPAWN_ECHO'} || 'coreutils'
$ENV{'PROC_SHELLSPAWN_ECHO'}
Truth table100%2/2
A
A= $ENV{'PROC_SHELLSPAWN_ECHO'}
Aresult
11
00
222 481 ▶die "PROC_SHELLSPAWN_ECHO: '$ECHO' is none of coreutils, dash, bash\n" unless $ECHO =~ /\A(?:coreutils|dash|bash)\z/;
Branch: 1 branch
BranchTrueFalseTotal
unless $Proc::ShellSpawn::ECHO =~ /\A(?:coreutils|dash|bash)\z/ 0 481 481
223  
224 # sh as Perl with this module (post-0.10, SH1, the user's follow-up (c) to WS1: "Windows has no sh"): a command named sh
225 # (no directory) runs as $^X -MPARSER -MProc::ShellSpawn=sh -e0 -- ARGS, PARSER the largest parser loaded here (as
226 # default_parser), with this Perl's @INC; then sh_main below reads ARGS as sh does. PROC_SHELLSPAWN_SH (or $SH at run
227 # time): auto (the default: so when the command's PATH has no sh), perl (always), program (never). The text after -c is
228 # an argument: through the primitive system1 on Windows, Perl's own spawn drops a " from it, and splits it at blanks too if it has one (❰BUG❱ in
229 # Perl, doc/perl-win32-system-bugs.md, 1); not worked around.
230 481 ▶our $SH = $ENV{PROC_SHELLSPAWN_SH} || 'auto';
Condition100%2/2
$ENV{'PROC_SHELLSPAWN_SH'} || 'auto'
l!l
20461
MC/DC100%1/1
$ENV{'PROC_SHELLSPAWN_SH'} || 'auto'
$ENV{'PROC_SHELLSPAWN_SH'}
Truth table100%2/2
A
A= $ENV{'PROC_SHELLSPAWN_SH'}
Aresult
11
00
231 481 ▶die "PROC_SHELLSPAWN_SH: '$SH' is none of auto, perl, program\n" unless $SH =~ /\A(?:auto|perl|program)\z/;
Branch: 1 branch
BranchTrueFalseTotal
unless $Proc::ShellSpawn::SH =~ /\A(?:auto|perl|program)\z/ 0 481 481
232 280 ▶sub sh_argv { # the argv of sh as Perl, or undef: run the program sh
Subroutine sh_argv: called CC=6 SCAR=18.0
Pod undocumented
233 278 my ($c, $argv, $path) = @_;
234 278 ▶ return if $argv->[0] ne 'sh' or $SH eq 'program' or $SH eq 'auto' && defined((find_cmd($c, 'sh', $path))[0]);
Branch: 1 branch
BranchTrueFalseTotal
if $argv->[0] ne "sh" or $Proc::ShellSpawn::SH eq "program" or $Proc::ShellSpawn::SH eq "auto" and defined((find_cmd($c, "sh", $path))[0]) 270 10 280
Condition88%8/9
$argv->[0] ne "sh" or $Proc::ShellSpawn::SH eq "program" or $Proc::ShellSpawn::SH eq "auto" and defined((find_cmd($c, "sh", $path))[0])
l!l&&r!l&&!r
263710
$argv->[0] ne "sh" or $Proc::ShellSpawn::SH eq "program"
l!l&&r!l&&!r
2531017
$Proc::ShellSpawn::SH eq "auto" and defined((find_cmd($c, "sh", $path))[0])
!ll&&!rl&&r
1007
MC/DC75%3/4
$argv->[0] ne "sh" or $Proc::ShellSpawn::SH eq "program" or $Proc::ShellSpawn::SH eq "auto" and defined((find_cmd($c, "sh", $path))[0])
$argv->[0] ne "sh" $Proc::ShellSpawn::SH eq "program" $Proc::ShellSpawn::SH eq "auto" defined((find_cmd($c, "sh", $path))[0])
Truth table80%4/5
A or B or C and D
A= $argv->[0] ne "sh"B= $Proc::ShellSpawn::SH eq "program"C= $Proc::ShellSpawn::SH eq "auto"D= defined((find_cmd($c, "sh", $path))[0])
ABCDresult
1XXX1
01XX1
00111
000X0
00100
235 483 ▶ my ($parser) = grep { no strict 'refs'; defined &{"${_}::parse"} } qw(Proc::ShellSubset::Large Proc::ShellSubset Proc::ShellSubset::Small);
Subroutine BEGIN: called CC=1 SCAR=0.0
236 10 ▶ [$^X, (map "-I$_", grep !ref, @INC), '-M' . ($parser // 'Proc::ShellSubset'), '-MProc::ShellSpawn=sh', '-e0', '--', @$argv[1 .. $#$argv]] }
Condition50%1/2
$parser // "Proc::ShellSubset"
l!l
100
MC/DC0%0/1
$parser // "Proc::ShellSubset"
$parser
Truth table50%1/2
A
A= $parser
Aresult
11
00
237 1130 ▶sub import { # use Proc::ShellSpawn 'sh': run as sh with @ARGV, then exit (SH1); with no list, nothing
Subroutine import: called CC=4 SCAR=23.2
238 1130 ▶ my ($pkg, @w) = @_; return unless @w;
Branch: 1 branch
BranchTrueFalseTotal
unless @w 1132 0 1132
239 0 ▶ die "Proc::ShellSpawn: only 'sh' can be imported\n" unless @w == 1 && $w[0] eq 'sh';
Branch: 1 branch
BranchTrueFalseTotal
unless @w == 1 and $w[0] eq "sh" 0 0 0
Condition0%0/3
@w == 1 and $w[0] eq "sh"
!ll&&!rl&&r
000
MC/DC0%0/2
@w == 1 and $w[0] eq "sh"
@w == 1 $w[0] eq "sh"
Truth table0%0/3
A and B
A= @w == 1B= $w[0] eq "sh"
ABresult
0X0
100
111
240 0 exit sh_main(@ARGV) }
241 0 ▶sub sh_main { # sh -c TEXT [NAME [ARGS]], sh FILE [ARGS], sh [-s] [ARGS] (the text from stdin): the exit status
Subroutine sh_main: not called CC=19 SCAR=59.4
Pod undocumented
242 0 my @a = @_; my ($opt_c, $opt_s, $text, $name, %opt);
243 0 ▶ my $bad = sub { print STDERR "sh: $_[0]\n"; 2 };
Subroutine __ANON__: not called CC=1 SCAR=6.9
244 0 ▶ while (@a && $a[0] =~ /\A-(.+)\z/s) {
Branch: 1 branch
BranchTrueFalseTotal
if (@a and $a[0] =~ /\A-(.+)\z/s) 0 0 0
Condition0%0/3
@a and $a[0] =~ /\A-(.+)\z/s
!ll&&!rl&&r
000
MC/DC0%0/2
@a and $a[0] =~ /\A-(.+)\z/s
@a $a[0] =~ /\A-(.+)\z/s
Truth table0%0/3
A and B
A= @aB= $a[0] =~ /\A-(.+)\z/s
ABresult
0X0
100
111
245 0 ▶ shift @a; last if $1 eq '-';
Branch: 1 branch
BranchTrueFalseTotal
if $1 eq "-" 0 0 0
246 0 for my $l (split //, $1) { # -c, -s; other letters as set takes them (-e, -u, -x, ...)
247 0 ▶ $l eq 'c' ? ($opt_c = 1) : $l eq 's' ? ($opt_s = 1) : $l =~ /\A[a-zA-Z]\z/ && $l ne 'o' && $l ne 'i' ? ($opt{$l} = 1)
Branch: 3 branches
BranchTrueFalseTotal
$l eq 'c' ? : 0 0 0
$l eq 's' ? : 0 0 0
$l =~ /\A[a-zA-Z]\z/ && $l ne 'o' && $l ne 'i' ? : 0 0 0
Condition0%0/6
$l =~ /\A[a-zA-Z]\z/ and $l ne "o" and $l ne "i"
!ll&&!rl&&r
000
$l =~ /\A[a-zA-Z]\z/ and $l ne "o"
!ll&&!rl&&r
000
MC/DC0%0/3
$l =~ /\A[a-zA-Z]\z/ and $l ne "o" and $l ne "i"
$l =~ /\A[a-zA-Z]\z/ $l ne "o" $l ne "i"
Truth table0%0/4
A and B and C
A= $l =~ /\A[a-zA-Z]\z/B= $l ne "o"C= $l ne "i"
ABCresult
0XX0
10X0
1100
1111
248 : return $bad->("-$l: option not supported here (SH1)") } }
249 0 ▶ if ($opt_c) { @a or return $bad->('-c requires an argument'); $text = shift @a; $name = shift @a }
Branch: 3 branches
BranchTrueFalseTotal
if ($opt_c) { } 0 0 0
elsif (not $opt_s and @a) { } 0 0 0
@a or return &$bad("-c requires an argument") 0 0 0
250 ▶ elsif (!$opt_s && @a) {
Condition0%0/3
not $opt_s and @a
!ll&&!rl&&r
000
MC/DC0%0/2
not $opt_s and @a
not $opt_s @a
Truth table0%0/3
not(A) and B
A= not $opt_sB= @a
ABresult
0X0
100
111
251 0 ▶ $name = shift @a; open my $f, '<', $name or return $bad->("0: cannot open $name: $!"); binmode $f; local $/; $text = <$f> }
Branch: 1 branch
BranchTrueFalseTotal
open my $f, "<", $name or return &$bad("0: cannot open ${name}: $!") 0 0 0
252 0 ▶ else { binmode STDIN; local $/; $text = <STDIN> // '' }
Condition0%0/2
readline STDIN // ""
l!l
00
MC/DC0%0/1
readline STDIN // ""
readline STDIN
Truth table0%0/2
A
A= readline STDIN
Aresult
11
00
253 0 ▶ local $NAME = $name // 'sh';
Condition0%0/2
$name // "sh"
l!l
00
MC/DC0%0/1
$name // "sh"
$name
Truth table0%0/2
A
A= $name
Aresult
11
00
254 0 my ($st, $err) = run($text, args => \@a, arg0 => $NAME, opt => \%opt);
255 0 ▶ defined $st or print(STDERR "$NAME: outside the subset: $err->{error} at $err->{pos}\n"), return 255; # (as t/try.pl)
Branch: 1 branch
BranchTrueFalseTotal
defined $st or print(STDERR qq[$Proc::ShellSpawn::NAME: outside the subset: $err->{"error"} at $err->{"pos"}\n]), (return 255) 0 0 0
256 0 ▶ if (my $s = $SIGNALLED) { local $SIG{$s} = 'DEFAULT'; kill $s, $$; sleep 1 } # die by it, as sh would
Branch: 1 branch
BranchTrueFalseTotal
if (my $s = $Proc::ShellSpawn::SIGNALLED) 0 0 0
257 0 $st }
258  
259 # TEMPORARY WORKAROUND (post-0.10, BIN1; the user's follow-up (d) to WS1, "Replace them from %ENV (inventing suitable
260 # fallbacks)", marked temporary by the user, 2026-11-10): where cat, sort, grep and the like come from. The directories
261 # in PROC_SHELLSPAWN_BIN (split as PATH; 'none': none, since Windows has no empty variables) are searched before PATH, on
262 # any platform. Unset, on Windows: the first of Git for Windows' usr\bin (beside git.exe on PATH, or under
263 # %ProgramFiles%, %ProgramW6432%, %LOCALAPPDATA%\Programs), MSYS2's (%SystemDrive%\msys64\usr\bin) and Cygwin's
264 # (%SystemDrive%\cygwin64\bin) that has cat.exe; elsewhere none. Also on Windows, a program of the system's own (under
265 # %SystemRoot%) named sort, find, timeout or expand is never taken for the POSIX one: they differ. @BIN at run time.
266 our @BIN = !defined $ENV{PROC_SHELLSPAWN_BIN} ? ($WIN ? win_posix_bin() : ())
267 481 ▶ : $ENV{PROC_SHELLSPAWN_BIN} eq 'none' ? () : Proc::Spawner::path_split($ENV{PROC_SHELLSPAWN_BIN});
Branch: 3 branches
BranchTrueFalseTotal
!defined($ENV{'PROC_SHELLSPAWN_BIN'}) ? : 481 0 481
$Proc::ShellSpawn::WIN ? : 0 481 481
$ENV{'PROC_SHELLSPAWN_BIN'} eq 'none' ? : 0 0 0
268 0 ▶sub win_posix_bin {
Subroutine win_posix_bin: not called CC=5 SCAR=34.0
Pod undocumented
269 0 ▶ my $sd = $ENV{SystemDrive} // 'C:';
Condition0%0/2
$ENV{"SystemDrive"} // "C:"
l!l
00
MC/DC0%0/1
$ENV{"SystemDrive"} // "C:"
$ENV{"SystemDrive"}
Truth table0%0/2
A
A= $ENV{"SystemDrive"}
Aresult
11
00
270 0 ▶ my $up = sub { $_[0] =~ s{[/\\][^/\\]+\z}{}r }; # the parent directory
Subroutine __ANON__: not called CC=1 SCAR=6.9
271 0 my @git = map { ($up->($_), $up->($up->($_))) } grep -f "$_\\git.exe", Proc::Spawner::path_split($ENV{PATH}); # Git\cmd, Git\mingw64\bin
272 0 ▶ for my $d ((map "$_\\usr\\bin", @git), (map "$_\\Git\\usr\\bin", grep defined, @ENV{qw(ProgramFiles ProgramW6432)}),
Branch: 1 branch
BranchTrueFalseTotal
defined $ENV{'LOCALAPPDATA'} ? : 0 0 0
273 (defined $ENV{LOCALAPPDATA} ? "$ENV{LOCALAPPDATA}\\Programs\\Git\\usr\\bin" : ()), "$sd\\msys64\\usr\\bin", "$sd\\cygwin64\\bin") {
274 0 ▶ return $d if -f "$d\\cat.exe" } () }
Branch: 1 branch
BranchTrueFalseTotal
if -f "$d\\cat.exe" 0 0 0
275 480 my %WINCLASH = map +($_ => 1), qw(sort find timeout expand); # Windows' own programs of these names are others (BIN1)
276 2 ▶sub win_clash { my ($name, $p) = @_; my $r = $ENV{SystemRoot} // return 0;
Subroutine win_clash: called CC=3 SCAR=15.4
Pod undocumented
Condition0%0/2
$ENV{"SystemRoot"} // (return 0)
l!l
00
MC/DC0%0/1
$ENV{"SystemRoot"} // (return 0)
$ENV{"SystemRoot"}
Truth table0%0/2
A
A= $ENV{"SystemRoot"}
Aresult
11
00
277 2 ▶ $WINCLASH{lc $name} && lc(substr($p, 0, length $r) =~ tr{/}{\\}r) eq lc($r =~ tr{/}{\\}r) }
Branch: 1 branch
BranchTrueFalseTotal
$WINCLASH{lc $name} and lc substr($p, 0, length($r)) =~ tr[/][\\]r eq lc $r =~ tr[/][\\]r 0 0 0
278  
279 297 ▶sub find_cmd { # the path to run for $name, or undef and the status (127, 126); Windows: PATHEXT's extensions first
Subroutine find_cmd: called CC=18 SCAR=35.4
Pod undocumented
280 294 my ($c, $name, $path) = @_;
281 294 ▶ my @ext = ($WIN ? (grep length, split /;/, $c->{sh}{vars}{PATHEXT} // '.COM;.EXE;.BAT;.CMD') : (), '');
Branch: 1 branch
BranchTrueFalseTotal
$Proc::ShellSpawn::WIN ? : 0 296 296
Condition0%0/2
$c->{"sh"}{"vars"}{"PATHEXT"} // ".COM;.EXE;.BAT;.CMD"
l!l
00
MC/DC0%0/1
$c->{"sh"}{"vars"}{"PATHEXT"} // ".COM;.EXE;.BAT;.CMD"
$c->{"sh"}{"vars"}{"PATHEXT"}
Truth table0%0/2
A
A= $c->{"sh"}{"vars"}{"PATHEXT"}
Aresult
11
00
282 296 ▶ if (has_dir($name)) { -f path_in($c, "$name$_") and return "$name$_" for @ext; return $name }
Branch: 2 branches
BranchTrueFalseTotal
if (has_dir($name)) 30 266 296
-f path_in($c, "$name$_") and return "$name$_" 28 2 30
283 280 my $denied;
284 280 for my $d (@BIN, path_list($path)) { for my $e (@ext) { # (@BIN: BIN1, a temporary workaround)
285 2138 ▶ my $p = ($d eq '' ? '.' : $d) . ($WIN && $d =~ /\\/ && $d !~ m{/} ? '\\' : '/') . "$name$e"; # (Windows: as PATH writes it)
Branch: 2 branches
BranchTrueFalseTotal
$d eq '' ? : 0 2152 2152
$Proc::ShellSpawn::WIN && $d =~ /\\/ && !($d =~ m[/]) ? : 0 2152 2152
Condition33%2/6
$Proc::ShellSpawn::WIN and $d =~ /\\/ and not $d =~ m[/]
!ll&&!rl&&r
215200
$Proc::ShellSpawn::WIN and $d =~ /\\/
!ll&&!rl&&r
215200
MC/DC0%0/3
$Proc::ShellSpawn::WIN and $d =~ /\\/ and not $d =~ m[/]
$Proc::ShellSpawn::WIN $d =~ /\\/ not $d =~ m[/]
Truth table25%1/4
A and B and not(C)
A= $Proc::ShellSpawn::WINB= $d =~ /\\/C= not $d =~ m[/]
ABCresult
0XX0
10X0
1100
1111
286 2136 ▶ next unless -f path_in($c, $p);
Branch: 1 branch
BranchTrueFalseTotal
unless -f path_in($c, $p) 1898 254 2152
287 252 ▶ next if $WIN && win_clash($name, $p);
Branch: 1 branch
BranchTrueFalseTotal
if $Proc::ShellSpawn::WIN and win_clash($name, $p) 0 254 254
Condition33%1/3
$Proc::ShellSpawn::WIN and win_clash($name, $p)
!ll&&!rl&&r
25400
MC/DC0%0/2
$Proc::ShellSpawn::WIN and win_clash($name, $p)
$Proc::ShellSpawn::WIN win_clash($name, $p)
Truth table33%1/3
A and B
A= $Proc::ShellSpawn::WINB= win_clash($name, $p)
ABresult
0X0
100
111
288 255 ▶ return $p if -x _;
Branch: 1 branch
BranchTrueFalseTotal
if -x _ 254 0 254
289 3 ▶ $denied //= $p } }
Condition0%0/3
$denied //= $p
l!l&&r!l&&!r
000
MC/DC0%0/2
$denied //= $p
$denied $p
Truth table0%0/3
A //= B
A= $deniedB= $p
ABresult
1X1
011
000
290 15 ▶ defined $denied ? (undef, 126, $denied) : (undef, 127) }
Branch: 1 branch
BranchTrueFalseTotal
defined $denied ? : 0 12 12
291  
292 897 ▶sub spawn { # starts @$argv with $map; $k->(STATUS) when it has ended; returns its process node or undef
Subroutine spawn: called CC=34 SCAR=40.9
Pod undocumented
293 900 my ($c, $map, $argv, $env, $k, $search) = @_; # $search: the PATH to look in, if not the command's own (command -p)
294 900 ▶ my %e = (%{$c->{sh}{vars}}{grep $c->{sh}{exp}{$_} && /^[A-Za-z_][A-Za-z_0-9]*\z/, keys %{$c->{sh}{vars}}}, %$env); # as dash: names only
Condition66%2/3
$c->{'sh'}{'exp'}{$_} && /^[A-Za-z_][A-Za-z_0-9]*\z/
!ll&&!rl&&r
3048031491
MC/DC50%1/2
$c->{'sh'}{'exp'}{$_} && /^[A-Za-z_][A-Za-z_0-9]*\z/
$c->{'sh'}{'exp'}{$_} /^[A-Za-z_][A-Za-z_0-9]*\z/
Truth table66%2/3
A && B
A= $c->{'sh'}{'exp'}{$_}B= /^[A-Za-z_][A-Za-z_0-9]*\z/
ABresult
0X0
100
111
295 897 ▶ return inproc($c, $map, $argv, \%e, $k) if $INPROC{$argv->[0]};
Branch: 1 branch
BranchTrueFalseTotal
if $Proc::ShellSpawn::INPROC{$argv->[0]} 620 280 900
296 280 ▶ if (my $a = sh_argv($c, $argv, $search // $e{PATH})) { $argv = $a; undef $search } # sh as Perl (SH1)
Branch: 1 branch
BranchTrueFalseTotal
if (my $a = sh_argv($c, $argv, $search // $e{"PATH"})) 10 270 280
Condition33%1/3
$search // $e{"PATH"}
l!l&&r!l&&!r
02800
MC/DC0%0/2
$search // $e{"PATH"}
$search $e{"PATH"}
Truth table33%1/3
A // B
A= $searchB= $e{"PATH"}
ABresult
1X1
011
000
297 278 ▶ my ($path, $st, $what) = find_cmd($c, $argv->[0], $search // $e{PATH});
Condition33%1/3
$search // $e{"PATH"}
l!l&&r!l&&!r
02800
MC/DC0%0/2
$search // $e{"PATH"}
$search $e{"PATH"}
Truth table33%1/3
A // B
A= $searchB= $e{"PATH"}
ABresult
1X1
011
000
298 278 ▶ $c->{sh}{hash}{$argv->[0]} = $path if defined $path && !defined $search && !has_dir($argv->[0]); # remembered, as dash (hash, type)
Branch: 1 branch
BranchTrueFalseTotal
if defined $path and not defined $search and not has_dir($argv->[0]) 242 38 280
Condition83%5/6
defined $path and not defined $search and not has_dir($argv->[0])
!ll&&!rl&&r
830242
defined $path and not defined $search
!ll&&!rl&&r
80272
MC/DC66%2/3
defined $path and not defined $search and not has_dir($argv->[0])
defined $path not defined $search not has_dir($argv->[0])
Truth table75%3/4
A and not(B) and not(C)
A= defined $pathB= not defined $searchC= not has_dir($argv->[0])
ABCresult
0XX0
10X0
1100
1111
299 280 ▶ if (!defined $path) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $path) 8 272 280
300 8 ▶ $ONBUILTIN->($st == 127 ? 'not found' : 'denied', $argv, {%$env}) if $ONBUILTIN; # (measurement: no program runs)
Branch: 2 branches
BranchTrueFalseTotal
if $Proc::ShellSpawn::ONBUILTIN 0 8 8
$st == 127 ? : 0 0 0
301 8 ▶ return msg($c, $st == 127 ? "$argv->[0]: not found" : "$argv->[0]: Permission denied", sub { $k->($st) }) }
Subroutine __ANON__: called CC=1 SCAR=0.2
Branch: 1 branch
BranchTrueFalseTotal
$st == 127 ? : 8 0 8
302 272 ▶ if ($WIN && -e path_in($c, $path) && (-d _ || !-x _)) { # Windows runs neither: as sh says it (CreateProcess: not found,
Branch: 1 branch
BranchTrueFalseTotal
if ($Proc::ShellSpawn::WIN and -e path_in($c, $path) and -d _ || !-x(_)) 0 272 272
Condition22%2/9
$Proc::ShellSpawn::WIN and -e path_in($c, $path) and -d _ || !-x(_)
!ll&&!rl&&r
27200
$Proc::ShellSpawn::WIN and -e path_in($c, $path)
!ll&&!rl&&r
27200
-d _ or not -x _
l!l&&r!l&&!r
000
MC/DC0%0/4
$Proc::ShellSpawn::WIN and -e path_in($c, $path) and -d _ || !-x(_)
$Proc::ShellSpawn::WIN -e path_in($c, $path) -d _ not -x _
Truth table20%1/5
A and B and C or not(D)
A= $Proc::ShellSpawn::WINB= -e path_in($c, $path)C= -d _D= not -x _
ABCDresult
0XXX0
10XX0
11000
111X1
11011
303 2 ▶ $ONBUILTIN->('denied', $argv, {%$env}) if $ONBUILTIN; # or "Exec format error")
Branch: 1 branch
BranchTrueFalseTotal
if $Proc::ShellSpawn::ONBUILTIN 0 0 0
304 2 ▶ return msg($c, "$argv->[0]: Permission denied", sub { $k->(126) }) }
Subroutine __ANON__: not called CC=1 SCAR=0.0
305 272 my @envp = map "$_=$e{$_}", sort keys %e;
306 272 ▶ my %def = map +($_ => 1), grep !$IGN0{$_} && ($SIG{$_} // '') eq 'IGNORE' && ($c->{sh}{trap}{$_} // 1) ne '', # trap '' SIG: stays ignored
Branch: 1 branch
BranchTrueFalseTotal
$FPE ? : 0 272 272
Condition70%7/10
!$IGN0{$_} && ($SIG{$_} // '') eq 'IGNORE' && ($c->{'sh'}{'trap'}{$_} // 1) ne ''
!ll&&!rl&&r
1713701359
not $IGN0{$_} and ($SIG{$_} // "") eq "IGNORE"
!ll&&!rl&&r
0171371359
$SIG{$_} // ""
l!l
136217134
$c->{"sh"}{"trap"}{$_} // 1
l!l
01359
MC/DC0%0/3
!$IGN0{$_} && ($SIG{$_} // '') eq 'IGNORE' && ($c->{'sh'}{'trap'}{$_} // 1) ne ''
not $IGN0{$_} $SIG{$_} $c->{"sh"}{"trap"}{$_}
Truth table50%2/4
not(A) and B && C
A= not $IGN0{$_}B= $SIG{$_}C= $c->{"sh"}{"trap"}{$_}
ABCresult
0XX0
10X0
1100
1111
307 keys %SIG, $FPE ? () : 'FPE';
308 272 ▶ delete @def{qw(INT QUIT)} if $c->{sh}{job}; # in the background: left ignored
Branch: 1 branch
BranchTrueFalseTotal
if $c->{"sh"}{"job"} 36 236 272
309 my @o = (sigdefault => [sort keys %def], $WIN ? () : (umask => $c->{sh}{umask}), on_exit => ['Proc::ShellSpawn::resume', $k], # (Windows: no umask)
310 270 ▶ $c->{sh}{cwd} ne Cwd::getcwd() ? (chdir => $c->{sh}{cwd}) : ());
Branch: 2 branches
BranchTrueFalseTotal
$Proc::ShellSpawn::WIN ? : 0 272 272
$c->{'sh'}{'cwd'} ne Cwd::getcwd() ? : 15 257 272
311 272 my $node = $G->start($path, $argv, \@envp, $map, @o);
312 270 ▶ if (!$node && !$WIN && $! == POSIX::ENOEXEC()) { # a script without #!: sh runs it with sh
Branch: 1 branch
BranchTrueFalseTotal
if (not $node || $Proc::ShellSpawn::WIN and $! == 8) 0 272 272
Condition66%4/6
not $node || $Proc::ShellSpawn::WIN and $! == 8
!ll&&!rl&&r
26840
$node || $Proc::ShellSpawn::WIN
l!l&&r!l&&!r
26804
MC/DC0%0/3
not $node || $Proc::ShellSpawn::WIN and $! == 8
$node $Proc::ShellSpawn::WIN $! == 8
Truth table50%2/4
not(A || B) and C
A= $nodeB= $Proc::ShellSpawn::WINC= $! == 8
ABCresult
1XX0
01X0
0000
0011
313 0 $node = $G->start('/bin/sh', ['sh', $path, @$argv[1 .. $#$argv]], \@envp, $map, @o) }
314 270 ▶ return $node if $node;
Branch: 1 branch
BranchTrueFalseTotal
if $node 268 4 272
315 4 my $err = "$!"; # an fd of ours that is not open: the first one the child should have got
316 4 ▶ my ($bad) = grep !is_open($_), map $map->{$_} ? $map->{$_}{fd} : (), sort { $a <=> $b } keys %$map;
Branch: 1 branch
BranchTrueFalseTotal
$map->{$_} ? : 12 0 12
317 4 ▶ $st = $! == POSIX::ENOENT() ? 127 : 126;
Branch: 1 branch
BranchTrueFalseTotal
$! == 2 ? : 1 3 4
318 4 ▶ msg($c, defined $bad ? "$bad: Bad file descriptor" : $st == 127 ? "$argv->[0]: not found" : "$argv->[0]: $err", sub { $k->($st) }) }
Subroutine __ANON__: called CC=1 SCAR=0.0
Branch: 2 branches
BranchTrueFalseTotal
defined $bad ? : 0 4 4
$st == 127 ? : 1 3 4
319 619 ▶sub inproc { # a program of %INPROC, run here: its output and messages in the program's order, then $k->(STATUS). A
Subroutine inproc: called CC=7 SCAR=20.0
Pod undocumented
320 # write error on stdout, as coreutils: death by SIGPIPE (EPIPE, unless the shell ignores SIGPIPE for its children), else
321 # no more output, the message "NAME: write error: ..." at the end and status 1. Undef, as spawn for no process started.
322 620 my ($c, $map, $argv, $env, $k) = @_;
323 620 require Proc::ShellSpawn::Programs;
324 620 my $d = { %$c, map => $map }; hold($_) for values %$map; # (the caller releases its holds when spawn returns)
325 620 ▶ $ONBUILTIN->('Proc::ShellSpawn::inproc', $argv, {%$env}) if $ONBUILTIN; # (measurement: no program runs)
Branch: 1 branch
BranchTrueFalseTotal
if $Proc::ShellSpawn::ONBUILTIN 0 620 620
326 620 tr_("in-process: @$argv");
327 620 ▶ my %opt = (cwd => $c->{sh}{cwd}, echo => $ECHO, isatty => sub { my $e = $map->{$_[0]}; $e && POSIX::isatty($e->{fd}) });
Subroutine __ANON__: called CC=2 SCAR=8.1
Branch: 1 branch
BranchTrueFalseTotal
$e and POSIX::isatty($e->{"fd"}) 0 0 0
328 620 ▶ my ($out, $err, $st, $seq) = Proc::ShellSpawn::Programs->can($argv->[0] eq '[' ? 'test' : $argv->[0])->($argv, $env, \%opt);
Branch: 1 branch
BranchTrueFalseTotal
$argv->[0] eq '[' ? : 30 590 620
329 620 ▶ my @seq = grep length $_->[1], @{$seq // [[2, $err], [1, $out]]};
Condition100%2/2
$seq // [[2, $err], [1, $out]]
l!l
28592
MC/DC100%1/1
$seq // [[2, $err], [1, $out]]
$seq
Truth table100%2/2
A
A= $seq
Aresult
11
00
330 620 ▶ my $pipe_dfl = !$IGN0{PIPE} && ($c->{sh}{trap}{PIPE} // 1) ne ''; # (Windows: as POSIX, though it has no SIGPIPE)
Condition40%2/5
!$IGN0{'PIPE'} && ($c->{'sh'}{'trap'}{'PIPE'} // 1) ne ''
!ll&&!rl&&r
00620
$c->{"sh"}{"trap"}{"PIPE"} // 1
l!l
0620
MC/DC0%0/2
!$IGN0{'PIPE'} && ($c->{'sh'}{'trap'}{'PIPE'} // 1) ne ''
!$IGN0{'PIPE'} $c->{"sh"}{"trap"}{"PIPE"}
Truth table33%1/3
not(A) && B
A= !$IGN0{'PIPE'}B= $c->{"sh"}{"trap"}{"PIPE"}
ABresult
0X0
100
111
331 619 my $werr;
332 1180 ▶ sub {
Subroutine __ANON__: called CC=7 SCAR=19.9
333 1181 my $next = __SUB__;
334 1181 my $p = shift @seq;
335 1180 ▶ if (!$p) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($p) 617 565 1182
336 616 ▶ release($_) for values %$map; return $k->($st) unless $werr;
Branch: 1 branch
BranchTrueFalseTotal
unless $werr 616 1 617
337 2 ▶ local $! = $werr; return write_fd($d, 2, "$argv->[0]: write error" . ($werr > 0 ? ": $!" : '') . "\n", sub { $k->(1) }) }
Subroutine __ANON__: called CC=1 SCAR=0.1
Branch: 1 branch
BranchTrueFalseTotal
$werr > 0 ? : 1 0 1
338 565 ▶ return $next->() if $p->[0] == 1 && $werr;
Branch: 1 branch
BranchTrueFalseTotal
if $p->[0] == 1 and $werr 0 565 565
Condition66%2/3
$p->[0] == 1 and $werr
!ll&&!rl&&r
35620
MC/DC0%0/2
$p->[0] == 1 and $werr
$p->[0] == 1 $werr
Truth table66%2/3
A and B
A= $p->[0] == 1B= $werr
ABresult
0X0
100
111
339 566 ▶ write_fd($d, $p->[0], $p->[1], sub {
Subroutine __ANON__: called CC=8 SCAR=21.5
340 564 my $e = shift;
341 564 ▶ if ($e && $p->[0] == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($e and $p->[0] == 1) 4 561 565
Condition66%2/3
$e and $p->[0] == 1
!ll&&!rl&&r
56104
MC/DC50%1/2
$e and $p->[0] == 1
$e $p->[0] == 1
Truth table66%2/3
A and B
A= $eB= $p->[0] == 1
ABresult
0X0
100
111
342 4 ▶ if ($e == POSIX::EPIPE() && $pipe_dfl) { release($_) for values %$map; return $k->(128 + 13) } # (SIGPIPE: 13)
Branch: 1 branch
BranchTrueFalseTotal
if ($e == 32 and $pipe_dfl) 3 1 4
Condition66%2/3
$e == 32 and $pipe_dfl
!ll&&!rl&&r
103
MC/DC50%1/2
$e == 32 and $pipe_dfl
$e == 32 $pipe_dfl
Truth table66%2/3
A and B
A= $e == 32B= $pipe_dfl
ABresult
0X0
100
111
343 # the reason only when it failed in the final flush (close_stream: errno 0 after an earlier failure): the last
344 # piece for stdout, short enough for one write of the buffer (glibc's: st_blksize, 4096 for a pipe)
345 3 ▶ $werr = !grep($_->[0] == 1, @seq) && length $p->[1] <= 4096 ? $e : -1 }
Branch: 1 branch
BranchTrueFalseTotal
!grep(($_->[0] == 1), @seq) && length $p->[1] <= 4096 ? : 1 0 1
Condition33%1/3
not grep(($_->[0] == 1), @seq) and length $p->[1] <= 4096
!ll&&!rl&&r
001
MC/DC0%0/2
not grep(($_->[0] == 1), @seq) and length $p->[1] <= 4096
not grep(($_->[0] == 1), @seq) length $p->[1] <= 4096
Truth table33%1/3
not(A) and B
A= not grep(($_->[0] == 1), @seq)B= length $p->[1] <= 4096
ABresult
0X0
100
111
346 619 $next->() }) }->();
347 621 return }
348 269 ▶sub resume { my ($g, $node, $w, $k) = @_; $k->(defined $w ? status_of($w) : 1) } # on_exit of our children
Subroutine resume: called CC=2 SCAR=7.2
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
defined $w ? : 268 0 268
349  
350 # ------------------------------------------------------------------ redirections
351 # Applies @$redirs to a copy of $c's map: $k->(MAP, [opened ends]), or $k->() after a message.
352 1324 ▶sub redirect {
Subroutine redirect: called CC=1 SCAR=0.0
Pod undocumented
353 1327 my ($c, $redirs, $k) = @_;
354 1327 my %m = %{$c->{map}}; my @opened;
355 1324 ▶ my $fail = sub { msg({ map => \%m }, shift, sub { release($_) for @opened; $k->() }) }; # through the redirections so far
Subroutine __ANON__: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=2 SCAR=6.9
356 1324 my $i = 0;
357 1428 ▶ sub {
Subroutine __ANON__: called CC=9 SCAR=22.0
358 1429 ▶ return $k->(\%m, \@opened) if $i > $#$redirs;
Branch: 1 branch
BranchTrueFalseTotal
if $i > $redirs->$#* 1305 127 1432
359 126 my ($fd, $op, $w) = @{$redirs->[$i++]};
360 127 ▶ if ($op eq '<<') { # a here-document: Perl writes the expanded body into a pipe the command reads
Branch: 1 branch
BranchTrueFalseTotal
if ($op eq "<<") 12 115 127
361 12 my $next = __SUB__;
362 12 ▶ return expand_str($c, $w, sub { my $body = shift;
Subroutine __ANON__: called CC=2 SCAR=7.0
363 12 ▶ my ($r, $wr) = new_pipe() or return $fail->("pipe: $!");
Branch: 1 branch
BranchTrueFalseTotal
() = new_pipe() or return &$fail("pipe: $!") 12 0 12
364 12 ▶ push @opened, $m{$fd} = $r; on_write($wr, $body, sub { release($wr) }); $next->() }) }
Subroutine __ANON__: called CC=1 SCAR=0.0
365 114 ▶ if ($op eq '<&' or $op eq '>&') {
Branch: 1 branch
BranchTrueFalseTotal
if ($op eq "<&" or $op eq ">&") 37 78 115
Condition100%3/3
$op eq "<&" or $op eq ">&"
l!l&&r!l&&!r
63178
MC/DC100%2/2
$op eq "<&" or $op eq ">&"
$op eq "<&" $op eq ">&"
Truth table100%3/3
A or B
A= $op eq "<&"B= $op eq ">&"
ABresult
1X1
011
000
366 37 ▶ if ($w eq '-') { $m{$fd} = undef }
Branch: 3 branches
BranchTrueFalseTotal
if ($w eq '-') { } 4 33 37
elsif (exists $m{$w}) { } 30 3 33
elsif (visible($w)) { } 0 3 3
367 30 ▶ elsif (exists $m{$w}) { defined $m{$w} ? ($m{$fd} = $m{$w}) : return $fail->("$w: Bad file descriptor") }
Branch: 1 branch
BranchTrueFalseTotal
defined $m{$w} ? : 30 0 30
368 1 elsif (visible($w)) { $m{$fd} = own_fd($w) }
369 4 else { return $fail->("$w: Bad file descriptor") }
370 34 return __SUB__->() }
371 77 my $next = __SUB__;
372 77 ▶ expand_str($c, $w, sub {
Subroutine __ANON__: called CC=7 SCAR=19.5
373 77 my $name = shift;
374 77 ▶ my $e = $name ne '' && open_end($c, $name, $op);
Condition100%3/3
$name ne '' && open_end($c, $name, $op)
!ll&&!rl&&r
11859
MC/DC100%2/2
$name ne '' && open_end($c, $name, $op)
$name ne '' open_end($c, $name, $op)
Truth table100%3/3
A && B
A= $name ne ''B= open_end($c, $name, $op)
ABresult
0X0
100
111
375 78 ▶ if (!$e) { # dash's wording
Branch: 1 branch
BranchTrueFalseTotal
unless ($e) 19 59 78
376 483 ▶ my $err = $name eq '' || $!{ENOENT} ? ($op eq '<' ? 'No such file' : 'Directory nonexistent') : "$!";
Subroutine BEGIN: called CC=1 SCAR=0.0
Branch: 2 branches
BranchTrueFalseTotal
$name eq '' || $!{'ENOENT'} ? : 18 1 19
$op eq '<' ? : 2 16 18
Condition100%3/3
$name eq "" or $!{"ENOENT"}
l!l&&r!l&&!r
1171
MC/DC100%2/2
$name eq "" or $!{"ENOENT"}
$name eq "" $!{"ENOENT"}
Truth table100%3/3
A or B
A= $name eq ""B= $!{"ENOENT"}
ABresult
1X1
011
000
377 19 ▶ return $fail->(($op eq '<' ? 'cannot open' : 'cannot create') . " $name: $err") }
Branch: 1 branch
BranchTrueFalseTotal
$op eq '<' ? : 2 17 19
378 1324 push @opened, $m{$fd} = $e; $next->() }) }->() }
379  
380 # Runs $body->(CONTEXT, K2) with @$redirs applied, then $k->(STATUS); status 2 if they fail.
381 219 ▶sub with_redirs {
Subroutine with_redirs: called CC=3 SCAR=11.0
Pod undocumented
382 219 my ($c, $redirs, $tail, $k, $body) = @_;
383 219 ▶ return $body->($c, $tail, $k) unless $redirs && @$redirs;
Branch: 1 branch
BranchTrueFalseTotal
unless $redirs and @$redirs 194 25 219
Condition66%2/3
$redirs and @$redirs
!ll&&!rl&&r
194025
MC/DC50%1/2
$redirs and @$redirs
$redirs @$redirs
Truth table66%2/3
A and B
A= $redirsB= @$redirs
ABresult
0X0
100
111
384 25 ▶ redirect($c, $redirs, sub {
Subroutine __ANON__: called CC=4 SCAR=13.9
385 25 ▶ my ($m, $opened) = @_ or return defer($k, 2);
Branch: 1 branch
BranchTrueFalseTotal
my($m, $opened) = or return defer($k, 2) 22 3 25
386 22 my $d = derive($c, $m); release($_) for @$opened;
387 25 ▶ $body->($d, [$d, @{$tail // []}], sub { release_ctx($d); $k->(@_) }) }) }
Subroutine __ANON__: called CC=1 SCAR=0.0
Condition100%2/2
$tail // []
l!l
1111
MC/DC100%1/1
$tail // []
$tail
Truth table100%2/2
A
A= $tail
Aresult
11
00
388  
389 # ------------------------------------------------------------------ expansion
390 574 ▶sub var { # also $0-$9 ${10}..., $#, $$, $@ and $* (joined by the first character of IFS)
Subroutine var: called CC=14 SCAR=26.4
Pod undocumented
391 574 my ($c, $n) = @_; my $sh = $c->{sh};
392 574 ▶ return $n ? $sh->{args}[$n - 1] // '' : $sh->{arg0} // 'sh' if $n =~ /^[0-9]+\z/;
Branch: 2 branches
BranchTrueFalseTotal
if $n =~ /^[0-9]+\z/ 25 549 574
$n ? : 24 1 25
Condition75%3/4
$sh->{"args"}[$n - 1] // ""
l!l
222
$sh->{"arg0"} // "sh"
l!l
01
MC/DC100%1/1
$sh->{"args"}[$n - 1] // ""
$sh->{"args"}[$n - 1]
MC/DC0%0/1
$sh->{"arg0"} // "sh"
$sh->{"arg0"}
Truth table100%2/2
A
A= $sh->{"args"}[$n - 1]
Aresult
11
00
Truth table50%1/2
A
A= $sh->{"arg0"}
Aresult
11
00
393 12 ▶ $n eq '?' ? $sh->{q} : $n eq '!' ? ($sh->{bang} // {})->{first} // '' : $n eq '#' ? scalar @{$sh->{args}}
Branch: 2 branches
BranchTrueFalseTotal
$n eq '$' ? : 18 371 389
$n eq '@' || $n eq '*' ? : 15 356 371
Condition100%3/3
$n eq "\@" or $n eq "*"
l!l&&r!l&&!r
510356
MC/DC100%2/2
$n eq "\@" or $n eq "*"
$n eq "\@" $n eq "*"
Truth table100%3/3
A or B
A= $n eq "\@"B= $n eq "*"
ABresult
1X1
011
000
394 549 ▶ : $n eq '$' ? $sh->{pid} : $n eq '@' || $n eq '*' ? join(ifs1($c), @{$sh->{args}}) : $sh->{vars}{$n} // '' }
Branch: 3 branches
BranchTrueFalseTotal
$n eq '?' ? : 142 407 549
$n eq '!' ? : 6 401 407
$n eq '#' ? : 12 389 401
Condition100%6/6
+($sh->{"bang"} // {})->{"first"} // ""
l!l
42
$sh->{"bang"} // {}
l!l
51
$sh->{"vars"}{$n} // ""
l!l
32531
MC/DC100%1/1
+($sh->{"bang"} // {})->{"first"} // ""
$sh->{"bang"}
MC/DC100%1/1
$sh->{"vars"}{$n} // ""
$sh->{"vars"}{$n}
Truth table100%2/2
A
A= $sh->{"bang"}
Aresult
11
00
Truth table100%2/2
A
A= $sh->{"vars"}{$n}
Aresult
11
00
395 18 ▶sub ifs1 { my $i = $_[0]{sh}{vars}{IFS}; defined $i ? substr($i, 0, 1) : ' ' }
Subroutine ifs1: called CC=2 SCAR=7.2
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
defined $i ? : 18 0 18
396 53 ▶sub isset {
Subroutine isset: called CC=5 SCAR=16.1
Pod undocumented
397 53 my ($c, $n) = @_; my $sh = $c->{sh};
398 3 ▶ $n =~ /^[1-9][0-9]*\z/ ? $n <= @{$sh->{args}} : $n =~ /^[@*]\z/ ? !!@{$sh->{args}}
Branch: 2 branches
BranchTrueFalseTotal
$n =~ /^[\@*]\z/ ? : 4 46 50
$n eq '!' ? : 1 45 46
Condition66%2/3
$n =~ /^[?#\$0]\z/ or defined $sh->{"vars"}{$n}
l!l&&r!l&&!r
02124
MC/DC50%1/2
$n =~ /^[?#\$0]\z/ or defined $sh->{"vars"}{$n}
$n =~ /^[?#\$0]\z/ defined $sh->{"vars"}{$n}
Truth table66%2/3
A or B
A= $n =~ /^[?#\$0]\z/B= defined $sh->{"vars"}{$n}
ABresult
1X1
011
000
399 53 ▶ : $n eq '!' ? defined $sh->{bang} : $n =~ /^[?#\$0]\z/ || defined $sh->{vars}{$n} }
Branch: 1 branch
BranchTrueFalseTotal
$n =~ /^[1-9][0-9]*\z/ ? : 3 50 53
400 475 ▶sub getvar { # a value for $NAME, or undef after ending the shell (set -u)
Subroutine getvar: called CC=4 SCAR=14.1
Pod undocumented
401 475 my ($c, $n) = @_;
402 475 ▶ return fail($c, 2, "$n: parameter not set") if $c->{sh}{opt}{u} && $n !~ /^[@*!]\z/ && !isset($c, $n);
Branch: 1 branch
BranchTrueFalseTotal
if $c->{"sh"}{"opt"}{"u"} and not $n =~ /^[\@*!]\z/ and not isset($c, $n) 2 473 475
Condition66%4/6
$c->{"sh"}{"opt"}{"u"} and not $n =~ /^[\@*!]\z/ and not isset($c, $n)
!ll&&!rl&&r
47302
$c->{"sh"}{"opt"}{"u"} and not $n =~ /^[\@*!]\z/
!ll&&!rl&&r
47302
MC/DC33%1/3
$c->{"sh"}{"opt"}{"u"} and not $n =~ /^[\@*!]\z/ and not isset($c, $n)
$c->{"sh"}{"opt"}{"u"} not $n =~ /^[\@*!]\z/ not isset($c, $n)
Truth table50%2/4
A and not(B) and not(C)
A= $c->{"sh"}{"opt"}{"u"}B= not $n =~ /^[\@*!]\z/C= not isset($c, $n)
ABCresult
0XX0
10X0
1100
1111
403 473 var($c, $n) }
404  
405 642 ▶sub glob_quote { (my $s = shift) =~ s/([\\*?\[\]{}~!^-])/\\$1/g; $s } # also ! ^ -: literal inside [...]
Subroutine glob_quote: called CC=1 SCAR=0.0
Pod undocumented
406 43 ▶sub slash_brackets { # for bsd_glob: a bracket expression with a '/' is none, its '[' literal (both shells); [^...] as [!...]
Subroutine slash_brackets: called CC=6 SCAR=17.9
Pod undocumented
407 36 my $p = shift; my $o = '';
408 36 ▶ while ($p =~ /\G(?:(\\.)|(\[)|(.))/gcs) {
Branch: 1 branch
BranchTrueFalseTotal
if ($p =~ /\G(?:(\\.)|(\[)|(.))/cgs) 150 36 186
409 150 ▶ if (!defined $2) { $o .= $+; next }
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $2) 135 15 150
410 15 my $s = pos $p;
411 15 ▶ if ($p =~ /\G([!^]?)(\]?(?:\\.|\[:[a-z]+:\]|[^\]\\])*)\]/gcs) { my ($n, $b) = ($1, $2);
Branch: 1 branch
BranchTrueFalseTotal
if ($p =~ /\G([!^]?)(\]?(?:\\.|\[:[a-z]+:\]|[^\]\\])*)\]/cgs) { } 12 3 15
412 12 ▶ if ("$n$b" =~ m{/}) { $o .= '\\['; pos($p) = $s } else { $o .= ($n ? '[!' : '[') . "$b]" } } # [^...]: [!...] (rule E)
Branch: 2 branches
BranchTrueFalseTotal
if ("$n$b" =~ m[/]) { } 2 10 12
$n ? : 1 9 10
413 10 else { $o .= '['; pos($p) = $s } }
414 36 $o }
415  
416 # A Word into fields: $k->([FIELD, ...]). $how: 'argv' splits and globs; 'str' gives one string.
417 # A field under construction is [TEXT, PATTERN, KEEP]: PATTERN is the text for globbing, with
418 # quoted characters escaped, or undef if nothing in it may glob.
419 3359 ▶sub expand {
Subroutine expand: called CC=2 SCAR=7.0
Pod undocumented
420 3359 my ($c, $word, $how, $k) = @_;
421 3359 ▶ return $k->([$word]) unless ref $word;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $word 2811 555 3366
422 # a field: [TEXT, GLOB PATTERN (quoted characters escaped), KEEP even if empty, HAS ACTIVE GLOB CHARS]
423 555 my @f; my $cur = ['', '', 0, 0];
424 969 ▶ my $add = sub { # text; $pat: its glob characters are active; $split: an unquoted expansion
Subroutine __ANON__: called CC=21 SCAR=30.6
425 969 my ($t, $pat, $split) = @_;
426 969 ▶ my $ifs = $c->{sh}{vars}{IFS} // " \t\n";
Condition50%1/2
$c->{"sh"}{"vars"}{"IFS"} // " \t\n"
l!l
9690
MC/DC0%0/1
$c->{"sh"}{"vars"}{"IFS"} // " \t\n"
$c->{"sh"}{"vars"}{"IFS"}
Truth table50%1/2
A
A= $c->{"sh"}{"vars"}{"IFS"}
Aresult
11
00
427 969 ▶ if ($split && $how eq 'argv' && $ifs ne '') { # split at IFS characters (L2); the pieces may glob
Branch: 2 branches
BranchTrueFalseTotal
if ($split and $how eq 'argv' and $ifs ne '') { } 313 656 969
elsif ($split and $how eq 'argv') { } 2 654 656
Condition100%6/6
$split and $how eq "argv" and $ifs ne ""
!ll&&!rl&&r
6542313
$split and $how eq "argv"
!ll&&!rl&&r
62133315
MC/DC100%3/3
$split and $how eq "argv" and $ifs ne ""
$split $how eq "argv" $ifs ne ""
Truth table100%4/4
A and B and C
A= $splitB= $how eq "argv"C= $ifs ne ""
ABCresult
0XX0
10X0
1100
1111
428 313 my ($ws, $nw) = map quotemeta, join('', $ifs =~ /[ \t\n]/g), join('', $ifs =~ /[^ \t\n]/g);
429 313 ▶ my $d = $nw eq '' ? qr/[$ws]+/ : $ws eq '' ? qr/[$nw]/ : qr/[$ws]*[$nw][$ws]*|[$ws]+/;
Branch: 2 branches
BranchTrueFalseTotal
$nw eq '' ? : 308 5 313
$ws eq '' ? : 5 0 5
430 313 my @p = split /($d)/, $t, -1;
431 313 for my $j (0 .. $#p) {
432 349 ▶ if ($j % 2) { # a delimiter: one with a non-blank IFS character ends a field even if it is empty
Branch: 1 branch
BranchTrueFalseTotal
if ($j % 2) 23 326 349
433 23 ▶ push @f, $cur if length $cur->[0] or $cur->[2] or $nw ne '' && $p[$j] =~ /[$nw]/; $cur = ['', '', 0, 0]; next }
Branch: 1 branch
BranchTrueFalseTotal
if length $cur->[0] or $cur->[2] or $nw ne "" and $p[$j] =~ /[$nw]/ 22 1 23
Condition77%7/9
length $cur->[0] or $cur->[2] or $nw ne "" and $p[$j] =~ /[$nw]/
l!l&&r!l&&!r
2021
length $cur->[0] or $cur->[2]
l!l&&r!l&&!r
2003
$nw ne "" and $p[$j] =~ /[$nw]/
!ll&&!rl&&r
102
MC/DC50%2/4
length $cur->[0] or $cur->[2] or $nw ne "" and $p[$j] =~ /[$nw]/
length $cur->[0] $cur->[2] $nw ne "" $p[$j] =~ /[$nw]/
Truth table60%3/5
A or B or C and D
A= length $cur->[0]B= $cur->[2]C= $nw ne ""D= $p[$j] =~ /[$nw]/
ABCDresult
1XXX1
01XX1
00111
000X0
00100
434 326 ▶ $cur->[0] .= $p[$j]; $cur->[1] .= $p[$j]; $cur->[3] ||= $p[$j] =~ /[*?\[]/ } }
Condition100%3/3
$cur->[3] ||= $p[$j] =~ /[*?\[]/
l!l&&r!l&&!r
36317
MC/DC100%2/2
$cur->[3] ||= $p[$j] =~ /[*?\[]/
$cur->[3] $p[$j] =~ /[*?\[]/
Truth table100%3/3
A ||= B
A= $cur->[3]B= $p[$j] =~ /[*?\[]/
ABresult
1X1
011
000
435 2 ▶ elsif ($split && $how eq 'argv') { $cur->[0] .= $t; $cur->[1] .= $t; $cur->[3] ||= $t =~ /[*?\[]/ } # IFS empty: no splitting
Condition66%4/6
$split and $how eq "argv"
!ll&&!rl&&r
621332
$cur->[3] ||= $t =~ /[*?\[]/
l!l&&r!l&&!r
002
MC/DC100%2/2
$split and $how eq "argv"
$split $how eq "argv"
MC/DC0%0/2
$cur->[3] ||= $t =~ /[*?\[]/
$cur->[3] $t =~ /[*?\[]/
Truth table100%3/3
A and B
A= $splitB= $how eq "argv"
ABresult
0X0
100
111
Truth table33%1/3
A ||= B
A= $cur->[3]B= $t =~ /[*?\[]/
ABresult
1X1
011
000
436 654 ▶ else { $cur->[0] .= $t; $cur->[1] .= $pat ? $t : glob_quote($t); $cur->[3] ||= $pat && $t =~ /[*?\[]/;
Branch: 1 branch
BranchTrueFalseTotal
$pat ? : 43 611 654
Condition100%6/6
$cur->[3] ||= $pat && $t =~ /[*?\[]/
l!l&&r!l&&!r
1833603
$pat && $t =~ /[*?\[]/
!ll&&!rl&&r
601233
MC/DC0%0/3
$cur->[3] ||= $pat && $t =~ /[*?\[]/
$cur->[3] $pat $t =~ /[*?\[]/
Truth table0%0/4
A ||= B && C
A= $cur->[3]B= $patC= $t =~ /[*?\[]/
ABCresult
1XX1
0111
00X0
0100
437 555 ▶ $cur->[2] = 1 unless $pat } };
Branch: 1 branch
BranchTrueFalseTotal
unless $pat 611 43 654
438 555 my @parts = @$word; my $i = 0;
439 1513 ▶ sub {
Subroutine __ANON__: called CC=54 SCAR=41.5
440 1513 ▶ if ($i > $#parts) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i > $#parts) 538 975 1513
441 538 ▶ push @f, $cur if length $cur->[0] or $cur->[2] && !$cur->[4] or $how ne 'argv';
Branch: 1 branch
BranchTrueFalseTotal
if length $cur->[0] or $cur->[2] and not $cur->[4] or $how ne "argv" 525 13 538
Condition88%8/9
length $cur->[0] or $cur->[2] and not $cur->[4] or $how ne "argv"
l!l&&r!l&&!r
525013
length $cur->[0] or $cur->[2] and not $cur->[4]
l!l&&r!l&&!r
516913
$cur->[2] and not $cur->[4]
!ll&&!rl&&r
1129
MC/DC75%3/4
length $cur->[0] or $cur->[2] and not $cur->[4] or $how ne "argv"
length $cur->[0] $cur->[2] not $cur->[4] $how ne "argv"
Truth table66%4/6
A or B and not(C) or D
A= length $cur->[0]B= $cur->[2]C= not $cur->[4]D= $how ne "argv"
ABCDresult
1XXX1
011X1
00X11
01011
00X00
01000
442 538 ▶ return $k->([map $_->[0], @f]) if $how ne 'argv';
Branch: 1 branch
BranchTrueFalseTotal
if $how ne "argv" 37 501 538
443 return $k->([map { # a pattern that matches nothing stays as it is
444 501 my ($t, $p, undef, $g) = @$_;
445 524 ▶ my $base = !$g || is_abs($p) || $c->{sh}{cwd} eq Cwd::getcwd() ? '' : glob_quote($c->{sh}{cwd}) . '/';
Branch: 1 branch
BranchTrueFalseTotal
!$g || is_abs($p) || $c->{'sh'}{'cwd'} eq Cwd::getcwd() ? : 513 11 524
Condition100%6/6
not $g or is_abs($p) or $c->{"sh"}{"cwd"} eq Cwd::getcwd()
l!l&&r!l&&!r
4961711
not $g or is_abs($p)
l!l&&r!l&&!r
4851128
MC/DC100%3/3
not $g or is_abs($p) or $c->{"sh"}{"cwd"} eq Cwd::getcwd()
not $g is_abs($p) $c->{"sh"}{"cwd"} eq Cwd::getcwd()
Truth table100%4/4
not(A) or B or C
A= not $gB= is_abs($p)C= $c->{"sh"}{"cwd"} eq Cwd::getcwd()
ABCresult
1XX1
01X1
0011
0000
446 524 ▶ my @m = $g && !$c->{sh}{opt}{f} ? sort { $a cmp $b } grep !m{(?:^|/)\.\.?\z}, File::Glob::bsd_glob($base . slash_brackets($p), File::Glob::GLOB_QUOTE()) : (); # never . or .. (rule E, as bash)
Branch: 1 branch
BranchTrueFalseTotal
$g && !$c->{'sh'}{'opt'}{'f'} ? : 36 488 524
Condition100%3/3
$g and not $c->{"sh"}{"opt"}{"f"}
!ll&&!rl&&r
485336
MC/DC100%2/2
$g and not $c->{"sh"}{"opt"}{"f"}
$g not $c->{"sh"}{"opt"}{"f"}
Truth table100%3/3
A and not(B)
A= $gB= not $c->{"sh"}{"opt"}{"f"}
ABresult
0X0
100
111
447 524 ▶ s{^\Q$c->{sh}{cwd}\E/}{} for $base ? @m : ();
Branch: 1 branch
BranchTrueFalseTotal
$base ? : 11 513 524
448 524 ▶ @m ? @m : $t } @f]) }
Branch: 1 branch
BranchTrueFalseTotal
@m ? : 22 502 524
449 975 my $x = $parts[$i++]; my $next = __SUB__;
450 975 ▶ return $add->($x, 0), $next->() unless ref $x;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $x 346 629 975
451 629 my ($kind, @a) = @$x; (my $q = $kind) =~ s/^"//; my $split = $kind !~ /^"/;
452 629 ▶ if ($kind eq '*') { $add->($a[0], 1) }
Branch: 12 branches
BranchTrueFalseTotal
if ($kind eq '*') { } 43 586 629
elsif ($kind eq '~') { } 5 581 586
elsif ($kind eq '"$' and $a[0] eq '@' and $how eq 'argv') { } 12 569 581
elsif ($q eq '$') { } 434 135 569
elsif ($q eq '${#') { } 12 123 135
elsif ($q eq '${') { } 51 72 123
elsif ($kind eq q[']) { } 0 72 72
elsif ($kind eq 'ext') { } 0 72 72
elsif ($q eq '$((' and ref $a[0]) { } 0 72 72
elsif ($q eq '$((') { } 39 33 72
elsif ($q eq '$(') { } 33 0 33
elsif ($kind eq '{' or $kind eq '{..') { } 0 0 0
453 elsif ($kind eq '~') { $add->($a[0] ne '' ? ($WIN ? win_home($a[0]) : (getpwnam $a[0])[7]) // "~$a[0]" # ~ without HOME: from the password
454 : exists $c->{sh}{vars}{HOME} ? var($c, 'HOME') # file (G16); Windows: no user database,
455 5 ▶ : ($WIN ? $ENV{USERPROFILE} : (getpwuid $<)[7]) // '~', 0) } # USERPROFILE
Branch: 4 branches
BranchTrueFalseTotal
$a[0] ne '' ? : 2 3 5
$Proc::ShellSpawn::WIN ? : 0 2 2
exists $c->{'sh'}{'vars'}{'HOME'} ? : 1 2 3
$Proc::ShellSpawn::WIN ? : 0 2 2
Condition75%3/4
($Proc::ShellSpawn::WIN ? win_home($a[0]) : (getpwnam $a[0])[7]) // "~$a[0]"
l!l
11
($Proc::ShellSpawn::WIN ? $ENV{"USERPROFILE"} : (getpwuid $<)[7]) // "~"
l!l
20
MC/DC100%1/1
($Proc::ShellSpawn::WIN ? win_home($a[0]) : (getpwnam $a[0])[7]) // "~$a[0]"
($Proc::ShellSpawn::WIN ? win_home($a[0]) : (getpwnam $a[0])[7])
MC/DC0%0/1
($Proc::ShellSpawn::WIN ? $ENV{"USERPROFILE"} : (getpwuid $<)[7]) // "~"
($Proc::ShellSpawn::WIN ? $ENV{"USERPROFILE"} : (getpwuid $<)[7])
Truth table100%2/2
A
A= ($Proc::ShellSpawn::WIN ? win_home($a[0]) : (getpwnam $a[0])[7])
Aresult
11
00
Truth table50%1/2
A
A= ($Proc::ShellSpawn::WIN ? $ENV{"USERPROFILE"} : (getpwuid $<)[7])
Aresult
11
00
456 ▶ elsif ($kind eq '"$' && $a[0] eq '@' && $how eq 'argv') { # "$@": one field per parameter
Condition83%5/6
$kind eq "\"\$" and $a[0] eq "\@" and $how eq "argv"
!ll&&!rl&&r
569012
$kind eq "\"\$" and $a[0] eq "\@"
!ll&&!rl&&r
38918012
MC/DC66%2/3
$kind eq "\"\$" and $a[0] eq "\@" and $how eq "argv"
$kind eq "\"\$" $a[0] eq "\@" $how eq "argv"
Truth table75%3/4
A and B and C
A= $kind eq "\"\$"B= $a[0] eq "\@"C= $how eq "argv"
ABCresult
0XX0
10X0
1100
1111
457 12 ▶ my @p = @{$c->{sh}{args}}; $cur->[4] = 1 unless @p; # none: the field goes, quotes or not (L1)
Branch: 1 branch
BranchTrueFalseTotal
unless @p 3 9 12
458 12 ▶ for my $j (0 .. $#p) { if ($j) { push @f, $cur; $cur = ['', '', 0, 0] } $add->($p[$j], 0) } }
Branch: 1 branch
BranchTrueFalseTotal
if ($j) 12 9 21
459 434 ▶ elsif ($q eq '$') { my $v = getvar($c, $a[0]) // return; $add->($v, 0, $split) }
Condition100%2/2
getvar($c, $a[0]) // (return)
l!l
4331
MC/DC100%1/1
getvar($c, $a[0]) // (return)
getvar($c, $a[0])
Truth table100%2/2
A
A= getvar($c, $a[0])
Aresult
11
00
460 12 ▶ elsif ($q eq '${#') { my $v = getvar($c, $a[0]) // return; $add->(length $v, 0, $split) }
Condition50%1/2
getvar($c, $a[0]) // (return)
l!l
120
MC/DC0%0/1
getvar($c, $a[0]) // (return)
getvar($c, $a[0])
Truth table50%1/2
A
A= getvar($c, $a[0])
Aresult
11
00
461 elsif ($q eq '${') { # the word is expanded only if it is used, as in sh
462 51 my ($n, $op, $w) = @a; my $v = var($c, $n);
463 51 ▶ my $set = isset($c, $n) && ($op !~ /:/ || $v ne '');
Condition100%6/6
isset($c, $n) && (!($op =~ /:/) || $v ne '')
!ll&&!rl&&r
24225
not $op =~ /:/ or $v ne ""
l!l&&r!l&&!r
2412
MC/DC100%3/3
isset($c, $n) && (!($op =~ /:/) || $v ne '')
isset($c, $n) not $op =~ /:/ $v ne ""
Truth table100%4/4
A && not(B) or C
A= isset($c, $n)B= not $op =~ /:/C= $v ne ""
ABCresult
0XX0
1000
11X1
1011
464 51 ▶ if ($op =~ /^[%#]/) { # remove the smallest or largest matching suffix or prefix
Branch: 1 branch
BranchTrueFalseTotal
if ($op =~ /^[%#]/) 21 30 51
465 21 ▶ getvar($c, $n) // return; # set -u (L4)
Condition100%2/2
getvar($c, $n) // (return)
l!l
201
MC/DC100%1/1
getvar($c, $n) // (return)
getvar($c, $n)
Truth table100%2/2
A
A= getvar($c, $n)
Aresult
11
00
466 20 ▶ return pattern_re($c, $w, sub { my $re = shift;
Subroutine __ANON__: called CC=9 SCAR=22.0
467 27 ▶ my $trim = sub { my $v = shift; my @i = 0 .. length $v; @i = reverse @i if $op =~ /^(?:%|##)\z/;
Subroutine __ANON__: called CC=5 SCAR=16.1
Branch: 1 branch
BranchTrueFalseTotal
if $op =~ /^(?:%|##)\z/ 14 13 27
468 27 ▶ for my $i (@i) { my ($cut, $keep) = $op =~ /%/ ? (substr($v, $i), substr($v, 0, $i)) : (substr($v, 0, $i), substr($v, $i));
Branch: 1 branch
BranchTrueFalseTotal
$op =~ /%/ ? : 34 53 87
469 87 ▶ return $keep if $cut =~ $re }
Branch: 1 branch
BranchTrueFalseTotal
if $cut =~ /$re/ 23 64 87
470 20 $v };
471 20 ▶ if ($n eq '@' || $n eq '*') { # G4 (rule E, as bash): from each parameter, then as $@ or $* would be
Branch: 1 branch
BranchTrueFalseTotal
if ($n eq '@' or $n eq '*') { } 4 16 20
Condition100%3/3
$n eq "\@" or $n eq "*"
l!l&&r!l&&!r
2216
MC/DC100%2/2
$n eq "\@" or $n eq "*"
$n eq "\@" $n eq "*"
Truth table100%3/3
A or B
A= $n eq "\@"B= $n eq "*"
ABresult
1X1
011
000
472 4 my @t = map $trim->($_), @{$c->{sh}{args}};
473 4 ▶ if ($kind eq '"${' && $n eq '@' && $how eq 'argv') { # "${@#p}": one field per parameter, as "$@"
Branch: 1 branch
BranchTrueFalseTotal
if ($kind eq '"${' and $n eq '@' and $how eq 'argv') { } 1 3 4
Condition83%5/6
$kind eq "\"\${" and $n eq "\@" and $how eq "argv"
!ll&&!rl&&r
301
$kind eq "\"\${" and $n eq "\@"
!ll&&!rl&&r
121
MC/DC66%2/3
$kind eq "\"\${" and $n eq "\@" and $how eq "argv"
$kind eq "\"\${" $n eq "\@" $how eq "argv"
Truth table75%3/4
A and B and C
A= $kind eq "\"\${"B= $n eq "\@"C= $how eq "argv"
ABCresult
0XX0
10X0
1100
1111
474 1 ▶ $cur->[4] = 1 unless @t; for my $j (0 .. $#t) { if ($j) { push @f, $cur; $cur = ['', '', 0, 0] } $add->($t[$j], 0) } }
Branch: 2 branches
BranchTrueFalseTotal
unless @t 0 1 1
if ($j) 2 1 3
475 3 else { $add->(join(ifs1($c), @t), 0, $split) } }
476 16 else { $add->($trim->($v), 0, $split) }
477 20 $next->() }) }
478 30 ▶ my $word = $op =~ /[-=?]/ ? !$set : $set;
Branch: 1 branch
BranchTrueFalseTotal
$op =~ /[-=?]/ ? : 27 3 30
479 30 ▶ unless ($word) { $add->($op =~ /[-=?]/ ? $v : '', 0, $split); return $next->() }
Branch: 2 branches
BranchTrueFalseTotal
unless ($word) 4 26 30
$op =~ /[-=?]/ ? : 3 1 4
480 18 ▶ return expand($c, $w, 'str', sub { my $t = $_[0][0];
Subroutine __ANON__: called CC=6 SCAR=18.0
481 18 ▶ return fail($c, 2, "$n: " . ($t ne '' ? $t : $op =~ /:/ ? 'parameter not set or null' : 'parameter not set')) if $op =~ /\?/;
Branch: 3 branches
BranchTrueFalseTotal
if $op =~ /\?/ 5 13 18
$t ne '' ? : 3 2 5
$op =~ /:/ ? : 2 0 2
482 13 ▶ if ($op =~ /=/) { setvar($c, $n, $t) or return }
Branch: 2 branches
BranchTrueFalseTotal
if ($op =~ /=/) 2 11 13
setvar($c, $n, $t) or return 2 0 2
483 26 ▶ $add->($t, 0, $split); $next->() }) if !$split || $op =~ /[=?]/;
Branch: 1 branch
BranchTrueFalseTotal
if not $split or $op =~ /[=?]/ 18 8 26
Condition100%3/3
not $split or $op =~ /[=?]/
l!l&&r!l&&!r
1178
MC/DC100%2/2
not $split or $op =~ /[=?]/
not $split $op =~ /[=?]/
Truth table100%3/3
not(A) or B
A= not $splitB= $op =~ /[=?]/
ABresult
1X1
011
000
484 8 ▶ return each_async(ref $w ? $w : [$w], sub { my ($p, $more) = @_; # unquoted: strings are split, ["'", text] is not
Subroutine __ANON__: called CC=3 SCAR=11.8
485 8 ▶ return $add->($p, 0, 1), $more->() unless ref $p;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $p 6 2 8
486 2 ▶ return $add->($p->[1], 0), $more->() if $p->[0] eq "'";
Branch: 1 branch
BranchTrueFalseTotal
if $p->[0] eq "'" 2 0 2
487 0 ▶ expand($c, [$p], 'str', sub { $add->($_[0][0], 0, $p->[0] !~ /^"/); $more->() }) }, $next) }
Subroutine __ANON__: not called CC=1 SCAR=1.2
Branch: 1 branch
BranchTrueFalseTotal
ref $w ? : 2 6 8
488 0 elsif ($kind eq "'") { $add->($a[0], 0) }
489 0 ▶ elsif ($kind eq 'ext') { return handler($a[0])->($c, $x, sub { $add->(shift, 0, $split); $next->() }) }
Subroutine __ANON__: not called CC=1 SCAR=6.9
490 ▶ elsif ($q eq '$((' && ref $a[0]) { # with $( ), `...` or ${#NAME} inside (parser item P2): those first, then the text
Condition66%2/3
$q eq "\$((" and ref $a[0]
!ll&&!rl&&r
33390
MC/DC0%0/2
$q eq "\$((" and ref $a[0]
$q eq "\$((" ref $a[0]
Truth table66%2/3
A and B
A= $q eq "\$(("B= ref $a[0]
ABresult
0X0
100
111
491 0 ▶ return expand_str($c, $a[0], sub { my $v = arith($c, shift); return unless defined $v; $add->($v, 0, $split); $next->() }) }
Subroutine __ANON__: not called CC=2 SCAR=17.9
Branch: 1 branch
BranchTrueFalseTotal
unless defined $v 0 0 0
492 39 ▶ elsif ($q eq '$((') { my $v = arith($c, $a[0]); return unless defined $v; $add->($v, 0, $split) }
Branch: 1 branch
BranchTrueFalseTotal
unless defined $v 10 29 39
493 33 ▶ elsif ($q eq '$(') { return subst($c, $a[0], sub { $add->(shift, 0, $split); $next->() }) }
Subroutine __ANON__: called CC=1 SCAR=0.0
494 0 ▶ elsif ($kind eq '{' || $kind eq '{..') { die "Proc::ShellSpawn: brace expansion is not implemented" }
Condition0%0/3
$kind eq "{" or $kind eq "{.."
l!l&&r!l&&!r
000
MC/DC0%0/2
$kind eq "{" or $kind eq "{.."
$kind eq "{" $kind eq "{.."
Truth table0%0/3
A or B
A= $kind eq "{"B= $kind eq "{.."
ABresult
1X1
011
000
495 0 else { die "Proc::ShellSpawn: unknown part '$kind'" }
496 555 $next->() }->() }
497 15 ▶sub each_async { # $body->(ITEM, NEXT) for each item in turn (each may finish later), then $done->()
Subroutine each_async: called CC=1 SCAR=0.0
Pod undocumented
498 15 my ($items, $body, $done) = @_; my $i = 0;
499 15 ▶ sub { my $next = __SUB__; return $done->() if $i > $#$items; $body->($items->[$i++], $next) }->() }
Subroutine __ANON__: called CC=2 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
if $i > $items->$#* 15 15 30
500 235 ▶sub expand_str { my ($c, $w, $k) = @_; expand($c, $w, 'str', sub { $k->($_[0][0]) }) }
Subroutine __ANON__: called CC=1 SCAR=0.0
Subroutine expand_str: called CC=1 SCAR=0.0
Pod undocumented
501 1334 ▶sub expand_list { # several words, one after another (each may see the effect of the one before)
Subroutine expand_list: called CC=1 SCAR=0.0
Pod undocumented
502 1334 my ($c, $ws, $how, $k) = @_; my @out; my $i = 0;
503 1345 ▶ sub { my $next = __SUB__; # a loop while words expand at once (no deep recursion); a $( ) resumes it later
Subroutine __ANON__: called CC=3 SCAR=11.0
504 1345 ▶ while ($i <= $#$ws) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i <= $ws->$#*) 3064 1320 4384
505 3064 my ($now, $done) = 1;
506 3061 ▶ expand($c, $ws->[$i++], $how, sub { push @out, @{$_[0]}; $now ? $done = 1 : $next->() });
Subroutine __ANON__: called CC=2 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
$now ? : 3042 8 3050
507 3064 ▶ $now = 0; $done or return }
Branch: 1 branch
BranchTrueFalseTotal
$done or return 3042 22 3064
508 1337 $k->(\@out) }->() }
509  
510 33 ▶sub subst { # $( list ): $k->(OUTPUT without trailing newlines)
Subroutine subst: called CC=2 SCAR=6.9
Pod undocumented
511 33 my ($c, $list, $k) = @_;
512 0 ▶ my ($r, $w) = new_pipe() or return msg($c, "pipe: $!", sub { $k->('') });
Subroutine __ANON__: not called CC=1 SCAR=1.2
Branch: 1 branch
BranchTrueFalseTotal
() = new_pipe() or return msg($c, "pipe: $!", sub { &$k(""); } ) 33 0 33
513 33 my ($out, $st, $eof) = ('');
514 33 ▶ my $done = sub { return unless $eof && defined $st; $c->{sh}{qsub} = $st; $k->($out =~ tr/\0//dr =~ s/\n+\z//r) };
Subroutine __ANON__: called CC=3 SCAR=11.0
Branch: 1 branch
BranchTrueFalseTotal
unless $eof and defined $st 33 33 66
Condition100%3/3
$eof and defined $st
!ll&&!rl&&r
31233
MC/DC100%2/2
$eof and defined $st
$eof defined $st
Truth table100%3/3
A and B
A= $eofB= defined $st
ABresult
0X0
100
111
515 33 ▶ my $d = derive($c, { %{$c->{map}}, 1 => $w }, jobs => 1, shell => sub { $st = shift; $done->() }); release($w);
Subroutine __ANON__: called CC=1 SCAR=0.0
516 1033 ▶ on_read($r, 65536, sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
517 1033 ▶ return $eof = 1, release($r), $done->() unless defined $_[0];
Branch: 1 branch
BranchTrueFalseTotal
unless defined $_[0] 33 1000 1033
518 33 $out .= $_[0]; on_read($r, 65536, __SUB__) });
519 33 x_list($d, $list, [$d], $d->{shell}{exit}) }
520  
521 # $(( )): sh's integer arithmetic. undef (after a message, and leaving the shell) on error.
522 39 ▶sub arith {
Subroutine arith: called CC=8 SCAR=21.7
Pod undocumented
523 39 my ($c, $e) = @_; my $src = $e;
524 39 ▶ my $unset; $e =~ s/\$\{?([A-Za-z_][A-Za-z_0-9]*|[0-9]+|[?!#\$])\}?/getvar($c, $1) \/\/ ($unset = '0')/ge;
Condition50%1/2
getvar($c, $1) // ($unset = 0)
l!l
80
MC/DC0%0/1
getvar($c, $1) // ($unset = 0)
getvar($c, $1)
Truth table50%1/2
A
A= getvar($c, $1)
Aresult
11
00
525 39 ▶ return if $unset;
Branch: 1 branch
BranchTrueFalseTotal
if $unset 0 39 39
526 39 my @t = $e =~ /\G\s*(0[xX][0-9a-fA-F]+|[0-9]+|[A-Za-z_][A-Za-z_0-9]*|<<=|>>=|<<|>>|<=|>=|==|!=|&&|\|\||[-+*\/%&^|]=|[-+*\/%<>&^|!~?:()=])/gc;
527 39 ▶ my $err = sub { fail($c, 2, "arithmetic expression: $_[0]: \"$src\""); undef };
Subroutine __ANON__: called CC=1 SCAR=0.0
528 39 ▶ return $err->('syntax error') if $e !~ /\G\s*\z/gc;
Branch: 1 branch
BranchTrueFalseTotal
unless $e =~ /\G\s*\z/cg 0 39 39
529 39 my $p = 0; my $bad; local our $skip = 0; # $skip: inside the side of && || ?: that is not taken
530 483 ▶ use integer;
Subroutine BEGIN: called CC=1 SCAR=0.0
531 39 my %bin = ('*' => 9, '/' => 9, '%' => 9, '+' => 8, '-' => 8, '<<' => 7, '>>' => 7, '<' => 6, '<=' => 6,
532 '>' => 6, '>=' => 6, '==' => 5, '!=' => 5, '&' => 4, '^' => 3, '|' => 2, '&&' => 1, '||' => 0);
533 39 my ($expr, $unary); # weak (below): the two parsers call each other, and strong references would form a cycle
534 88 ▶ my $unary_s = $unary = sub {
Subroutine __ANON__: called CC=22 SCAR=37.7
535 88 ▶ my $x = $t[$p++] // return +($bad //= 'syntax error') && 0;
Condition66%4/6
$t[$p++] // (return ($bad //= "syntax error") && 0)
l!l
871
($bad //= 'syntax error') && 0
!ll
01
$bad //= "syntax error"
l!l
01
MC/DC100%1/1
$t[$p++] // (return ($bad //= "syntax error") && 0)
$t[$p++]
MC/DC0%0/1
($bad //= 'syntax error') && 0
($bad //= 'syntax error')
MC/DC0%0/1
$bad //= "syntax error"
$bad
Truth table100%2/2
A
A= $t[$p++]
Aresult
11
00
Truth table50%1/2
A
A= ($bad //= 'syntax error')
Aresult
00
11
Truth table50%1/2
A
A= $bad
Aresult
11
00
536 87 ▶ return -$unary->() if $x eq '-'; return +$unary->() if $x eq '+';
Branch: 2 branches
BranchTrueFalseTotal
if $x eq "-" 5 82 87
if $x eq "+" 0 82 82
537 82 ▶ return !$unary->() ? 1 : 0 if $x eq '!'; return ~$unary->() if $x eq '~';
Branch: 3 branches
BranchTrueFalseTotal
if $x eq "!" 0 82 82
!&$unary() ? : 0 0 0
if $x eq "~" 0 82 82
538 82 ▶ if ($x eq '(') { my $v = $expr->(0); ($t[$p++] // '') eq ')' or $bad //= 'syntax error'; return $v }
Branch: 2 branches
BranchTrueFalseTotal
if ($x eq "(") 1 81 82
($t[$p++] // "") eq ")" or $bad //= "syntax error" 1 0 1
Condition25%1/4
$t[$p++] // ""
l!l
10
$bad //= "syntax error"
l!l
00
MC/DC0%0/1
$t[$p++] // ""
$t[$p++]
MC/DC0%0/1
$bad //= "syntax error"
$bad
Truth table50%1/2
A
A= $t[$p++]
Aresult
11
00
Truth table0%0/2
A
A= $bad
Aresult
11
00
539 483 ▶ return do { no warnings 'portable'; $x =~ /^0[xX]/ ? hex $x : $x =~ /^0/ ? oct $x : $x } if $x =~ /^[0-9]/; # 64-bit, as dash
Subroutine BEGIN: called CC=1 SCAR=0.0
Branch: 3 branches
BranchTrueFalseTotal
if $x =~ /^[0-9]/ 73 8 81
$x =~ /^0[xX]/ ? : 0 73 73
$x =~ /^0/ ? : 13 60 73
540 8 ▶ if ($x =~ /^[A-Za-z_]/) { my $v = var($c, $x); $v = 0 if $v =~ /^\s*\z/;
Branch: 2 branches
BranchTrueFalseTotal
if ($x =~ /^[A-Za-z_]/) 8 0 8
if $v =~ /^\s*\z/ 0 8 8
541 8 ▶ $v =~ /^\s*[-+]?[0-9]+\s*\z/ or $skip or $bad //= "$x: not a number"; return $v + 0 }
Branch: 1 branch
BranchTrueFalseTotal
$v =~ /^\s*[-+]?[0-9]+\s*\z/ or $Proc::ShellSpawn::skip or $bad //= "${x}: not a number" 8 0 8
Condition20%1/5
$v =~ /^\s*[-+]?[0-9]+\s*\z/ or $Proc::ShellSpawn::skip
l!l&&r!l&&!r
800
$bad //= "${x}: not a number"
l!l
00
MC/DC0%0/2
$v =~ /^\s*[-+]?[0-9]+\s*\z/ or $Proc::ShellSpawn::skip
$v =~ /^\s*[-+]?[0-9]+\s*\z/ $Proc::ShellSpawn::skip
MC/DC0%0/1
$bad //= "${x}: not a number"
$bad
Truth table33%1/3
A or B
A= $v =~ /^\s*[-+]?[0-9]+\s*\z/B= $Proc::ShellSpawn::skip
ABresult
1X1
011
000
Truth table0%0/2
A
A= $bad
Aresult
11
00
542 0 ▶ $bad //= 'syntax error'; 0 };
Condition0%0/2
$bad //= "syntax error"
l!l
00
MC/DC0%0/1
$bad //= "syntax error"
$bad
Truth table0%0/2
A
A= $bad
Aresult
11
00
543 39 my $dead;
544 91 ▶ my $expr_s = $expr = sub {
Subroutine __ANON__: called CC=40 SCAR=39.7
545 88 my $min = shift;
546 88 ▶ if (!$min && ($t[$p] // '') =~ /^[A-Za-z_]/ && ($t[$p + 1] // '') =~ /^(?:<<|>>|[-+*\/%&^|])?=\z/) { # NAME op= EXPR, right to left
Branch: 1 branch
BranchTrueFalseTotal
if (not $min and ($t[$p] // "") =~ /^[A-Za-z_]/ and ($t[$p + 1] // "") =~ m[^(?:<<|>>|[-+*/%&^|])?=\z]) 5 83 88
Condition80%8/10
not $min and ($t[$p] // "") =~ /^[A-Za-z_]/ and ($t[$p + 1] // "") =~ m[^(?:<<|>>|[-+*/%&^|])?=\z]
!ll&&!rl&&r
7585
not $min and ($t[$p] // "") =~ /^[A-Za-z_]/
!ll&&!rl&&r
413413
$t[$p] // ""
l!l
470
$t[$p + 1] // ""
l!l
130
MC/DC33%1/3
not $min and ($t[$p] // "") =~ /^[A-Za-z_]/ and ($t[$p + 1] // "") =~ m[^(?:<<|>>|[-+*/%&^|])?=\z]
not $min $t[$p] $t[$p + 1]
Truth table50%2/4
not(A) and B and C
A= not $minB= $t[$p]C= $t[$p + 1]
ABCresult
0XX0
10X0
1100
1111
547 5 my ($n, $op) = @t[$p, $p + 1]; $p += 2; my $r = $expr->(0); $op =~ s/=\z//;
548 5 ▶ my $o = var($c, $n); $o = 0 if $o =~ /^\s*\z/;
Branch: 1 branch
BranchTrueFalseTotal
if $o =~ /^\s*\z/ 1 4 5
549 5 ▶ ($op =~ m{^[/%]\z} && !$r) ? ($bad //= 'division by zero') : $op ne '' and $r = eval "\$o $op \$r";
Branch: 2 branches
BranchTrueFalseTotal
$op =~ m[^[/%]\z] && !$r ? $bad //= "division by zero" : $op ne "" and $r = eval "\$o $op \$r" 3 2 5
$op =~ m[^[/%]\z] && !$r ? : 0 5 5
Condition20%1/5
$op =~ m[^[/%]\z] and not $r
!ll&&!rl&&r
500
$bad //= "division by zero"
l!l
00
MC/DC0%0/2
$op =~ m[^[/%]\z] and not $r
$op =~ m[^[/%]\z] not $r
MC/DC0%0/1
$bad //= "division by zero"
$bad
Truth table33%1/3
A and not(B)
A= $op =~ m[^[/%]\z]B= not $r
ABresult
0X0
100
111
Truth table0%0/2
A
A= $bad
Aresult
11
00
550 5 ▶ $skip or $dead or setvar($c, $n, $r) or $dead = 1; return $r }
Branch: 1 branch
BranchTrueFalseTotal
$Proc::ShellSpawn::skip or $dead or setvar($c, $n, $r) or $dead = 1 4 1 5
Condition50%3/6
$Proc::ShellSpawn::skip or $dead or setvar($c, $n, $r)
l!l&&r!l&&!r
041
$Proc::ShellSpawn::skip or $dead
l!l&&r!l&&!r
005
MC/DC33%1/3
$Proc::ShellSpawn::skip or $dead or setvar($c, $n, $r)
$Proc::ShellSpawn::skip $dead setvar($c, $n, $r)
Truth table50%2/4
A or B or C
A= $Proc::ShellSpawn::skipB= $deadC= setvar($c, $n, $r)
ABCresult
1XX1
01X1
0011
0000
551 83 my $l = $unary->();
552 83 ▶ while (defined(my $op = $t[$p])) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $op = $t[$p])) 48 77 125
553 48 ▶ if ($op eq '?' && $min <= 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($op eq "?" and $min <= 0) 1 47 48
Condition66%2/3
$op eq "?" and $min <= 0
!ll&&!rl&&r
4701
MC/DC50%1/2
$op eq "?" and $min <= 0
$op eq "?" $min <= 0
Truth table66%2/3
A and B
A= $op eq "?"B= $min <= 0
ABresult
0X0
100
111
554 1 ▶ $p++; my $a = do { local $skip = $skip || !$l; $expr->(0) };
Condition33%1/3
$Proc::ShellSpawn::skip || !$l
l!l&&r!l&&!r
001
MC/DC0%0/2
$Proc::ShellSpawn::skip || !$l
$Proc::ShellSpawn::skip !$l
Truth table33%1/3
A || not(B)
A= $Proc::ShellSpawn::skipB= !$l
ABresult
1X1
011
000
555 1 ▶ ($t[$p++] // '') eq ':' or $bad //= 'syntax error';
Branch: 1 branch
BranchTrueFalseTotal
($t[$p++] // "") eq ":" or $bad //= "syntax error" 1 0 1
Condition25%1/4
$t[$p++] // ""
l!l
10
$bad //= "syntax error"
l!l
00
MC/DC0%0/1
$t[$p++] // ""
$t[$p++]
MC/DC0%0/1
$bad //= "syntax error"
$bad
Truth table50%1/2
A
A= $t[$p++]
Aresult
11
00
Truth table0%0/2
A
A= $bad
Aresult
11
00
556 1 ▶ my $b = do { local $skip = $skip || $l; $expr->(0) }; $l = $l ? $a : $b; next }
Branch: 1 branch
BranchTrueFalseTotal
$l ? : 1 0 1
Condition33%1/3
$Proc::ShellSpawn::skip || $l
l!l&&r!l&&!r
010
MC/DC0%0/2
$Proc::ShellSpawn::skip || $l
$Proc::ShellSpawn::skip $l
Truth table33%1/3
A || B
A= $Proc::ShellSpawn::skipB= $l
ABresult
1X1
011
000
557 47 ▶ my $pr = $bin{$op}; last unless defined $pr && $pr >= $min; $p++;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $pr and $pr >= $min 6 41 47
Condition100%3/3
defined $pr and $pr >= $min
!ll&&!rl&&r
3341
MC/DC100%2/2
defined $pr and $pr >= $min
defined $pr $pr >= $min
Truth table100%3/3
A and B
A= defined $prB= $pr >= $min
ABresult
0X0
100
111
558 41 ▶ my $r = do { local $skip = $skip || ($op eq '&&' ? !$l : $op eq '||' ? $l : 0); $expr->($pr + 1) };
Branch: 2 branches
BranchTrueFalseTotal
$op eq '&&' ? : 2 36 38
$op eq '||' ? : 2 34 36
Condition100%3/3
$Proc::ShellSpawn::skip || ($op eq '&&' ? !$l : ($op eq '||' ? $l : 0))
l!l&&r!l&&!r
3236
MC/DC100%2/2
$Proc::ShellSpawn::skip || ($op eq '&&' ? !$l : ($op eq '||' ? $l : 0))
$Proc::ShellSpawn::skip ($op eq '&&' ? !$l : ($op eq '||' ? $l : 0))
Truth table100%3/3
A || B
A= $Proc::ShellSpawn::skipB= ($op eq '&&' ? !$l : ($op eq '||' ? $l : 0))
ABresult
1X1
011
000
559 41 ▶ if ($op eq '&&') { $l = $l && $r ? 1 : 0 } elsif ($op eq '||') { $l = $l || $r ? 1 : 0 }
Branch: 5 branches
BranchTrueFalseTotal
if ($op eq '&&') { } 2 39 41
elsif ($op eq '||') { } 2 37 39
elsif ($op =~ m[^[/%]\z] and not $r) { } 11 26 37
$l && $r ? : 0 2 2
$l || $r ? : 2 0 2
Condition66%4/6
$l and $r
!ll&&!rl&&r
110
$l or $r
l!l&&r!l&&!r
110
MC/DC0%0/2
$l and $r
$l $r
MC/DC0%0/2
$l or $r
$l $r
Truth table66%2/3
A and B
A= $lB= $r
ABresult
0X0
100
111
Truth table66%2/3
A or B
A= $lB= $r
ABresult
1X1
011
000
560 11 ▶ elsif ($op =~ m{^[/%]\z} && !$r) { $bad //= 'division by zero' unless $skip; $l = 0 }
Branch: 1 branch
BranchTrueFalseTotal
unless $Proc::ShellSpawn::skip 8 3 11
Condition80%4/5
$op =~ m[^[/%]\z] and not $r
!ll&&!rl&&r
23311
$bad //= "division by zero"
l!l
08
MC/DC100%2/2
$op =~ m[^[/%]\z] and not $r
$op =~ m[^[/%]\z] not $r
MC/DC0%0/1
$bad //= "division by zero"
$bad
Truth table100%3/3
A and not(B)
A= $op =~ m[^[/%]\z]B= not $r
ABresult
0X0
100
111
Truth table50%1/2
A
A= $bad
Aresult
11
00
561 29 ▶ else { $l = eval "\$l $op \$r" ; $l = $l ? 1 : 0 if $op =~ /^[<>=!]=?\z|^[<>]\z/ } }
Branch: 2 branches
BranchTrueFalseTotal
if $op =~ /^[<>=!]=?\z|^[<>]\z/ 1 25 26
$l ? : 1 0 1
562 39 $l };
563 483 ▶ no integer;
Subroutine BEGIN: called CC=1 SCAR=0.0
564 39 weaken($expr); weaken($unary); # $expr_s and $unary_s keep them alive until arith returns
565 39 ▶ my $v = $expr->(0); $bad //= 'syntax error' if $p <= $#t;
Branch: 1 branch
BranchTrueFalseTotal
if $p <= $#t 0 39 39
Condition0%0/2
$bad //= "syntax error"
l!l
00
MC/DC0%0/1
$bad //= "syntax error"
$bad
Truth table0%0/2
A
A= $bad
Aresult
11
00
566 39 ▶ return if $dead; # a readonly variable: the shell is already ending
Branch: 1 branch
BranchTrueFalseTotal
if $dead 1 38 39
567 38 ▶ defined $bad ? $err->($bad) : $v }
Branch: 1 branch
BranchTrueFalseTotal
defined $bad ? : 9 29 38
568  
569 # ------------------------------------------------------------------ the tree
570 # x_*($c, NODE, $tail, $k): run NODE in context $c, then $k->(STATUS). $tail: the contexts to
571 # release as soon as the last process NODE can start has started (undef: something may follow).
572 932 ▶sub after_start { release_ctx($_) for @{$_[0] // []} }
Subroutine after_start: called CC=3 SCAR=11.0
Pod undocumented
Condition100%2/2
$_[0] // []
l!l
229704
MC/DC100%1/1
$_[0] // []
$_[0]
Truth table100%2/2
A
A= $_[0]
Aresult
11
00
573  
574 792 ▶sub x_list {
Subroutine x_list: called CC=1 SCAR=0.0
Pod undocumented
575 792 my ($c, $l, $tail, $k) = @_; my $i = 0;
576 2184 ▶ sub { my $st = shift; my $p = $c->{sh}{pend}; my $me = __SUB__;
Subroutine __ANON__: called CC=7 SCAR=19.5
577 2180 ▶ return Proc::ShellSpawn::Large::run_pending($c, sub { $c->{sh}{q} = $st; $me->($st) }) if !$c->{intrap} && ($p && @$p || $c->{sh}{tbusy}); # X19
Subroutine __ANON__: called CC=1 SCAR=0.0
Branch: 1 branch
BranchTrueFalseTotal
if not $c->{"intrap"} and $p && @$p || $c->{"sh"}{"tbusy"} 2 2182 2184
Condition77%7/9
not $c->{"intrap"} and $p && @$p || $c->{"sh"}{"tbusy"}
!ll&&!rl&&r
1821642
$p and @$p or $c->{"sh"}{"tbusy"}
l!l&&r!l&&!r
022164
$p and @$p
!ll&&!rl&&r
18403260
MC/DC50%2/4
not $c->{"intrap"} and $p && @$p || $c->{"sh"}{"tbusy"}
not $c->{"intrap"} $p @$p $c->{"sh"}{"tbusy"}
Truth table66%4/6
not(A) and B and C or D
A= not $c->{"intrap"}B= $pC= @$pD= $c->{"sh"}{"tbusy"}
ABCDresult
0XXX0
10X00
11000
111X1
10X11
11011
578 2178 ▶ return defer($k, $st) if $i > $#$l;
Branch: 1 branch
BranchTrueFalseTotal
if $i > $l->$#* 710 1472 2182
579 792 ▶ x_andor($c, $l->[$i++], $i > $#$l ? $tail : undef, $me) }->(0) }
Branch: 1 branch
BranchTrueFalseTotal
$i > $l->$#* ? : 745 727 1472
580  
581 1503 ▶sub x_andor {
Subroutine x_andor: called CC=2 SCAR=6.9
Pod undocumented
582 1500 my ($c, $ao, $tail, $k) = @_;
583 1500 ▶ return x_bg($c, [@$ao[0 .. $#$ao - 1]], $k) if $ao->[-1] eq '&';
Branch: 1 branch
BranchTrueFalseTotal
if $ao->[-1] eq "&" 30 1472 1502
584 1475 my ($i, $ran) = (0, -1); my $cc = cond($c);
585 2935 ▶ sub { my $st = shift;
Subroutine __ANON__: called CC=12 SCAR=24.9
586 2935 ▶ $i += 2 while $i > 0 && $i <= $#$ao && ($ao->[$i - 1] eq '&&') != ($st == 0);
Branch: 1 branch
BranchTrueFalseTotal
$i > 0 and $i <= $ao->$#* and ($$ao[$i - 1] eq "&&") != ($st == 0) and do { $i += 2 } 10 2938 2948
Condition100%6/6
$i > 0 and $i <= $ao->$#* and ($$ao[$i - 1] eq "&&") != ($st == 0)
!ll&&!rl&&r
28706810
$i > 0 and $i <= $ao->$#*
!ll&&!rl&&r
1472139878
MC/DC100%3/3
$i > 0 and $i <= $ao->$#* and ($$ao[$i - 1] eq "&&") != ($st == 0)
$i > 0 $i <= $ao->$#* ($$ao[$i - 1] eq "&&") != ($st == 0)
Truth table100%4/4
A and B and C
A= $i > 0B= $i <= $ao->$#*C= ($$ao[$i - 1] eq "&&") != ($st == 0)
ABCresult
0XX0
10X0
1100
1111
587 2936 ▶ if ($i > $#$ao) { # set -e: the last pipeline failed, not negated, not in a condition
Branch: 1 branch
BranchTrueFalseTotal
if ($i > $ao->$#*) 1398 1540 2938
588 1399 ▶ return leave($c, $st) if $st && $c->{sh}{opt}{e} && !$c->{cond} && $ran == $#$ao && ref $ao->[-1][0];
Branch: 1 branch
BranchTrueFalseTotal
if $st and $c->{"sh"}{"opt"}{"e"} and not $c->{"cond"} and $ran == $ao->$#* and ref $ao->[-1][0] 6 1392 1398
Condition91%11/12
$st and $c->{"sh"}{"opt"}{"e"} and not $c->{"cond"} and $ran == $ao->$#* and ref $ao->[-1][0]
!ll&&!rl&&r
139116
$st and $c->{"sh"}{"opt"}{"e"} and not $c->{"cond"} and $ran == $ao->$#*
!ll&&!rl&&r
139107
$st and $c->{"sh"}{"opt"}{"e"} and not $c->{"cond"}
!ll&&!rl&&r
138927
$st and $c->{"sh"}{"opt"}{"e"}
!ll&&!rl&&r
12391509
MC/DC80%4/5
$st and $c->{"sh"}{"opt"}{"e"} and not $c->{"cond"} and $ran == $ao->$#* and ref $ao->[-1][0]
$st $c->{"sh"}{"opt"}{"e"} not $c->{"cond"} $ran == $ao->$#* ref $ao->[-1][0]
Truth table83%5/6
A and B and not(C) and D and E
A= $stB= $c->{"sh"}{"opt"}{"e"}C= not $c->{"cond"}D= $ran == $ao->$#*E= ref $ao->[-1][0]
ABCDEresult
0XXXX0
10XXX0
110XX0
1110X0
111100
111111
589 1393 return defer($k, $st) }
590 1539 my $p = $ao->[$ran = $i]; $i += 2;
591 1475 ▶ x_pipeline($i > $#$ao ? $c : $cc, $p, $i > $#$ao ? $tail : undef, __SUB__) }->(0) }
Branch: 2 branches
BranchTrueFalseTotal
$i > $ao->$#* ? : 1463 77 1540
$i > $ao->$#* ? : 1463 77 1540
592 1523 ▶sub cond { +{ %{$_[0]}, cond => 1, held => 0 } } # a context whose commands do not trigger set -e
Subroutine cond: called CC=1 SCAR=0.0
Pod undocumented
593  
594 28 ▶sub x_bg { # chain & : its own shell and job, fd 0 from /dev/null
Subroutine x_bg: called CC=2 SCAR=6.9
Pod undocumented
595 30 my ($c, $ao, $k) = @_;
596 30 ▶ my $null = open_end($c, '/dev/null', '<') or return msg($c, "/dev/null: $!", sub { $k->(2) });
Subroutine __ANON__: called CC=1 SCAR=0.2
Branch: 1 branch
BranchTrueFalseTotal
my $null = open_end($c, "/dev/null", "<") or return msg($c, "/dev/null: $!", sub { &$k(2); } ) 30 0 30
597 30 my $job = { pids => [] }; $JOBS{$job} = $job; push @{$c->{sh}{jobl}}, $job;
598 30 $job->{id} = ++$c->{sh}{jobs};
599 30 ▶ my $d = derive($c, { %{$c->{map}}, 0 => $null }, shell => sub {
Subroutine __ANON__: called CC=3 SCAR=11.0
600 30 tr_("background job $job->{id}: done, status $_[0]"); delete $JOBS{$job};
601 30 ▶ $job->{st} = shift; $_->() for splice @{$job->{waiters} // []} }); # for the wait builtin
Condition100%2/2
$job->{"waiters"} // []
l!l
1218
MC/DC100%1/1
$job->{"waiters"} // []
$job->{"waiters"}
Truth table100%2/2
A
A= $job->{"waiters"}
Aresult
11
00
602 30 release($null);
603 30 $d->{sh}{job} = $job; # shared by the job's shells: its first process becomes $!
604 30 x_andor($d, $ao, [$d], $d->{shell}{exit});
605 28 $c->{sh}{bang} = $job;
606 30 $c->{sh}{q} = 0; defer($k, 0) }
607  
608 1540 ▶sub x_pipeline {
Subroutine x_pipeline: called CC=11 SCAR=24.0
Pod undocumented
609 1540 my ($c, $p, $tail, $k) = @_;
610 1540 ▶ my @cmd = @$p; my $neg = !ref $cmd[0] && shift @cmd; $c = cond($c) if $neg;
Branch: 1 branch
BranchTrueFalseTotal
if $neg 3 1537 1540
Condition66%2/3
!ref($cmd[0]) && shift @cmd
!ll&&!rl&&r
153703
MC/DC50%1/2
!ref($cmd[0]) && shift @cmd
!ref($cmd[0]) shift @cmd
Truth table66%2/3
not(A) && B
A= !ref($cmd[0])B= shift @cmd
ABresult
0X0
100
111
611 1537 ▶ my $kk = sub { my $st = $neg ? ($_[0] ? 0 : 1) : $_[0]; $c->{sh}{q} = $st; $k->($st) };
Subroutine __ANON__: called CC=3 SCAR=11.0
Branch: 2 branches
BranchTrueFalseTotal
$neg ? : 3 1463 1466
$_[0] ? : 0 3 3
612 1537 ▶ return x_cmd($c, $cmd[0], $tail, $kk) if @cmd == 1;
Branch: 1 branch
BranchTrueFalseTotal
if @cmd == 1 1444 96 1540
613 96 my (@ends, @d, @st); my $left = @cmd;
614 96 ▶ for (1 .. $#cmd) { push @ends, [new_pipe()]; @{$ends[-1]} or return msg($c, "pipe: $!", sub { $kk->(2) }) }
Subroutine __ANON__: not called CC=1 SCAR=0.0
Branch: 1 branch
BranchTrueFalseTotal
@{$ends[-1];} or return msg($c, "pipe: $!", sub { &$kk(2); } ) 100 0 100
615 96 for my $j (0 .. $#cmd) { # each element: a shell of its own, fds 0 and 1 on the pipes
616 196 my %m = %{$c->{map}};
617 196 ▶ $m{0} = $ends[$j - 1][0] if $j; $m{1} = $ends[$j][1] if $j < $#cmd;
Branch: 2 branches
BranchTrueFalseTotal
if $j 100 96 196
if $j < $#cmd 100 96 196
618 196 ▶ my $done = sub { $st[$j] = shift; defer($kk, $st[-1]) unless --$left };
Subroutine __ANON__: called CC=2 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
unless --$left 96 100 196
619 196 $d[$j] = derive($c, \%m, jobs => 1, shell => $done) }
620 99 release($_) for map @$_, @ends; # the creator's holds: only the elements' remain
621 99 x_cmd($d[$_], $cmd[$_], [$d[$_]], $d[$_]{shell}{exit}) for 0 .. $#cmd;
622 99 after_start($tail) }
623  
624 1670 ▶sub x_cmd {
Subroutine x_cmd: called CC=8 SCAR=20.8
Pod undocumented
625 1670 my ($c, $x, $tail, $k) = @_;
626 1670 ▶ $c->{sh}{vars}{LINENO} = $x->{line} if $x->{line}; # G8 (rule E, as bash): the line where the command starts
Branch: 1 branch
BranchTrueFalseTotal
if $x->{"line"} 5 1668 1673
627 1670 ▶ return x_simple($c, $x, $tail, $k) if $x->{argv};
Branch: 1 branch
BranchTrueFalseTotal
if $x->{"argv"} 1307 366 1673
628 366 ▶ return with_redirs($c, $x->{redir}, undef, $k, sub { x_cd($_[0], $x, $_[2]) }) if exists $x->{cd}; # cd with redirections (post4-0.03)
Subroutine __ANON__: called CC=1 SCAR=0.0
Branch: 1 branch
BranchTrueFalseTotal
if exists $x->{"cd"} 47 319 366
629 319 ▶ return x_set($c, $x, $k) if $x->{set};
Branch: 1 branch
BranchTrueFalseTotal
if $x->{"set"} 103 216 319
630 216 ▶ return handler('Proc::ShellSpawn::Large::x_rest')->($c, $x, $tail, $k) if exists $x->{rest}; # P1
Branch: 1 branch
BranchTrueFalseTotal
if exists $x->{"rest"} 2 214 216
631 214 ▶ if (my ($h) = $x->{ext} // map $KIND{$_}, grep exists $x->{$_}, sort keys %KIND) { return handler($h)->($c, $x, $tail, $k) }
Branch: 1 branch
BranchTrueFalseTotal
if (my($h) = $x->{"ext"} // map($Proc::ShellSpawn::KIND{$_}, grep(exists $x->{$_}, sort(keys %Proc::ShellSpawn::KIND)))) 42 172 214
Condition66%2/3
$x->{"ext"} // map($Proc::ShellSpawn::KIND{$_}, grep(exists $x->{$_}, sort(keys %Proc::ShellSpawn::KIND)))
l!l&&r!l&&!r
042172
MC/DC50%1/2
$x->{"ext"} // map($Proc::ShellSpawn::KIND{$_}, grep(exists $x->{$_}, sort(keys %Proc::ShellSpawn::KIND)))
$x->{"ext"} map($Proc::ShellSpawn::KIND{$_}, grep(exists $x->{$_}, sort(keys %Proc::ShellSpawn::KIND)))
Truth table66%2/3
A // B
A= $x->{"ext"}B= map($Proc::ShellSpawn::KIND{$_}, grep(exists $x->{$_}, sort(keys %Proc::ShellSpawn::KIND)))
ABresult
1X1
011
000
632 169 ▶ with_redirs($c, $x->{redir}, $tail, $k, sub {
Subroutine __ANON__: called CC=9 SCAR=22.0
633 169 my ($c, $tail, $k) = @_;
634 169 ▶ if (my $l = $x->{group}) { return x_list($c, $l, $tail, $k) }
Branch: 1 branch
BranchTrueFalseTotal
if (my $l = $x->{"group"}) 68 101 169
635 101 ▶ if (my $l = $x->{sub}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $l = $x->{"sub"}) 37 64 101
636 37 my $d = derive($c, { %{$c->{map}} }, shell => $k);
637 37 ▶ return x_list($d, $l, [$d, @{$tail // []}], $d->{shell}{exit}) }
Condition100%2/2
$tail // []
l!l
1423
MC/DC100%1/1
$tail // []
$tail
Truth table100%2/2
A
A= $tail
Aresult
11
00
638 64 ▶ return x_if($c, $x->{if}, $tail, $k) if $x->{if};
Branch: 1 branch
BranchTrueFalseTotal
if $x->{"if"} 7 57 64
639 57 ▶ return x_while($c, $x, $k) if $x->{while} || $x->{until};
Branch: 1 branch
BranchTrueFalseTotal
if $x->{"while"} or $x->{"until"} 13 44 57
Condition100%3/3
$x->{"while"} or $x->{"until"}
l!l&&r!l&&!r
12144
MC/DC100%2/2
$x->{"while"} or $x->{"until"}
$x->{"while"} $x->{"until"}
Truth table100%3/3
A or B
A= $x->{"while"}B= $x->{"until"}
ABresult
1X1
011
000
640 44 ▶ return x_for($c, $x, $k) if exists $x->{for};
Branch: 1 branch
BranchTrueFalseTotal
if exists $x->{"for"} 27 17 44
641 17 ▶ return x_case($c, $x, $tail, $k) if exists $x->{case};
Branch: 1 branch
BranchTrueFalseTotal
if exists $x->{"case"} 17 0 17
642 0 die "Proc::ShellSpawn: unknown command node" }) }
643  
644 7 ▶sub x_if {
Subroutine x_if: called CC=1 SCAR=0.0
Pod undocumented
645 7 my ($c, $arms, $tail, $k) = @_; my $i = 0;
646 11 ▶ sub {
Subroutine __ANON__: called CC=3 SCAR=11.0
647 11 ▶ return defer($k, 0) if $i > $#$arms;
Branch: 1 branch
BranchTrueFalseTotal
if $i > $arms->$#* 3 8 11
648 8 ▶ return x_list($c, $arms->[$i], $tail, $k) if $i == $#$arms; # else
Branch: 1 branch
BranchTrueFalseTotal
if $i == $arms->$#* 0 8 8
649 8 my $then = $arms->[$i + 1]; $i += 2; my $next = __SUB__;
650 7 ▶ x_list(cond($c), $arms->[$i - 2], undef, sub { $_[0] ? $next->() : x_list($c, $then, $tail, $k) }) }->() }
Subroutine __ANON__: called CC=2 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
$_[0] ? : 4 4 8
651  
652 39 ▶sub loop { # runs $iter->(CONTEXT, NEXT, END) per iteration, with break and continue
Subroutine loop: called CC=1 SCAR=0.0
Pod undocumented
653 39 my ($c, $k, $iter) = @_; my $st = 0;
654 39 my $rec = { scope => [] };
655 39 my $lc = { %$c, loops => [@{$c->{loops}}, $rec] };
656 39 ▶ my $end = sub { release_all($rec->{scope}); delete @$rec{qw(brk cont)}; defer($k, @_ ? shift : $st) };
Subroutine __ANON__: called CC=2 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
@_ ? : 4 27 31
657 39 ▶ $rec->{brk} = sub { $end->(0) };
Subroutine __ANON__: called CC=1 SCAR=0.0
658 106 ▶ sub { my $next = __SUB__; release_all($rec->{scope}); $rec->{scope} = [];
Subroutine __ANON__: called CC=1 SCAR=0.0
659 39 ▶ $rec->{cont} = sub { $st = 0; $next->() }; $iter->($lc, sub { $st = shift; defer($next) }, $end) }->() }
Subroutine __ANON__: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=1 SCAR=0.0
660  
661 13 ▶sub x_while {
Subroutine x_while: called CC=1 SCAR=0.0
Pod undocumented
662 13 my ($c, $x, $k) = @_; my $until = exists $x->{until};
663 40 ▶ loop($c, $k, sub { my ($c, $next, $end) = @_;
Subroutine __ANON__: called CC=2 SCAR=7.0
664 40 ▶ x_list(cond($c), $x->{while} // $x->{until}, undef, sub {
Subroutine __ANON__: called CC=2 SCAR=7.0
665 13 ▶ ($_[0] == 0) != $until ? x_list($c, $x->{do}, undef, $next) : $end->() }) }) }
Branch: 1 branch
BranchTrueFalseTotal
($_[0] == 0) != $until ? : 30 10 40
Condition66%2/3
$x->{"while"} // $x->{"until"}
l!l&&r!l&&!r
3730
MC/DC0%0/2
$x->{"while"} // $x->{"until"}
$x->{"while"} $x->{"until"}
Truth table66%2/3
A // B
A= $x->{"while"}B= $x->{"until"}
ABresult
1X1
011
000
666  
667 27 ▶sub x_for {
Subroutine x_for: called CC=2 SCAR=7.0
Pod undocumented
668 27 my ($c, $x, $k) = @_;
669 26 ▶ expand_list($c, $x->{in} // [[['"$', '@']]], 'argv', sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
670 26 my @w = @{$_[0]};
671 66 ▶ loop($c, $k, sub { my ($c, $next, $end) = @_;
Subroutine __ANON__: called CC=3 SCAR=11.1
672 66 ▶ return $end->() unless @w;
Branch: 1 branch
BranchTrueFalseTotal
unless @w 17 49 66
673 27 ▶ setvar($c, $x->{for}, shift @w) or return; x_list($c, $x->{do}, undef, $next) }) }) }
Branch: 1 branch
BranchTrueFalseTotal
setvar($c, $x->{"for"}, shift @w) or return 49 0 49
Condition50%1/2
$x->{"in"} // [[["\"\$", "\@"]]]
l!l
270
MC/DC0%0/1
$x->{"in"} // [[["\"\$", "\@"]]]
$x->{"in"}
Truth table50%1/2
A
A= $x->{"in"}
Aresult
11
00
674  
675 17 ▶sub x_case {
Subroutine x_case: called CC=1 SCAR=0.0
Pod undocumented
676 17 my ($c, $x, $tail, $k) = @_; my @in = @{$x->{in}};
677 16 ▶ expand_str($c, $x->{case}, sub { my $s = shift;
Subroutine __ANON__: called CC=1 SCAR=0.0
678 17 ▶ sub { return defer($k, 0) unless @in;
Subroutine __ANON__: called CC=2 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
unless @in 0 17 17
679 17 my ($pats, $l) = splice @in, 0, 2; my $next = __SUB__; my @p = @$pats;
680 18 ▶ sub { return $next->() unless @p;
Subroutine __ANON__: called CC=2 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
unless @p 1 17 18
681 17 my $again = __SUB__;
682 17 ▶ pattern_re($c, shift @p, sub { $s =~ $_[0] ? x_list($c, $l, $tail, $k) : $again->() }) }->() }->() }) }
Subroutine __ANON__: called CC=2 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
$s =~ /$_[0]/ ? : 16 1 17
683  
684 37 ▶sub pattern_re { # a case (or ${N%p}) pattern as a regex anchored at both ends: quoted parts literal. The whole
Subroutine pattern_re: called CC=2 SCAR=7.0
Pod undocumented
685 37 my ($c, $w, $k) = @_; # pattern is put together first, quoted text escaped, so that a bracket expression may span Parts
686 37 ▶ my @parts = ref $w ? @$w : ($w); my $g = ''; my $i = 0;
Branch: 1 branch
BranchTrueFalseTotal
ref $w ? : 27 10 37
687 89 ▶ sub {
Subroutine __ANON__: called CC=5 SCAR=16.3
688 0 ▶ return $k->(eval { my $re = glob_re($g); qr/\A$re\z/s } // do { (my $t = $g) =~ s/\\(.)/$1/gs; qr/\A\Q$t\E\z/s })
Branch: 1 branch
BranchTrueFalseTotal
if $i > $#parts 37 52 89
Condition33%1/3
eval { do { my $re = glob_re($g); qr/\A$re\z/s } } // do { (my $t = $g) =~ s/\\(.)/$1/gs; qr/\A\Q$t\E\z/s }
l!l&&r!l&&!r
3700
MC/DC0%0/2
eval { do { my $re = glob_re($g); qr/\A$re\z/s } } // do { (my $t = $g) =~ s/\\(.)/$1/gs; qr/\A\Q$t\E\z/s }
eval { do { my $re = glob_re($g); qr/\A$re\z/s } } do { (my $t = $g) =~ s/\\(.)/$1/gs; qr/\A\Q$t\E\z/s }
Truth table33%1/3
A // B
A= eval { do { my $re = glob_re($g); qr/\A$re\z/s } }B= do { (my $t = $g) =~ s/\\(.)/$1/gs; qr/\A\Q$t\E\z/s }
ABresult
1X1
011
000
689 if $i > $#parts;
690 52 my $x = $parts[$i++]; my $next = __SUB__;
691 52 ▶ return $g .= glob_quote($x), $next->() unless ref $x;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $x 17 35 52
692 35 ▶ if ($x->[0] eq '*') { $g .= $x->[1]; return $next->() }
Branch: 1 branch
BranchTrueFalseTotal
if ($x->[0] eq "*") 31 4 35
693 37 ▶ expand($c, [$x], 'str', sub { $g .= $x->[0] =~ /^"/ ? glob_quote($_[0][0]) : $_[0][0]; $next->() }) }->() }
Subroutine __ANON__: called CC=2 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
$x->[0] =~ /^"/ ? : 3 1 4
694 37 ▶sub glob_re { # a glob pattern (quoted characters escaped with '\') as a regex
Subroutine glob_re: called CC=6 SCAR=17.9
Pod undocumented
695 37 my $g = shift; my $re = '';
696 37 ▶ while ($g =~ /\G(?:(\*)|(\?)|\[([!^]?)(\]?(?:\\.|\[:[a-z]+:\]|[^\]\\])*)\]|\\(.)|(.))/gcs) {
Branch: 1 branch
BranchTrueFalseTotal
if ($g =~ /\G(?:(\*)|(\?)|\[([!^]?)(\]?(?:\\.|\[:[a-z]+:\]|[^\]\\])*)\]|\\(.)|(.))/cgs) 56 37 93
697 56 ▶ $re .= defined $1 ? '.*' : defined $2 ? '.' : defined $4 ? bracket_re($3, $4) : quotemeta($5 // $6) }
Branch: 3 branches
BranchTrueFalseTotal
defined $1 ? : 15 41 56
defined $2 ? : 1 40 41
defined $4 ? : 12 28 40
Condition100%3/3
$5 // $6
l!l&&r!l&&!r
41014
MC/DC100%2/2
$5 // $6
$5 $6
Truth table100%3/3
A // B
A= $5B= $6
ABresult
1X1
011
000
698 37 $re }
699 12 ▶sub bracket_re { # the members of a bracket expression: classes and ranges kept, every other character literal
Subroutine bracket_re: called CC=6 SCAR=17.9
Pod undocumented
700 12 my ($neg, $b) = @_; my $o = '';
701 12 ▶ while ($b =~ /\G(?:(\[:[a-z]+:\])|\\(.)|(-)|(.))/gcs) { $o .= defined $1 ? $1 : defined $3 ? '-' : quotemeta($2 // $4) }
Branch: 3 branches
BranchTrueFalseTotal
if ($b =~ /\G(?:(\[:[a-z]+:\])|\\(.)|(-)|(.))/cgs) 16 12 28
defined $1 ? : 1 15 16
defined $3 ? : 1 14 15
Condition66%2/3
$2 // $4
l!l&&r!l&&!r
3110
MC/DC0%0/2
$2 // $4
$2 $4
Truth table66%2/3
A // B
A= $2B= $4
ABresult
1X1
011
000
702 12 ▶ '[' . ($neg ? '^' : '') . $o . ']' }
Branch: 1 branch
BranchTrueFalseTotal
$neg ? : 3 9 12
703  
704 356 ▶sub setvar { # 1, or 0 after ending the shell (a readonly variable, as dash)
Subroutine setvar: called CC=3 SCAR=11.0
Pod undocumented
705 356 my ($c, $n, $v) = @_; my $sh = $c->{sh};
706 356 ▶ return do { fail($c, 2, "$n: is read only"); 0 } if $sh->{ro}{$n};
Branch: 1 branch
BranchTrueFalseTotal
if $sh->{"ro"}{$n} 2 354 356
707 354 ▶ $sh->{exp}{$n} = 1 if $sh->{opt}{a}; $sh->{vars}{$n} = $v; 1 }
Branch: 1 branch
BranchTrueFalseTotal
if $sh->{"opt"}{"a"} 1 353 354
708  
709 107 ▶sub x_set { # NAME=value ... alone, or with redirections (D2: as dash, redirect first; failed: no setting, status 2)
Subroutine x_set: called CC=2 SCAR=6.9
Pod undocumented
710 107 my ($c, $x, $k) = @_; my @s = @{$x->{set}};
711 6 ▶ return redirect($c, $x->{redir}, sub { my ($m, $opened) = @_ or return defer($k, 2); # the values are expanded with
Subroutine __ANON__: called CC=3 SCAR=11.0
Branch: 1 branch
BranchTrueFalseTotal
my($m, $opened) = or return defer($k, 2) 4 2 6
712 4 my $d = derive($c, $m); release($_) for @$opened; # the redirections in force
713 107 ▶ x_set($d, { set => $x->{set} }, sub { release_ctx($d); $k->(@_) }) }) if $x->{redir}; # (rule E: category effect)
Subroutine __ANON__: called CC=1 SCAR=0.0
Branch: 1 branch
BranchTrueFalseTotal
if $x->{"redir"} 6 101 107
714 101 delete $c->{sh}{qsub}; my %log; # the settings as made, for $ONBUILTIN (measurement)
715 202 ▶ sub { unless (@s) { $ONBUILTIN->('x_set', [], {%log}) if $ONBUILTIN; return defer($k, $c->{sh}{qsub} // 0) }
Subroutine __ANON__: called CC=4 SCAR=13.9
Branch: 2 branches
BranchTrueFalseTotal
unless (@s) 99 103 202
if $Proc::ShellSpawn::ONBUILTIN 0 99 99
Condition100%2/2
$c->{"sh"}{"qsub"} // 0
l!l
2277
MC/DC100%1/1
$c->{"sh"}{"qsub"} // 0
$c->{"sh"}{"qsub"}
Truth table100%2/2
A
A= $c->{"sh"}{"qsub"}
Aresult
11
00
716 103 my ($n, $w) = splice @s, 0, 2; my $next = __SUB__;
717 101 ▶ expand_str($c, $w, sub { $log{$n} = $_[0]; setvar($c, $n, shift) or return; $next->() }) }->() }
Subroutine __ANON__: called CC=2 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
setvar($c, $n, shift()) or return 101 1 102
718  
719 47 ▶sub x_cd {
Subroutine x_cd: called CC=2 SCAR=7.1
Pod undocumented
720 47 my ($c, $x, $k) = @_;
721 46 ▶ my $go = sub {
Subroutine __ANON__: called CC=28 SCAR=36.4
722 46 ▶ my @f = @_; $ONBUILTIN->('x_cd', ['cd', ($x->{cd_p} ? '-P' : ()), @f], {}) if $ONBUILTIN; # (measurement)
Branch: 2 branches
BranchTrueFalseTotal
if $Proc::ShellSpawn::ONBUILTIN 0 46 46
$x->{'cd_p'} ? : 0 0 0
723 46 ▶ my $d = @f ? $f[0] : var($c, 'HOME');
Branch: 1 branch
BranchTrueFalseTotal
@f ? : 44 2 46
724 46 ▶ my $dash = @f == 1 && $d eq '-' and $d = var($c, 'OLDPWD'); # cd -: back, and print where
Branch: 1 branch
BranchTrueFalseTotal
my $dash = @f == 1 && $d eq "-" and $d = var($c, "OLDPWD") 4 42 46
Condition100%3/3
@f == 1 && $d eq '-'
!ll&&!rl&&r
2404
MC/DC100%2/2
@f == 1 && $d eq '-'
@f == 1 $d eq '-'
Truth table100%3/3
A && B
A= @f == 1B= $d eq '-'
ABresult
0X0
100
111
725 46 ▶ return defer($k, 0) if @f == 1 && $d eq '';
Branch: 1 branch
BranchTrueFalseTotal
if @f == 1 and $d eq "" 0 46 46
Condition66%2/3
@f == 1 and $d eq ""
!ll&&!rl&&r
2440
MC/DC0%0/2
@f == 1 and $d eq ""
@f == 1 $d eq ""
Truth table66%2/3
A and B
A= @f == 1B= $d eq ""
ABresult
0X0
100
111
726 46 ▶ return msg($c, "cd: too many arguments", sub { $k->(1) }) if $x->{cd_extra}; # as bash (rule E)
Subroutine __ANON__: called CC=1 SCAR=0.0
Branch: 1 branch
BranchTrueFalseTotal
if $x->{"cd_extra"} 1 45 46
727 45 ▶ return msg($c, "cd: HOME not set", sub { $k->(1) }) if !@f && ($d // '') eq ''; # as bash (rule E; N4)
Subroutine __ANON__: called CC=1 SCAR=0.0
Branch: 1 branch
BranchTrueFalseTotal
if not @f and ($d // "") eq "" 1 44 45
Condition80%4/5
not @f and ($d // "") eq ""
!ll&&!rl&&r
4311
$d // ""
l!l
20
MC/DC50%1/2
not @f and ($d // "") eq ""
not @f $d
Truth table66%2/3
not(A) and B
A= not @fB= $d
ABresult
0X0
100
111
728 0 ▶ if (@f > 1 or $d =~ /^-/ && !$dash) { return msg($c, "cd: bad argument", sub { $k->(2) }) }
Subroutine __ANON__: not called CC=1 SCAR=2.3
Branch: 1 branch
BranchTrueFalseTotal
if (@f > 1 or $d =~ /^-/ and not $dash) 0 44 44
Condition33%2/6
@f > 1 or $d =~ /^-/ and not $dash
l!l&&r!l&&!r
0044
$d =~ /^-/ and not $dash
!ll&&!rl&&r
4400
MC/DC0%0/3
@f > 1 or $d =~ /^-/ and not $dash
@f > 1 $d =~ /^-/ not $dash
Truth table25%1/4
A or B and not(C)
A= @f > 1B= $d =~ /^-/C= not $dash
ABCresult
1XX1
0111
00X0
0100
729 44 my $new = path_in($c, $d);
730 44 ▶ if ($x->{cd_p}) { $new = -d $new && Cwd::realpath($new) } # cd -P: symbolic links resolved, '..' physical (P6)
Branch: 1 branch
BranchTrueFalseTotal
if ($x->{'cd_p'}) { } 3 41 44
Condition66%2/3
-d $new && Cwd::realpath($new)
!ll&&!rl&&r
102
MC/DC50%1/2
-d $new && Cwd::realpath($new)
-d $new Cwd::realpath($new)
Truth table66%2/3
A && B
A= -d $newB= Cwd::realpath($new)
ABresult
0X0
100
111
731 else { # (Windows: the drive or the //server/share stays in front)
732 41 ▶ my ($pre, $rest) = $WIN && $new =~ m{^([A-Za-z]:|[/\\]{2}[^/\\]+[/\\][^/\\]+)(.*)}s ? ($1 =~ tr{\\}{/}r, $2) : ('', $new);
Branch: 1 branch
BranchTrueFalseTotal
$Proc::ShellSpawn::WIN && $new =~ m(^([A-Za-z]:|[/\\]{2}[^/\\]+[/\\][^/\\]+)(.*))s ? : 0 41 41
Condition33%1/3
$Proc::ShellSpawn::WIN and $new =~ m(^([A-Za-z]:|[/\\]{2}[^/\\]+[/\\][^/\\]+)(.*))s
!ll&&!rl&&r
4100
MC/DC0%0/2
$Proc::ShellSpawn::WIN and $new =~ m(^([A-Za-z]:|[/\\]{2}[^/\\]+[/\\][^/\\]+)(.*))s
$Proc::ShellSpawn::WIN $new =~ m(^([A-Za-z]:|[/\\]{2}[^/\\]+[/\\][^/\\]+)(.*))s
Truth table33%1/3
A and B
A= $Proc::ShellSpawn::WINB= $new =~ m(^([A-Za-z]:|[/\\]{2}[^/\\]+[/\\][^/\\]+)(.*))s
ABresult
0X0
100
111
733 41 ▶ my @p; for (split $SEP, $rest) { next if $_ eq '' or $_ eq '.'; $_ eq '..' ? pop @p : push @p, $_ }
Branch: 2 branches
BranchTrueFalseTotal
if $_ eq "" or $_ eq "." 30 83 113
$_ eq '..' ? : 2 81 83
Condition66%2/3
$_ eq "" or $_ eq "."
l!l&&r!l&&!r
30083
MC/DC50%1/2
$_ eq "" or $_ eq "."
$_ eq "" $_ eq "."
Truth table66%2/3
A or B
A= $_ eq ""B= $_ eq "."
ABresult
1X1
011
000
734 41 $new = $pre . '/' . join '/', @p }
735 44 ▶ $new && -d $new or return msg($c, "cd: can't cd to $d", sub { $k->(2) });
Subroutine __ANON__: called CC=1 SCAR=0.0
Branch: 1 branch
BranchTrueFalseTotal
$new and -d $new or return msg($c, "cd: can't cd to $d", sub { &$k(2); } ) 38 6 44
Condition100%3/3
$new and -d $new
!ll&&!rl&&r
1538
MC/DC100%2/2
$new and -d $new
$new -d $new
Truth table100%3/3
A and B
A= $newB= -d $new
ABresult
0X0
100
111
736 38 ▶ setvar($c, OLDPWD => $c->{sh}{cwd}) && setvar($c, PWD => $new) or return; $c->{sh}{cwd} = $new;
Branch: 1 branch
BranchTrueFalseTotal
setvar($c, "OLDPWD", $c->{"sh"}{"cwd"}) and setvar($c, "PWD", $new) or return 38 0 38
Condition33%1/3
setvar($c, "OLDPWD", $c->{"sh"}{"cwd"}) and setvar($c, "PWD", $new)
!ll&&!rl&&r
0038
MC/DC0%0/2
setvar($c, "OLDPWD", $c->{"sh"}{"cwd"}) and setvar($c, "PWD", $new)
setvar($c, "OLDPWD", $c->{"sh"}{"cwd"}) setvar($c, "PWD", $new)
Truth table33%1/3
A and B
A= setvar($c, "OLDPWD", $c->{"sh"}{"cwd"})B= setvar($c, "PWD", $new)
ABresult
0X0
100
111
737 47 ▶ $dash ? put($c, 1, "$new\n", sub { $k->(0) }) : defer($k, 0) };
Subroutine __ANON__: called CC=1 SCAR=0.0
Branch: 1 branch
BranchTrueFalseTotal
$dash ? : 4 34 38
738 47 ▶ defined $x->{cd} ? expand($c, $x->{cd}, 'argv', sub { $go->(@{$_[0]}) }) : $go->() }
Subroutine __ANON__: called CC=1 SCAR=0.0
Branch: 1 branch
BranchTrueFalseTotal
defined $x->{'cd'} ? : 45 2 47
739  
740 1304 ▶sub x_simple {
Subroutine x_simple: called CC=3 SCAR=11.0
Pod undocumented
741 1307 my ($c, $x, $tail, $k) = @_;
742 1307 ▶ $k = sub { leave($c, shift) } if $x->{exec}; # exec cmd: then the shell ends
Subroutine __ANON__: called CC=1 SCAR=0.0
Branch: 1 branch
BranchTrueFalseTotal
if $x->{"exec"} 3 1304 1307
743 1307 ▶ my @env = @{$x->{env} // []}; my %env;
Condition100%2/2
$x->{"env"} // []
l!l
151292
MC/DC100%1/1
$x->{"env"} // []
$x->{"env"}
Truth table100%2/2
A
A= $x->{"env"}
Aresult
11
00
744 1304 delete $c->{sh}{qsub};
745 1307 ▶ my $settings = sub { # NAME=value before the command, left to right, each seeing the ones before
Subroutine __ANON__: called CC=1 SCAR=0.0
746 1304 my $next = shift;
747 1323 ▶ sub { return $next->() unless @env;
Subroutine __ANON__: called CC=2 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
unless @env 1307 19 1326
748 19 my ($n, $w) = splice @env, 0, 2; my $again = __SUB__;
749 19 my $v = { %$c, sh => { %{$c->{sh}}, vars => { %{$c->{sh}{vars}}, %env } } };
750 1307 ▶ expand_str($v, $w, sub { $env{$n} = shift; $c->{sh}{qsub} = $v->{sh}{qsub} if exists $v->{sh}{qsub}; $again->() }) }->() };
Subroutine __ANON__: called CC=2 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
if exists $v->{"sh"}{"qsub"} 2 17 19
751 1307 ▶ $settings->(sub { expand_list($c, $x->{argv}, 'argv', sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=4 SCAR=13.9
752 1294 my @argv = @{$_[0]};
753 10 ▶ return redirect($c, $x->{redir} // [], sub { # every word expanded to nothing: the redirections are still done
Subroutine __ANON__: called CC=4 SCAR=13.9
754 1291 ▶ my ($m, $opened) = @_ or return defer($k, 2); release($_) for @$opened; defer($k, $c->{sh}{qsub} // 0) }) unless @argv;
Branch: 2 branches
BranchTrueFalseTotal
unless @argv 7 1287 1294
my($m, $opened) = or return defer($k, 2) 4 3 7
Condition75%3/4
$x->{"redir"} // []
l!l
70
$c->{"sh"}{"qsub"} // 0
l!l
13
MC/DC0%0/1
$x->{"redir"} // []
$x->{"redir"}
MC/DC100%1/1
$c->{"sh"}{"qsub"} // 0
$c->{"sh"}{"qsub"}
Truth table50%1/2
A
A= $x->{"redir"}
Aresult
11
00
Truth table100%2/2
A
A= $c->{"sh"}{"qsub"}
Aresult
11
00
755 1284 ▶ redirect($c, $x->{redir} // [], sub {
Subroutine __ANON__: called CC=16 SCAR=27.8
756 1287 my ($m, $opened) = @_;
757 1284 ▶ if (!$m) { return $SPECIAL{$argv[0]} ? leave($c, 2) : defer($k, 2) }
Branch: 2 branches
BranchTrueFalseTotal
unless ($m) 14 1273 1287
$Proc::ShellSpawn::SPECIAL{$argv[0]} ? : 3 11 14
758 1270 ▶ if (my $e = $c->{sh}{cmd}{$argv[0]} // ($x->{fn} ? ['Proc::ShellSpawn::Large::b_late'] : cmd_of($argv[0]))) { # a function or a builtin, in this process
Branch: 2 branches
BranchTrueFalseTotal
if (my $e = $c->{"sh"}{"cmd"}{$argv[0]} // ($x->{"fn"} ? ["Proc::ShellSpawn::Large::b_late"] : cmd_of($argv[0]))) 436 837 1273
$x->{'fn'} ? : 2 1238 1240
Condition100%3/3
$c->{"sh"}{"cmd"}{$argv[0]} // ($x->{"fn"} ? ["Proc::ShellSpawn::Large::b_late"] : cmd_of($argv[0]))
l!l&&r!l&&!r
33403837
MC/DC100%2/2
$c->{"sh"}{"cmd"}{$argv[0]} // ($x->{"fn"} ? ["Proc::ShellSpawn::Large::b_late"] : cmd_of($argv[0]))
$c->{"sh"}{"cmd"}{$argv[0]} ($x->{"fn"} ? ["Proc::ShellSpawn::Large::b_late"] : cmd_of($argv[0]))
Truth table100%3/3
A // B
A= $c->{"sh"}{"cmd"}{$argv[0]}B= ($x->{"fn"} ? ["Proc::ShellSpawn::Large::b_late"] : cmd_of($argv[0]))
ABresult
1X1
011
000
759 436 my $d = derive($c, $m); release($_) for @$opened; # a context holds its fds until it is done
760 436 ▶ $ONBUILTIN->($e->[0], \@argv, {%env}) if $ONBUILTIN; # (measurement: doc/large-subset/tools/large-subset-builtins.pl)
Branch: 1 branch
BranchTrueFalseTotal
if $Proc::ShellSpawn::ONBUILTIN 0 436 436
761 436 ▶ if ($SPECIAL{$argv[0]}) { setvar($c, $_, $env{$_}) or return for sort keys %env; %env = () } # these settings stay
Branch: 2 branches
BranchTrueFalseTotal
if ($Proc::ShellSpawn::SPECIAL{$argv[0]}) 129 307 436
setvar($c, $_, $env{$_}) or return 1 0 1
762 439 ▶ return handler($e->[0])->($d, \@argv, \%env, sub { release_ctx($d); $k->(@_) }, $e->[1]) }
Subroutine __ANON__: called CC=1 SCAR=0.0
763 837 ▶ @argv = printf_zero(@argv) if $argv[0] eq 'printf';
Branch: 1 branch
BranchTrueFalseTotal
if $argv[0] eq "printf" 32 805 837
764 837 my $node = spawn($c, $m, \@argv, \%env, $k);
765 834 ▶ $c->{sh}{job}{first} //= $node->{pid} if $node && $c->{sh}{job};
Branch: 1 branch
BranchTrueFalseTotal
if $node and $c->{"sh"}{"job"} 36 801 837
Condition83%5/6
$node and $c->{"sh"}{"job"}
!ll&&!rl&&r
57622536
$c->{"sh"}{"job"}{"first"} //= $node->{"pid"}
l!l&&r!l&&!r
8280
MC/DC100%2/2
$node and $c->{"sh"}{"job"}
$node $c->{"sh"}{"job"}
MC/DC0%0/2
$c->{"sh"}{"job"}{"first"} //= $node->{"pid"}
$c->{"sh"}{"job"}{"first"} $node->{"pid"}
Truth table100%3/3
A and B
A= $nodeB= $c->{"sh"}{"job"}
ABresult
0X0
100
111
Truth table66%2/3
A //= B
A= $c->{"sh"}{"job"}{"first"}B= $node->{"pid"}
ABresult
1X1
011
000
766 1307 ▶ release($_) for @$opened; after_start($tail) }) }) }) }
Condition100%2/2
$x->{"redir"} // []
l!l
741213
MC/DC100%1/1
$x->{"redir"} // []
$x->{"redir"}
Truth table100%2/2
A
A= $x->{"redir"}
Aresult
11
00
767  
768 32 ▶sub printf_zero { # the 0 flag of %s, %c, %b dropped from printf's format, as both shells (glibc's printf(3) ignores it; the
Subroutine printf_zero: called CC=7 SCAR=20.4
Pod undocumented
769 32 my @a = @_; # flag is undefined for them in C and POSIX); the program printf (coreutils) refuses it (decision Z0, 2026-11-05)
770 32 ▶ my $i = ($a[1] // '') eq '--' ? 2 : 1;
Branch: 1 branch
BranchTrueFalseTotal
($a[1] // '') eq '--' ? : 0 32 32
Condition50%1/2
$a[1] // ""
l!l
320
MC/DC0%0/1
$a[1] // ""
$a[1]
Truth table50%1/2
A
A= $a[1]
Aresult
11
00
771 32 ▶ return @a unless defined $a[$i] && $a[$i] !~ /^-/; # printf -v ...: the program's, as decided (Q2)
Branch: 1 branch
BranchTrueFalseTotal
unless defined $a[$i] and not $a[$i] =~ /^-/ 0 32 32
Condition33%1/3
defined $a[$i] and not $a[$i] =~ /^-/
!ll&&!rl&&r
0032
MC/DC0%0/2
defined $a[$i] and not $a[$i] =~ /^-/
defined $a[$i] not $a[$i] =~ /^-/
Truth table33%1/3
A and not(B)
A= defined $a[$i]B= not $a[$i] =~ /^-/
ABresult
0X0
100
111
772 32 $a[$i] =~ s{%(%|([-+ #0']*)(\*|[0-9]*)((?:\.(?:\*|[0-9]*))?)([a-zA-Z]))}{
773 24 my ($all, $fl, $w, $p, $cv) = ($1, $2, $3, $4, $5);
774 24 ▶ defined $cv && $cv =~ /^[scb]\z/ ? '%' . ($fl =~ tr/0//dr) . $w . $p . $cv : "%$all" }ge;
Branch: 1 branch
BranchTrueFalseTotal
defined $cv && $cv =~ /^[scb]\z/ ? : 14 10 24
Condition100%3/3
defined $cv and $cv =~ /^[scb]\z/
!ll&&!rl&&r
1914
MC/DC100%2/2
defined $cv and $cv =~ /^[scb]\z/
defined $cv $cv =~ /^[scb]\z/
Truth table100%3/3
A and B
A= defined $cvB= $cv =~ /^[scb]\z/
ABresult
0X0
100
111
775 32 @a }
776 88 ▶sub builtin { # : exit break continue read
Subroutine builtin: called CC=10 SCAR=23.1
Pod undocumented
777 88 my ($c, $argv, $env, $k) = @_; my $m = $c->{map};
778 88 my ($n, @a) = @$argv;
779 88 ▶ return defer($k, 0) if $n eq ':';
Branch: 1 branch
BranchTrueFalseTotal
if $n eq ":" 9 79 88
780 79 ▶ return leave($c, @a ? $a[0] % 256 : $c->{sh}{q}) if $n eq 'exit'; # exit 1000: 232, as both shells (parser item P4)
Branch: 2 branches
BranchTrueFalseTotal
if $n eq "exit" 14 65 79
@a ? : 14 0 14
781 65 ▶ if ($n eq 'break' || $n eq 'continue') {
Branch: 1 branch
BranchTrueFalseTotal
if ($n eq "break" or $n eq "continue") 16 49 65
Condition100%3/3
$n eq "break" or $n eq "continue"
l!l&&r!l&&!r
61049
MC/DC100%2/2
$n eq "break" or $n eq "continue"
$n eq "break" $n eq "continue"
Truth table100%3/3
A or B
A= $n eq "break"B= $n eq "continue"
ABresult
1X1
011
000
782 16 ▶ my $l = $c->{loops}; my $j = @a ? $a[0] : 1;
Branch: 1 branch
BranchTrueFalseTotal
@a ? : 7 9 16
783 16 ▶ return leave($c, 0) if $j > @$l; # the loop is outside this subshell: it ends the subshell, as dash (rule E, post-0.04)
Branch: 1 branch
BranchTrueFalseTotal
if $j > @$l 6 10 16
784 10 release_all(map $_->{scope}, @$l[$#$l - $j + 1 .. $#$l]);
785 10 ▶ return defer($l->[-$j]{$n eq 'break' ? 'brk' : 'cont'}) }
Branch: 1 branch
BranchTrueFalseTotal
$n eq 'break' ? : 4 6 10
786 49 ▶ if ($n eq 'read') { return read_line($c, $m, $env, \@a, $k) }
Branch: 1 branch
BranchTrueFalseTotal
if ($n eq "read") 49 0 49
787 0 die "Proc::ShellSpawn: builtin $n" }
788  
789 # read [-r] [-p PROMPT] NAME...: one line from fd 0, one byte at a time (later commands get the rest), split
790 # as sh does: IFS blanks around fields are dropped, one other IFS character ends a field, the last
791 # NAME gets the rest of the line; without -r a backslash protects the next character, and a
792 # backslash before the newline continues the line. Status 1 at end of file. The prompt of -p goes to fd 2,
793 # and only when fd 0 is a terminal, as in both shells (P6).
794 49 ▶sub read_line {
Subroutine read_line: called CC=17 SCAR=28.6
Pod undocumented
795 49 my ($c, $m, $env, $names, $k) = @_; my @a = @$names; my ($raw, $prompt);
796 49 ▶ while (@a && $a[0] =~ /^-(r*)(p?)\z/ && "$1$2" ne '') { shift @a; $raw ||= $1 ne ''; $prompt = shift @a if $2 }
Branch: 2 branches
BranchTrueFalseTotal
if (@a and $a[0] =~ /^-(r*)(p?)\z/ and "$1$2" ne "") 7 49 56
if $2 3 4 7
Condition77%7/9
@a and $a[0] =~ /^-(r*)(p?)\z/ and "$1$2" ne ""
!ll&&!rl&&r
4907
@a and $a[0] =~ /^-(r*)(p?)\z/
!ll&&!rl&&r
0497
$raw ||= $1 ne ""
l!l&&r!l&&!r
142
MC/DC33%1/3
@a and $a[0] =~ /^-(r*)(p?)\z/ and "$1$2" ne ""
@a $a[0] =~ /^-(r*)(p?)\z/ "$1$2" ne ""
MC/DC100%2/2
$raw ||= $1 ne ""
$raw $1 ne ""
Truth table50%2/4
A and B and C
A= @aB= $a[0] =~ /^-(r*)(p?)\z/C= "$1$2" ne ""
ABCresult
0XX0
10X0
1100
1111
Truth table100%3/3
A ||= B
A= $rawB= $1 ne ""
ABresult
1X1
011
000
797 # names may come from expansions (post-0.04): checked here, with dash's messages and status 2 (A5)
798 0 ▶ return msg($c, "read: arg count", sub { $k->(2) }) unless @a;
Subroutine __ANON__: not called CC=1 SCAR=1.2
Branch: 1 branch
BranchTrueFalseTotal
unless @a 0 49 49
799 49 ▶ for (@a) { return msg($c, "read: $_: bad variable name", sub { $k->(2) }) unless /^[A-Za-z_][A-Za-z0-9_]*\z/;
Subroutine __ANON__: called CC=1 SCAR=0.0
Branch: 1 branch
BranchTrueFalseTotal
unless /^[A-Za-z_][A-Za-z0-9_]*\z/ 1 66 67
800 66 ▶ return handler("Proc::ShellSpawn::Large::unsupported")->($c, "the name '$_' in 'read'") unless Proc::ShellSubset::settable($_);
Branch: 1 branch
BranchTrueFalseTotal
unless Proc::ShellSubset::settable($_) 0 66 66
801 66 ▶ return msg($c, "read: $_: is read only", sub { $k->(2) }) if $c->{sh}{ro}{$_} }
Subroutine __ANON__: called CC=1 SCAR=0.0
Branch: 1 branch
BranchTrueFalseTotal
if $c->{"sh"}{"ro"}{$_} 1 65 66
802 47 ▶ my $e = $m->{0} or return defer($k, 1);
Branch: 1 branch
BranchTrueFalseTotal
my $e = $m->{0} or return defer($k, 1) 46 1 47
803 46 ▶ my $ifs = $env->{IFS} // $c->{sh}{vars}{IFS} // " \t\n";
Condition60%3/5
($env->{"IFS"} // $c->{"sh"}{"vars"}{"IFS"}) // " \t\n"
l!l
460
$env->{"IFS"} // $c->{"sh"}{"vars"}{"IFS"}
l!l&&r!l&&!r
7390
MC/DC0%0/2
($env->{"IFS"} // $c->{"sh"}{"vars"}{"IFS"}) // " \t\n"
$env->{"IFS"} $c->{"sh"}{"vars"}{"IFS"}
Truth table66%2/3
A // B
A= $env->{"IFS"}B= $c->{"sh"}{"vars"}{"IFS"}
ABresult
1X1
011
000
804 46 my %ws = map +($_ => 1), grep /[ \t\n]/, split //, $ifs;
805 46 my %nw = map +($_ => 1), grep !/[ \t\n]/, split //, $ifs;
806 46 my $line = '';
807 46 ▶ my $got = sub {
Subroutine __ANON__: called CC=26 SCAR=32.7
808 46 my $eof = shift;
809 46 my @ch; # [character, protected by a backslash]
810 46 ▶ if ($raw) { @ch = map [$_, 0], split //, $line }
Branch: 1 branch
BranchTrueFalseTotal
if ($raw) { } 4 42 46
811 42 ▶ else { push @ch, defined $1 ? [$1, 1] : [$2, 0] while $line =~ /\G(?:\\(.)|([^\\]))/gs }
Branch: 2 branches
BranchTrueFalseTotal
$line =~ /\G(?:\\(.)|([^\\]))/gs and do { push @ch, defined $1 ? [$1, 1] : [$2, 0] } 719 42 761
defined $1 ? : 2 717 719
812 46 ▶ my $isws = sub { !$_[0][1] && $ws{$_[0][0]} }; my $isnw = sub { !$_[0][1] && $nw{$_[0][0]} };
Subroutine __ANON__: called CC=2 SCAR=6.9
Subroutine __ANON__: called CC=2 SCAR=6.9
Branch: 2 branches
BranchTrueFalseTotal
not $_[0][1] and $ws{$_[0][0]} 140 2 142
not $_[0][1] and $nw{$_[0][0]} 79 2 81
813 46 ▶ my $i = 0; $i++ while $i < @ch && $isws->($ch[$i]);
Branch: 1 branch
BranchTrueFalseTotal
$i < @ch and &$isws($ch[$i]) and do { ++$i } 2 46 48
Condition100%3/3
$i < @ch and &$isws($ch[$i])
!ll&&!rl&&r
8382
MC/DC100%2/2
$i < @ch and &$isws($ch[$i])
$i < @ch &$isws($ch[$i])
Truth table100%3/3
A and B
A= $i < @chB= &$isws($ch[$i])
ABresult
0X0
100
111
814 46 for my $j (0 .. $#a) {
815 64 ▶ if ($j == $#a) { # the rest; a single trailing delimiter after the only field is dropped, as in dash
Branch: 1 branch
BranchTrueFalseTotal
if ($j == $#a) 46 18 64
816 46 ▶ my @r = @ch[$i .. $#ch]; pop @r while @r && $isws->($r[-1]);
Branch: 1 branch
BranchTrueFalseTotal
@r and &$isws($r[-1]) and do { pop @r } 2 46 48
Condition100%3/3
@r and &$isws($r[-1])
!ll&&!rl&&r
10362
MC/DC100%2/2
@r and &$isws($r[-1])
@r &$isws($r[-1])
Truth table100%3/3
A and B
A= @rB= &$isws($r[-1])
ABresult
0X0
100
111
817 46 ▶ if (@r && $isnw->($r[-1]) && !grep $isws->($_) || $isnw->($_), @r[0 .. $#r - 1]) { pop @r; pop @r while @r && $isws->($r[-1]) }
Branch: 2 branches
BranchTrueFalseTotal
if (@r and &$isnw($r[-1]) and not grep((&$isws($_) || &$isnw($_)), @r[0 .. $#r - 1])) 1 45 46
@r and &$isws($r[-1]) and do { pop @r } 0 1 1
Condition58%7/12
@r and &$isnw($r[-1]) and not grep((&$isws($_) || &$isnw($_)), @r[0 .. $#r - 1])
!ll&&!rl&&r
4501
@r and &$isnw($r[-1])
!ll&&!rl&&r
10351
&$isws($_) || &$isnw($_)
l!l&&r!l&&!r
001
@r and &$isws($r[-1])
!ll&&!rl&&r
010
MC/DC66%2/3
@r and &$isnw($r[-1]) and not grep((&$isws($_) || &$isnw($_)), @r[0 .. $#r - 1])
@r &$isnw($r[-1]) not grep((&$isws($_) || &$isnw($_)), @r[0 .. $#r - 1])
MC/DC0%0/2
&$isws($_) || &$isnw($_)
&$isws($_) &$isnw($_)
MC/DC0%0/2
@r and &$isws($r[-1])
@r &$isws($r[-1])
Truth table75%3/4
A and B and not(C)
A= @rB= &$isnw($r[-1])C= not grep((&$isws($_) || &$isnw($_)), @r[0 .. $#r - 1])
ABCresult
0XX0
10X0
1100
1111
Truth table33%1/3
A || B
A= &$isws($_)B= &$isnw($_)
ABresult
1X1
011
000
Truth table33%1/3
A and B
A= @rB= &$isws($r[-1])
ABresult
0X0
100
111
818 46 setvar($c, $a[$j], join '', map $_->[0], @r); last }
819 18 ▶ my $f = ''; $f .= $ch[$i++][0] while $i < @ch && !$isws->($ch[$i]) && !$isnw->($ch[$i]);
Branch: 1 branch
BranchTrueFalseTotal
$i < @ch and not &$isws($ch[$i]) and not &$isnw($ch[$i]) and do { $f .= $ch[$i++][0] } 24 18 42
Condition100%6/6
$i < @ch and not &$isws($ch[$i]) and not &$isnw($ch[$i])
!ll&&!rl&&r
10824
$i < @ch and not &$isws($ch[$i])
!ll&&!rl&&r
6432
MC/DC100%3/3
$i < @ch and not &$isws($ch[$i]) and not &$isnw($ch[$i])
$i < @ch not &$isws($ch[$i]) not &$isnw($ch[$i])
Truth table100%4/4
A and not(B) and not(C)
A= $i < @chB= not &$isws($ch[$i])C= not &$isnw($ch[$i])
ABCresult
0XX0
10X0
1100
1111
820 18 setvar($c, $a[$j], $f);
821 18 ▶ $i++ while $i < @ch && $isws->($ch[$i]);
Branch: 1 branch
BranchTrueFalseTotal
$i < @ch and &$isws($ch[$i]) and do { ++$i } 4 18 22
Condition100%3/3
$i < @ch and &$isws($ch[$i])
!ll&&!rl&&r
6124
MC/DC100%2/2
$i < @ch and &$isws($ch[$i])
$i < @ch &$isws($ch[$i])
Truth table100%3/3
A and B
A= $i < @chB= &$isws($ch[$i])
ABresult
0X0
100
111
822 18 ▶ if ($i < @ch && $isnw->($ch[$i])) { $i++; $i++ while $i < @ch && $isws->($ch[$i]) } }
Branch: 2 branches
BranchTrueFalseTotal
if ($i < @ch and &$isnw($ch[$i])) 9 9 18
$i < @ch and &$isws($ch[$i]) and do { ++$i } 1 9 10
Condition83%5/6
$i < @ch and &$isnw($ch[$i])
!ll&&!rl&&r
639
$i < @ch and &$isws($ch[$i])
!ll&&!rl&&r
091
MC/DC100%2/2
$i < @ch and &$isnw($ch[$i])
$i < @ch &$isnw($ch[$i])
MC/DC50%1/2
$i < @ch and &$isws($ch[$i])
$i < @ch &$isws($ch[$i])
Truth table100%3/3
A and B
A= $i < @chB= &$isnw($ch[$i])
ABresult
0X0
100
111
Truth table66%2/3
A and B
A= $i < @chB= &$isws($ch[$i])
ABresult
0X0
100
111
823 46 ▶ defer($k, $eof ? 1 : 0) };
Branch: 1 branch
BranchTrueFalseTotal
$eof ? : 8 38 46
824 46 ▶ my $go = sub { on_read($e, 1, sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=5 SCAR=16.3
825 773 my $b = shift;
826 773 ▶ return $got->(1) unless defined $b;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $b 8 765 773
827 765 ▶ if ($b eq "\n") { # continued if the line ends in an odd number of backslashes
Branch: 1 branch
BranchTrueFalseTotal
if ($b eq "\n") 38 727 765
828 38 ▶ return $got->(0) if $raw or ($line =~ /(\\*)\z/)[0] =~ tr/\\// % 2 == 0;
Branch: 1 branch
BranchTrueFalseTotal
if $raw or ($line =~ /(\\*)\z/)[0] =~ tr/\\// % 2 == 0 38 0 38
Condition66%2/3
$raw or ($line =~ /(\\*)\z/)[0] =~ tr/\\// % 2 == 0
l!l&&r!l&&!r
4340
MC/DC0%0/2
$raw or ($line =~ /(\\*)\z/)[0] =~ tr/\\// % 2 == 0
$raw ($line =~ /(\\*)\z/)[0] =~ tr/\\// % 2 == 0
Truth table66%2/3
A or B
A= $rawB= ($line =~ /(\\*)\z/)[0] =~ tr/\\// % 2 == 0
ABresult
1X1
011
000
829 0 chop $line; return on_read($e, 1, __SUB__) }
830 46 $line .= $b; on_read($e, 1, __SUB__) }) };
831 46 ▶ defined $prompt && $e->{fh} && -t $e->{fh} ? put($c, 2, $prompt, $go) : $go->() }
Branch: 1 branch
BranchTrueFalseTotal
defined $prompt && $e->{'fh'} && -t $e->{'fh'} ? : 0 46 46
Condition66%4/6
defined $prompt and $e->{"fh"} and -t $e->{"fh"}
!ll&&!rl&&r
4330
defined $prompt and $e->{"fh"}
!ll&&!rl&&r
4303
MC/DC0%0/3
defined $prompt and $e->{"fh"} and -t $e->{"fh"}
defined $prompt $e->{"fh"} -t $e->{"fh"}
Truth table50%2/4
A and B and C
A= defined $promptB= $e->{"fh"}C= -t $e->{"fh"}
ABCresult
0XX0
10X0
1100
1111
832  
833 # ------------------------------------------------------------------ entry points
834 476 ▶sub start_pwd {
Subroutine start_pwd: called CC=5 SCAR=20.2
Pod undocumented
835 474 my $phys = Cwd::getcwd();
836 476 my $p = $ENV{PWD};
837 476 ▶ return $p if defined $p && is_abs($p) && (stat $p)[1] && join(':', (stat $p)[0, 1]) eq join(':', (stat '.')[0, 1]);
Branch: 1 branch
BranchTrueFalseTotal
if defined $p and is_abs($p) and (stat $p)[1] and join(":", (stat $p)[0, 1]) eq join(":", (stat ".")[0, 1]) 476 0 476
Condition33%3/9
defined $p and is_abs($p) and (stat $p)[1] and join(":", (stat $p)[0, 1]) eq join(":", (stat ".")[0, 1])
!ll&&!rl&&r
00476
defined $p and is_abs($p) and (stat $p)[1]
!ll&&!rl&&r
00476
defined $p and is_abs($p)
!ll&&!rl&&r
00476
MC/DC0%0/4
defined $p and is_abs($p) and (stat $p)[1] and join(":", (stat $p)[0, 1]) eq join(":", (stat ".")[0, 1])
defined $p is_abs($p) (stat $p)[1] join(":", (stat $p)[0, 1]) eq join(":", (stat ".")[0, 1])
Truth table20%1/5
A and B and C and D
A= defined $pB= is_abs($p)C= (stat $p)[1]D= join(":", (stat $p)[0, 1]) eq join(":", (stat ".")[0, 1])
ABCDresult
0XXX0
10XX0
110X0
11100
11111
838 2 $phys }
839  
840 # run(STRING or TREE, parser => CODE, interactive => 'nop' or 'dash', args => [$1 ...], arg0 => $0, opt => {e => 1, ...}):
841 # sh's status, or (undef, ERROR) if STRING is
842 # outside the subset. The parser also reads the text of eval, . and trap actions (with the aliases defined so far:
843 # parser->(TEXT, aliases => {NAME => VALUE})). interactive: what history, fc, bind, help, compopt, logout and
844 # set -o history do (B2): nothing (nop, the default; give the parser the same option) or as in dash (not found).
845 480 require Proc::ShellSpawn::Builtins;
846 482 ▶sub run {
Subroutine run: called CC=10 SCAR=24.5
Pod undocumented
847 482 ▶ my ($s, %o) = @_; my $parse = $o{parser} // default_parser(); a4();
Condition33%1/3
$o{"parser"} // default_parser()
l!l&&r!l&&!r
04820
MC/DC0%0/2
$o{"parser"} // default_parser()
$o{"parser"} default_parser()
Truth table33%1/3
A // B
A= $o{"parser"}B= default_parser()
ABresult
1X1
011
000
848 482 ▶ my $tree = ref $s ? $s : $parse->($s);
Branch: 1 branch
BranchTrueFalseTotal
ref $s ? : 0 482 482
849 482 ▶ return (undef, $tree) if ref $tree eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
if ref $tree eq "HASH" 6 476 482
850 476 my $cwd = start_pwd();
851 # dash sets OPTIND and IFS when it starts (L3)
852 my $sh = { vars => { %ENV, PWD => $cwd, OPTIND => 1, IFS => " \t\n", PPID => $Proc::Spawner::WIN ? Proc::Spawner::__win_ppid() : getppid() }, exp => { map +($_ => 1), keys %ENV, 'PWD' }, cwd => $cwd, q => 0,
853 476 ▶ parse => $parse, args => [@{$o{args} // []}], arg0 => $o{arg0}, pid => $$, opt => {%{$o{opt} // {}}}, cmd => {}, ro => {}, trap => {}, jobl => [], umask => umask,
Condition50%3/6
$o{"args"} // []
l!l
0476
$o{"opt"} // {}
l!l
0476
$o{"interactive"} // "nop"
l!l
0476
MC/DC0%0/1
$o{"args"} // []
$o{"args"}
MC/DC0%0/1
$o{"opt"} // {}
$o{"opt"}
MC/DC0%0/1
$o{"interactive"} // "nop"
$o{"interactive"}
Truth table50%1/2
A
A= $o{"args"}
Aresult
11
00
Truth table50%1/2
A
A= $o{"opt"}
Aresult
11
00
Truth table50%1/2
A
A= $o{"interactive"}
Aresult
11
00
854 476 ▶ alias => {}, hash => {}, intext => 0, interactive => $o{interactive} // 'nop' };
Branch: 1 branch
BranchTrueFalseTotal
$Proc::Spawner::WIN ? : 0 476 476
855 476 my $st;
856 476 ▶ my $c = { sh => $sh, loops => [], map => { map +($_ => is_open($_) ? own_fd($_) : undef), 0 .. 2 } };
Branch: 1 branch
BranchTrueFalseTotal
is_open($_) ? : 1428 0 1428
857 476 ▶ my $scope = []; $c->{shell} = { scope => $scope, exit => shell_exit($c, $scope, sub { $st //= shift }) };
Subroutine __ANON__: called CC=2 SCAR=7.6
Condition33%1/3
$st //= shift()
l!l&&r!l&&!r
04760
MC/DC0%0/2
$st //= shift()
$st shift()
Truth table33%1/3
A //= B
A= $stB= shift()
ABresult
1X1
011
000
858 476 ▶ $sh->{die} = sub { $st //= shift }; # kill ... $$ (Proc::ShellSpawn::Large::b_kill): the whole string ends
Subroutine __ANON__: called CC=2 SCAR=10.5
Condition0%0/3
$st //= shift()
l!l&&r!l&&!r
000
MC/DC0%0/2
$st //= shift()
$st shift()
Truth table0%0/3
A //= B
A= $stB= shift()
ABresult
1X1
011
000
859 476 local %TRAPSAVE = (); $SIGNALLED = undef; # signals the trap builtin changed: put back afterwards
860 476 { local $RUNNING = 1;
861 476 ▶ ignoring_int(sub { x_list($c, $tree, undef, $c->{shell}{exit}); loop_until(sub { defined $st }) }) }
Subroutine __ANON__: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=1 SCAR=0.0
862 476 $SIG{$_} = $TRAPSAVE{$_} for keys %TRAPSAVE;
863 476 %$c = ();
864 476 idle(1); idle_pass(); # K3 (B): background jobs move on between calls too
865 476 $st }
866  
867 480 1;
« lib/Proc/ShellSubset/Large.pm ↑ Summary lib/Proc/ShellSubset.pm »