lib/Proc/ShellSubset/Small.pm

filter: Statementstmt 99.1% 225 / 227 Branchbran 97.0% 198 / 204 Conditioncond 83.8% 119 / 142 MC/DCmcdc 73.9% 54 / 73 Subroutinesub 100% 31 / 31 Podpod 0.0% 0 / 20 totaltotal 89.9% 627 / 697 CC 159 SCAR 27.6
CC
159
Cov
95%
simple
44.8
dots
17.0
xc
12.0
CRAP 15.8
« lib/Proc/Spawner/Loop/POSIX.pm ↑ Summary lib/Proc/ShellSpawn/Large.pm »
1 package Proc::ShellSubset::Small; # Proc::ShellSubset with its options frozen (see doc/parsers/shell-subset-spec.md, section 9)
2 1 our $VERSION = '0.11';
3 1 ▶use strict; use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 # Proc::ShellSubset::Small::parse($string) returns a List, or { error => '...', pos => N, last => N, tree => List }:
6 # 'last' is the position after the last top-level ';', '&' or newline, 'tree' the part parsed so far, with
7 # { ERROR => 1 } where parsing failed (an 'exec' in the wrong place gets ERROR => 1 in its own hash; an 'exec'
8 # not checked yet when parsing failed has exec => its position, which may be 0: test the key with exists).
9 # Frozen options, each at the value that leaves the least code: no if, while, until, for, case, read (so no
10 # break, continue), no brace expansion, no ${x:-w} forms, no commands with only settings, no ~ after NAME=
11 # in arguments; ^ and $PWD accepted, no checker, an empty string accepted (an empty List), multi-digit fds
12 # accepted (as bash reads them; dash reads '10>f' as the argument 10 and a redirection).
13 #
14 # List = [ AndOr, ... ]
15 # AndOr = [ Pipeline, '&&' | '||', Pipeline, ..., '&' (only if in background) ]
16 # Pipeline = [ '!' (only if negated), Command, ... ]
17 # Command = { argv => [Word, ...], env => [NAME, Word, ...], redir => [Redir, ...], exec => 1 }
18 # | { sub => List, redir => [...] } | { group => List, redir => [...] } | { cd => Word | undef }
19 # (keys only when non-empty; argv->[0] is a plain string; cd alone has cd => undef)
20 # Redir = [ fd, op, Word ] (for <& and >&: [ fd, op, 'digit or -' ])
21 # Word = 'literal text' | [ Part, ... ]
22 # Part = 'literal text' | [ '$', NAME or '?' or '!' ] | [ '$((', 'expr' ] | [ '$(', List ]
23 # | the same three with '"' in front ('"$' ...) when inside double quotes
24 # | [ '~', 'user' or '' ] | [ '*', 'pattern text' ]
25  
26 1 our ($M, @OPEN, $ATT, $LAST); # position map of a backquote's inside; arrays being filled (for the
27 # partial tree); how many of them are in the tree; end of the last top-level chain
28 1 my %KW = map +($_ => 1), qw(if then else elif fi case esac for while until do done in [[ ]] function select coproc !);
29 1 my %BI = map +($_ => 1), qw(. break continue eval export readonly return set shift times trap unset alias
30 unalias read wait umask ulimit jobs fg bg command getopts hash type fc chdir local source let declare
31 typeset shopt enable builtin caller dirs pushd popd disown mapfile readarray suspend logout help
32 history bind compgen complete compopt);
33 1 my %SH = map +($_ => 1), qw(IFS PS1 PS2 PS4 OPTIND PPID OLDPWD LINENO _ BASH BASHOPTS BASHPID DIRSTACK
34 EPOCHREALTIME EPOCHSECONDS EUID FUNCNAME GROUPS HISTCMD HOSTTYPE MACHTYPE OPTERR OSTYPE PIPESTATUS
35 POSIXLY_CORRECT RANDOM SECONDS SHELLOPTS SHLVL SRANDOM UID);
36 1 my $NM = qr/[A-Za-z_][A-Za-z0-9_]*/;
37 1 my $END = qr/(?=[ \t\n;&|()<>]|\z)/;
38 1 my $B = qr/(?:[ \t]|\\\n|#.*)*+/; # blanks, line continuations, a comment
39 1 my $BN = qr/(?:[ \t\n]|\\\n|#.*)*+/; # the same, and newlines
40 1 my $PIECE = qr/\G(?: '(?<sq>[^']*)' | (?<dq>") | \\(?<bs>.) | (?<ex>[\$`]) | (?<gl>[*?]) | (?<br>\[)
41 | (?<ti>~) | (?<lit>(?:\{\}|[^ \t\n;&|()<>'"\\\$`*?\[{}~\x00-\x1f\x7f])+) | (?<bad>.) )/sx; # {} is literal (C2)
42 1 my $ARITH = qr{(?(DEFINE) # the expression grammar of $((...))
43 (?<w> [ \t\n]* )
44 (?<num> (?: 0[xX][0-9a-fA-F]+ | 0[0-7]* | [1-9][0-9]* ) (?![0-9A-Za-z_]) )
45 (?<atom> (?&w) (?: [-+!~] (?&w) )* (?: (?&num) | \$? [A-Za-z_][A-Za-z0-9_]* | \$\{[A-Za-z_][A-Za-z0-9_]*\} | \$[?!] | \$\{[?!]\}
46 | \( (?&e) (?&w) \) ) ) # $NAME, ${NAME}: substituted as text first (C9)
47 (?<op> (?&w) (?: << | >> | <= | >= | == | != | && | \|\| | [-+*/%<>&^|] ) )
48 (?<e> (?&atom) (?: (?&op) (?&atom) )* (?: (?&w) \? (?&e) (?&w) : (?&e) )? ) )}x;
49  
50 1 my %EX = ('$' => \&dollar, '`' => \&bq); # the expansion a $ or ` starts: ($q, $p) -> Part
51  
52 1992 ▶sub P { my $p = shift; $M ? $$M[$p] // $$M[-1] : $p } # position in the original
Subroutine P: called CC=3 SCAR=11.7
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
$Proc::ShellSubset::Small::M ? : 73 1919 1992
Condition33%1/3
$Proc::ShellSubset::Small::M->[$p] // $Proc::ShellSubset::Small::M->[-1]
l!l&&r!l&&!r
7300
MC/DC0%0/2
$Proc::ShellSubset::Small::M->[$p] // $Proc::ShellSubset::Small::M->[-1]
$Proc::ShellSubset::Small::M->[$p] $Proc::ShellSubset::Small::M->[-1]
Truth table33%1/3
A // B
A= $Proc::ShellSubset::Small::M->[$p]B= $Proc::ShellSubset::Small::M->[-1]
ABresult
1X1
011
000
53 831 ▶sub E { push @{$OPEN[$ATT // -1]}, { ERROR => 1 } if @OPEN; die [shift, P(shift)] }
Subroutine E: called CC=3 SCAR=11.0
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
if @Proc::ShellSubset::Small::OPEN 824 7 831
Condition100%2/2
$Proc::ShellSubset::Small::ATT // -1
l!l
462362
MC/DC100%1/1
$Proc::ShellSubset::Small::ATT // -1
$Proc::ShellSubset::Small::ATT
Truth table100%2/2
A
A= $Proc::ShellSubset::Small::ATT
Aresult
11
00
54 64 ▶sub U { /\G$B/gc; E(/\G(.)/s ? 'unexpected ' . ($1 eq "\n" ? 'newline' : "'$1'") : 'unexpected end', pos) }
Subroutine U: called CC=3 SCAR=11.1
Pod undocumented
Branch: 2 branches
BranchTrueFalseTotal
/\G(.)/s ? : 60 4 64
$1 eq "\n" ? : 0 60 60
55 1873 ▶sub parse {
Subroutine parse: called CC=5 SCAR=16.1
Pod undocumented
56 1873 my $s = shift; local ($M, @OPEN, $ATT); local $LAST = 0; my @l;
57 1873 my $t = eval {
58 1873 local $_ = $s;
59 1873 ▶ E('NUL character', $-[0]) if /\0/;
Branch: 1 branch
BranchTrueFalseTotal
if /\0/ 1 1872 1873
60 1872 ▶ E(q{starts with - or +: sh would read it as options}, $-[1]) if /\A[ \t\n\r\f\cK]*([-+])/; # Perl skips leading white space, then runs sh -c STRING (U1)
Branch: 1 branch
BranchTrueFalseTotal
if /\A[ \t\n\r\f\cK]*([-+])/ 6 1866 1872
61 1866 shell('', \@l) };
62 1873 ▶ $t // (ref $@ eq 'ARRAY' ? { error => $@->[0], pos => $@->[1], last => $LAST, tree => \@l } : die $@) }
Branch: 1 branch
BranchTrueFalseTotal
ref $@ eq 'ARRAY' ? : 848 0 848
Condition100%2/2
$t // (ref $@ eq "ARRAY" ? {"error", $@->[0], "pos", $@->[1], "last", $Proc::ShellSubset::Small::LAST, "tree", \@l} : die($@))
l!l
1025848
MC/DC100%1/1
$t // (ref $@ eq "ARRAY" ? {"error", $@->[0], "pos", $@->[1], "last", $Proc::ShellSubset::Small::LAST, "tree", \@l} : die($@))
$t
Truth table100%2/2
A
A= $t
Aresult
11
00
63  
64 2252 ▶sub list { # up to ')' (subshell, $()), '}' (group) or the end ('')
Subroutine list: called CC=9 SCAR=22.0
Pod undocumented
65 2252 ▶ my ($t, $l) = @_; local $OPEN[@OPEN] = $l; my $top = !$t && !$M; # fills @$l in place
Condition100%3/3
$t || $Proc::ShellSubset::Small::M
l!l&&r!l&&!r
292941866
MC/DC100%2/2
$t || $Proc::ShellSubset::Small::M
$t $Proc::ShellSubset::Small::M
Truth table100%3/3
A || B
A= $tB= $Proc::ShellSubset::Small::M
ABresult
1X1
011
000
66 2252 ▶ my $e = $t eq ')' ? qr/\G(?=\))/ : $t ? qr/\G(?=\}$END)/ : qr/\G\z/;
Branch: 2 branches
BranchTrueFalseTotal
$t eq ')' ? : 236 2016 2252
$t ? : 56 1960 2016
67 2252 ▶ while (/\G$BN/gc, !/$e/) { # (zero-length /gc matches can't repeat at one place: test with plain //)
Branch: 1 branch
BranchTrueFalseTotal
if (/\G$BN/cg, !/$e/) 2408 115 2523
68 2408 push @$l, my $c = []; andor($c);
69 1588 ▶ if (/\G$B&(?!&)/gc) { push @$c, '&' }
Branch: 2 branches
BranchTrueFalseTotal
if (/\G$B&(?!&)/cg) { } 51 1537 1588
elsif (not /\G$B(?:;(?!;)|\n)/cg) { } 1317 220 1537
70 1317 ▶ elsif (!/\G$B(?:;(?!;)|\n)/gc) { /\G$B/gc, /$e/ ? last : U() }
Branch: 1 branch
BranchTrueFalseTotal
/$e/ ? : 1253 64 1317
71 271 ▶ $LAST = pos if $top }
Branch: 1 branch
BranchTrueFalseTotal
if $top 157 114 271
72 1368 $l }
73  
74 2196 ▶sub shell { # a list that runs in a shell of its own: exec is checked at its end
Subroutine shell: called CC=1 SCAR=0.0
Pod undocumented
75 2196 my $l = list(@_); xc($l, 1); $l }
76  
77 2408 ▶sub andor {
Subroutine andor: called CC=3 SCAR=11.0
Pod undocumented
78 2408 my $ao = shift; local $OPEN[@OPEN] = $ao;
79 2408 ▶ do { push @$ao, my $p = []; pipeline($p) } while /\G$B(&&|\|\|)$BN/gc && push @$ao, $1 }
Branch: 1 branch
BranchTrueFalseTotal
/\G$B(&&|\|\|)$BN/cg and push @$ao, $1 and do { do { push @$ao, my $p = []; pipeline($p) } } 159 1588 1747
Condition66%2/3
/\G$B(&&|\|\|)$BN/cg and push @$ao, $1
!ll&&!rl&&r
15880159
MC/DC50%1/2
/\G$B(&&|\|\|)$BN/cg and push @$ao, $1
/\G$B(&&|\|\|)$BN/cg push @$ao, $1
Truth table66%2/3
A and B
A= /\G$B(&&|\|\|)$BN/cgB= push @$ao, $1
ABresult
0X0
100
111
80  
81 2567 ▶sub pipeline {
Subroutine pipeline: called CC=5 SCAR=16.1
Pod undocumented
82 2567 my $p = shift; local $OPEN[@OPEN] = $p;
83 2567 ▶ push @$p, '!' if /\G!(?=[ \t])$B/gc;
Branch: 1 branch
BranchTrueFalseTotal
if /\G!(?=[ \t])$B/cg 29 2538 2567
84 2567 ▶ E("'! !'", pos) if @$p && /\G!$END/;
Branch: 1 branch
BranchTrueFalseTotal
if @$p and /\G!$END/ 5 2562 2567
Condition100%3/3
@$p and /\G!$END/
!ll&&!rl&&r
2538245
MC/DC100%2/2
@$p and /\G!$END/
@$p /\G!$END/
Truth table100%3/3
A and B
A= @$pB= /\G!$END/
ABresult
0X0
100
111
85 2562 ▶ do { command($p) } while /\G$B\|(?![|&])$BN/gc }
Branch: 1 branch
BranchTrueFalseTotal
/\G$B\|(?![|&])$BN/cg and do { do { command($p) } } 544 1747 2291
86  
87 3106 ▶sub command { # pushes the command onto the pipeline @{$_[0]}
Subroutine command: called CC=8 SCAR=20.8
Pod undocumented
88 3106 my $pl = shift; my $p = pos; my $c;
89 3106 ▶ E("'((' at the start of a command", $p) if /\G\(\(/;
Branch: 1 branch
BranchTrueFalseTotal
if /\G\(\(/ 5 3101 3106
90 3101 ▶ if (/\G\(/gc) {
Branch: 2 branches
BranchTrueFalseTotal
if (/\G\(/cg) { } 71 3030 3101
elsif (/\G\{(?=[ \t\n])/cg) { } 56 2974 3030
91 71 push @$pl, $c = { sub => my $l = [] };
92 71 ▶ shell(')', $l); /\G\)/gc; @$l or E('empty subshell', $p) }
Branch: 1 branch
BranchTrueFalseTotal
@$l or E("empty subshell", $p) 66 3 69
93 elsif (/\G\{(?=[ \t\n])/gc) {
94 56 push @$pl, $c = { group => my $l = [] };
95 56 ▶ list('}', $l); /\G\}/gc; @$l or E('empty group', $p) } # xc: by the parent
Branch: 1 branch
BranchTrueFalseTotal
@$l or E("empty group", $p) 49 1 50
96 2974 else { return simple($pl) }
97 115 ▶ my ($r, @r); push @r, $r while /\G$B/gc, $r = redir();
Branch: 1 branch
BranchTrueFalseTotal
/\G$B/cg, $r = redir() and do { push @r, $r } 34 115 149
98 115 ▶ $c->{redir} = \@r if @r;
Branch: 1 branch
BranchTrueFalseTotal
if @r 24 91 115
99 115 $c }
100  
101 7490 ▶sub redir { # a redirection, or nothing (pos unchanged) if none starts here
Subroutine redir: called CC=9 SCAR=22.0
Pod undocumented
102 7490 my $p = pos;
103 7490 ▶ E('process substitution (bash)', $p) if /\G[<>]\(/;
Branch: 1 branch
BranchTrueFalseTotal
if /\G[<>]\(/ 13 7477 7490
104 7477 ▶ /\G([0-9]*)(<<|>>|<>|>\||<&|>&|<|>)$B/gc or return;
Branch: 1 branch
BranchTrueFalseTotal
/\G([0-9]*)(<<|>>|<>|>\||<&|>&|<|>)$B/cg or return 480 6997 7477
105 480 ▶ E('target followed by a redirection operator (dash: a descriptor)', pos) if /\G[0-9]+[<>]/; # x >&2>f (U4)
Branch: 1 branch
BranchTrueFalseTotal
if /\G[0-9]+[<>]/ 6 474 480
106 474 my ($n, $op) = ($1, $2);
107 474 ▶ E('here-document', $p) if $op eq '<<';
Branch: 1 branch
BranchTrueFalseTotal
if $op eq "<<" 5 469 474
108 469 ▶ my $fd = length $n ? 0 + $n : $op =~ /^</ ? 0 : 1;
Branch: 2 branches
BranchTrueFalseTotal
length $n ? : 111 358 469
$op =~ /^</ ? : 91 267 358
109 469 ▶ return [$fd, $op, /\G([0-9-])$END/gc ? $1 : E("'$op' takes one digit or '-'", pos)] if $op =~ /&/;
Branch: 2 branches
BranchTrueFalseTotal
if $op =~ /&/ 79 390 469
/\G([0-9-])$END/cg ? : 72 7 79
110 390 [$fd, $op, word('r')] }
111  
112 2974 ▶sub simple {
Subroutine simple: called CC=40 SCAR=38.0
Pod undocumented
113 2974 my $pl = shift; my (@env, @av, @ap, @r, @np, $kw); my $p0 = pos; # @ap: the position of each word of @av
114 2974 push @$pl, my $c = { argv => \@av }; local $OPEN[@OPEN] = \@av;
115 2974 ▶ while (/\G$B/gc, !/\G(?=[;&|()\n]|\z)/) {
Branch: 1 branch
BranchTrueFalseTotal
if (/\G$B/cg, !/\G(?=[;&|()\n]|\z)/) 7341 2434 9775
116 7341 my $p = pos;
117 7341 ▶ if (my $r = redir()) { push @r, $r }
Branch: 2 branches
BranchTrueFalseTotal
if (my $r = redir()) { } 379 6882 7261
elsif (not @av and /\G($NM)(\+?)=/cg) { } 184 6698 6882
118 184 ▶ elsif (!@av and /\G($NM)(\+?)=/gc) { E("'$1+='", $p) if $2; push @np, ["$1", $p]; push @env, "$1", word('e') } # "$1", not $1: word() matches again
Branch: 1 branch
BranchTrueFalseTotal
if $2 6 178 184
Condition100%3/3
not @av and /\G($NM)(\+?)=/cg
!ll&&!rl&&r
38892809184
MC/DC100%2/2
not @av and /\G($NM)(\+?)=/cg
not @av /\G($NM)(\+?)=/cg
Truth table100%3/3
not(A) and B
A= not @avB= /\G($NM)(\+?)=/cg
ABresult
0X0
100
111
119 6698 ▶ else { push @av, word('a'); push @ap, $p; $kw //= substr $_, $p, pos() - $p } }
Condition66%2/3
$kw //= substr($_, $p, pos($_) - $p)
l!l&&r!l&&!r
349927820
MC/DC0%0/2
$kw //= substr($_, $p, pos($_) - $p)
$kw substr($_, $p, pos($_) - $p)
Truth table66%2/3
A //= B
A= $kwB= substr($_, $p, pos($_) - $p)
ABresult
1X1
011
000
120 2434 name(@$_) for grep $$_[0] ne 'IFS', @np; # bash refuses its own names (UID=5 cmd) (U5)
121 2430 ▶ @av or E(@env || @r ? 'no command name' : 'missing command', $p0);
Branch: 2 branches
BranchTrueFalseTotal
@av or E(@env || @r ? "no command name" : "missing command", $p0) 2326 104 2430
@env || @r ? : 94 10 104
Condition100%3/3
@env or @r
l!l&&r!l&&!r
702410
MC/DC100%2/2
@env or @r
@env @r
Truth table100%3/3
A or B
A= @envB= @r
ABresult
1X1
011
000
122 2326 ▶ E('command name not literal', $ap[0]) if ref $av[0];
Branch: 1 branch
BranchTrueFalseTotal
if ref $av[0] 7 2319 2326
123 2319 my $n = $av[0];
124 2319 ▶ if ($n eq 'exec') {
Branch: 1 branch
BranchTrueFalseTotal
if ($n eq 'exec') { } 61 2258 2319
125 61 shift @av; my $xp = shift @ap;
126 61 ▶ @av or E("'exec' without a command", $p0);
Branch: 1 branch
BranchTrueFalseTotal
@av or E("'exec' without a command", $p0) 57 4 61
127 57 ▶ E("unsupported 'exec' form", $ap[0]) if ref($av[0]) || $av[0] =~ /^-|^(?:cd|:|exit)\z/;
Branch: 1 branch
BranchTrueFalseTotal
if ref $av[0] or $av[0] =~ /^-|^(?:cd|:|exit)\z/ 6 51 57
Condition66%2/3
ref $av[0] or $av[0] =~ /^-|^(?:cd|:|exit)\z/
l!l&&r!l&&!r
0651
MC/DC50%1/2
ref $av[0] or $av[0] =~ /^-|^(?:cd|:|exit)\z/
ref $av[0] $av[0] =~ /^-|^(?:cd|:|exit)\z/
Truth table66%2/3
A or B
A= ref $av[0]B= $av[0] =~ /^-|^(?:cd|:|exit)\z/
ABresult
1X1
011
000
128 51 $c->{exec} = P($xp) } # its position, until xc() has checked it and made it 1
129 else {
130 2258 ▶ E("keyword '$n'", $ap[0]) if $KW{$n} && $kw eq $n;
Branch: 1 branch
BranchTrueFalseTotal
if $KW{$n} and $kw eq $n 80 2178 2258
Condition100%3/3
$KW{$n} and $kw eq $n
!ll&&!rl&&r
2170880
MC/DC100%2/2
$KW{$n} and $kw eq $n
$KW{$n} $kw eq $n
Truth table100%3/3
A and B
A= $KW{$n}B= $kw eq $n
ABresult
0X0
100
111
131 2178 ▶ E("builtin '$n'", $ap[0]) if $BI{$n};
Branch: 1 branch
BranchTrueFalseTotal
if $BI{$n} 27 2151 2178
132 2151 ▶ if ($n eq 'cd') {
Branch: 1 branch
BranchTrueFalseTotal
if ($n eq "cd") 48 2103 2151
133 48 ▶ @av <= 2 && !@env && !@r && !defined $ENV{CDPATH} && ($av[1] // '') !~ /^-/
Branch: 1 branch
BranchTrueFalseTotal
@av <= 2 and not @env and not @r and not defined $ENV{"CDPATH"} and not +($av[1] // "") =~ /^-/ or E("unsupported cd form", $ap[0]) 36 12 48
Condition85%12/14
@av <= 2 and not @env and not @r and not defined $ENV{"CDPATH"} and not +($av[1] // "") =~ /^-/
!ll&&!rl&&r
9336
@av <= 2 and not @env and not @r and not defined $ENV{"CDPATH"}
!ll&&!rl&&r
9039
@av <= 2 and not @env and not @r
!ll&&!rl&&r
7239
@av <= 2 and not @env
!ll&&!rl&&r
7041
$av[1] // ""
l!l
363
MC/DC60%3/5
@av <= 2 and not @env and not @r and not defined $ENV{"CDPATH"} and not +($av[1] // "") =~ /^-/
@av <= 2 not @env not @r not defined $ENV{"CDPATH"} $av[1]
Truth table66%4/6
A and not(B) and not(C) and not(D) and not(E)
A= @av <= 2B= not @envC= not @rD= not defined $ENV{"CDPATH"}E= $av[1]
ABCDEresult
0XXXX0
10XXX0
110XX0
1110X0
111110
111101
134 or E('unsupported cd form', $ap[0]); # C8: the argument may have expansions; cd alone goes home
135 E('cd to $HOME without HOME', $ap[0]) if !defined $ENV{HOME}
136 0 ▶ && (@av == 1 || ref $av[1] && grep { ref && $$_[0] =~ /^\$/ } @{$av[1]});
Branch: 1 branch
BranchTrueFalseTotal
if not defined $ENV{"HOME"} and @av == 1 || ref $av[1] && grep({ref $_ and $_->[0] =~ /^\$/;} @{$av[1];}) 0 36 36
Condition8%1/12
not defined $ENV{"HOME"} and @av == 1 || ref $av[1] && grep({ref $_ and $_->[0] =~ /^\$/;} @{$av[1];})
!ll&&!rl&&r
3600
@av == 1 or ref $av[1] and grep {ref $_ and $_->[0] =~ /^\$/;} @{$av[1];}
l!l&&r!l&&!r
000
ref $av[1] and grep {ref $_ and $_->[0] =~ /^\$/;} @{$av[1];}
!ll&&!rl&&r
000
ref $_ && $_->[0] =~ /^\$/
!ll&&!rl&&r
000
MC/DC0%0/4
not defined $ENV{"HOME"} and @av == 1 || ref $av[1] && grep({ref $_ and $_->[0] =~ /^\$/;} @{$av[1];})
not defined $ENV{"HOME"} @av == 1 ref $av[1] grep {ref $_ and $_->[0] =~ /^\$/;} @{$av[1];}
MC/DC0%0/2
ref $_ && $_->[0] =~ /^\$/
ref $_ $_->[0] =~ /^\$/
Truth table20%1/5
not(A) and B or C and D
A= not defined $ENV{"HOME"}B= @av == 1C= ref $av[1]D= grep {ref $_ and $_->[0] =~ /^\$/;} @{$av[1];}
ABCDresult
0XXX0
100X0
10100
11XX1
10111
Truth table0%0/3
A && B
A= ref $_B= $_->[0] =~ /^\$/
ABresult
0X0
100
111
137 36 return %$c = (cd => $av[1]) }
138 2103 ▶ if ($n =~ /^(?::|exit)\z/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($n =~ /^(?::|exit)\z/) 60 2043 2103
139 60 ▶ E("settings before '$n'", $p0) if @env;
Branch: 1 branch
BranchTrueFalseTotal
if @env 4 56 60
140 56 ▶ E('unsupported exit status', $ap[0]) if $n eq 'exit' && (@av > 2 || @av == 2
Branch: 1 branch
BranchTrueFalseTotal
if $n eq "exit" and @av > 2 || @av == 2 && (!($av[1] =~ /^(?:0|[1-9][0-9]{0,2})\z/) || $av[1] > 255) 10 46 56
Condition91%11/12
$n eq "exit" and @av > 2 || @av == 2 && (!($av[1] =~ /^(?:0|[1-9][0-9]{0,2})\z/) || $av[1] > 255)
!ll&&!rl&&r
291710
@av > 2 or @av == 2 and !($av[1] =~ /^(?:0|[1-9][0-9]{0,2})\z/) || $av[1] > 255
l!l&&r!l&&!r
01017
@av == 2 and !($av[1] =~ /^(?:0|[1-9][0-9]{0,2})\z/) || $av[1] > 255
!ll&&!rl&&r
61110
not $av[1] =~ /^(?:0|[1-9][0-9]{0,2})\z/ or $av[1] > 255
l!l&&r!l&&!r
7311
MC/DC80%4/5
$n eq "exit" and @av > 2 || @av == 2 && (!($av[1] =~ /^(?:0|[1-9][0-9]{0,2})\z/) || $av[1] > 255)
$n eq "exit" @av > 2 @av == 2 not $av[1] =~ /^(?:0|[1-9][0-9]{0,2})\z/ $av[1] > 255
Truth table83%5/6
A and B or C and not(D) or E
A= $n eq "exit"B= @av > 2C= @av == 2D= not $av[1] =~ /^(?:0|[1-9][0-9]{0,2})\z/E= $av[1] > 255
ABCDEresult
0XXXX0
100XX0
101000
11XXX1
1011X1
101011
141 && ($av[1] !~ /^(?:0|[1-9][0-9]{0,2})\z/ || $av[1] > 255)) } }
142 2140 ▶ $c->{env} = \@env if @env; $c->{redir} = \@r if @r;
Branch: 2 branches
BranchTrueFalseTotal
if @env 48 2092 2140
if @r 255 1885 2140
143 2140 $c }
144  
145 7266 ▶sub word { # $x: a(rgument), e(nv value), r(edirection target)
Subroutine word: called CC=11 SCAR=24.0
Pod undocumented
146 7266 ▶ my $x = shift; my $p0 = pos; my @s; local $ATT = $ATT // $#OPEN;
Condition100%2/2
$Proc::ShellSubset::Small::ATT // $#Proc::ShellSubset::Small::OPEN
l!l
5786688
MC/DC100%1/1
$Proc::ShellSubset::Small::ATT // $#Proc::ShellSubset::Small::OPEN
$Proc::ShellSubset::Small::ATT
Truth table100%2/2
A
A= $Proc::ShellSubset::Small::ATT
Aresult
11
00
147 7266 ▶ return '[' if $x eq 'a' and /\G\[$END/gc; # '[' alone: literal
Branch: 1 branch
BranchTrueFalseTotal
if $x eq "a" and /\G\[$END/cg 80 7186 7266
Condition100%3/3
$x eq "a" and /\G\[$END/cg
!ll&&!rl&&r
568661880
MC/DC100%2/2
$x eq "a" and /\G\[$END/cg
$x eq "a" /\G\[$END/cg
Truth table100%3/3
A and B
A= $x eq "a"B= /\G\[$END/cg
ABresult
0X0
100
111
148 7186 ▶ my $te = $x eq 'e' ? qr{(?=[/:])|$END} : qr{(?=/)|$END}; # ~ also before ':' in a setting
Branch: 1 branch
BranchTrueFalseTotal
$x eq 'e' ? : 178 7008 7186
149 7186 my $p;
150 my %do = (
151 144 ▶ sq => sub { push @s, [q => shift] },
Subroutine __ANON__: called CC=1 SCAR=0.0
152 409 ▶ dq => sub { push @s, [q => '']; dq(\@s, $p) },
Subroutine __ANON__: called CC=1 SCAR=0.0
153 101 ▶ bs => sub { $_[0] eq "\n" ? E('backslash-newline in a word', $p) : push @s, [q => shift] },
Subroutine __ANON__: called CC=2 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
$_[0] eq "\n" ? : 6 95 101
154 671 ▶ ex => sub { push @s, [x => $EX{$_[0]}->('', $p)] }, # also in redirection targets (Q1)
Subroutine __ANON__: called CC=1 SCAR=0.0
155 170 ▶ gl => sub { E('pattern in a redirection target', $p) if $x eq 'r'; push @s, [$x eq 'e' ? 'u' : 'g', shift] },
Subroutine __ANON__: called CC=3 SCAR=11.0
Branch: 2 branches
BranchTrueFalseTotal
if $x eq "r" 7 163 170
$x eq 'e' ? : 2 161 163
156 44 ▶ br => sub {
Subroutine __ANON__: called CC=5 SCAR=16.5
157 44 ▶ E('pattern in a redirection target', $p) if $x eq 'r';
Branch: 1 branch
BranchTrueFalseTotal
if $x eq "r" 0 44 44
158 44 ▶ push @s, $x eq 'e' ? [u => '['] : /\G(!?\]?[^\] \t\n;&|()<>'"\\\$`{}^\/,]*\])/gc ? [g => "[$1"]
Branch: 3 branches
BranchTrueFalseTotal
$x eq 'e' ? : 0 44 44
m(\G(!?\]?[^\] \t\n;&|()<>'"\\\$`{}^/,]*\]))cg ? : 20 24 44
/\G(?:\\.|'[^']*'|"(?:[^"\\]|\\.)*"|[^ \t\n;&|()<>\\'"])*?\]/s ? : 12 12 24
159 : /\G(?:\\.|'[^']*'|"(?:[^"\\]|\\.)*"|[^ \t\n;&|()<>\\'"])*?\]/s # a ] later in the word, past quotes
160 ? E('bracket expression with a quote, expansion or slash', $p) : [g => '['] },
161 122 ▶ ti => sub { # ~ at the start of the word, or after an unquoted ':' in a setting, is an expansion
Subroutine __ANON__: called CC=8 SCAR=20.9
162 122 ▶ return push @s, [u => '~'] if @s && !($x eq 'e' && $s[-1][0] eq 'u' && $s[-1][1] =~ /:\z/);
Branch: 1 branch
BranchTrueFalseTotal
if @s and not $x eq "e" && $s[-1][0] eq "u" && $s[-1][1] =~ /:\z/ 25 97 122
Condition100%9/9
@s and not $x eq "e" && $s[-1][0] eq "u" && $s[-1][1] =~ /:\z/
!ll&&!rl&&r
89825
$x eq 'e' && $s[-1][0] eq 'u' && $s[-1][1] =~ /:\z/
!ll&&!rl&&r
2418
$x eq "e" and $s[-1][0] eq "u"
!ll&&!rl&&r
2229
MC/DC100%4/4
@s and not $x eq "e" && $s[-1][0] eq "u" && $s[-1][1] =~ /:\z/
@s $x eq "e" $s[-1][0] eq "u" $s[-1][1] =~ /:\z/
Truth table100%5/5
A and not(B and C && D)
A= @sB= $x eq "e"C= $s[-1][0] eq "u"D= $s[-1][1] =~ /:\z/
ABCDresult
0XXX0
11110
10XX1
110X1
11101
163 97 ▶ /\G((?:[A-Za-z0-9._][A-Za-z0-9._-]*)?)$te/gc or E('unsupported ~ form', $p);
Branch: 1 branch
BranchTrueFalseTotal
/\G((?:[A-Za-z0-9._][A-Za-z0-9._-]*)?)$te/cg or E("unsupported ~ form", $p) 88 9 97
164 88 ▶ E('~ without HOME', $p) if $1 eq '' && !defined $ENV{HOME};
Branch: 1 branch
BranchTrueFalseTotal
if $1 eq "" and not defined $ENV{"HOME"} 0 88 88
Condition66%2/3
$1 eq "" and not defined $ENV{"HOME"}
!ll&&!rl&&r
11770
MC/DC0%0/2
$1 eq "" and not defined $ENV{"HOME"}
$1 eq "" not defined $ENV{"HOME"}
Truth table66%2/3
A and not(B)
A= $1 eq ""B= not defined $ENV{"HOME"}
ABresult
0X0
100
111
165 88 push @s, [x => ['~', $1]] },
166 5955 ▶ lit => sub { push @s, [u => shift] },
Subroutine __ANON__: called CC=1 SCAR=0.0
167 109 ▶ bad => sub { E({"'" => 'unterminated quote', '\\' => 'final backslash', '{' => "unquoted '{'", '}' => "unquoted '}'"}->{$_[0]}
Subroutine __ANON__: called CC=2 SCAR=6.9
Condition100%2/2
{"'", "unterminated quote", "\\", "final backslash", "{", "unquoted '{'", "}", "unquoted '}'"}->{$_[0]} // sprintf("control character \\x%02x", ord shift())
l!l
1063
MC/DC100%1/1
{"'", "unterminated quote", "\\", "final backslash", "{", "unquoted '{'", "}", "unquoted '}'"}->{$_[0]} // sprintf("control character \\x%02x", ord shift())
{"'", "unterminated quote", "\\", "final backslash", "{", "unquoted '{'", "}", "unquoted '}'"}->{$_[0]}
Truth table100%2/2
A
A= {"'", "unterminated quote", "\\", "final backslash", "{", "unquoted '{'", "}", "unquoted '}'"}->{$_[0]}
Aresult
11
00
168 7186 // sprintf('control character \\x%02x', ord shift), $p) });
169 7186 ▶ until (/\G$END/) { $p = pos; /$PIECE/gc; my ($k, $v) = %+; $do{$k}($v) }
Branch: 1 branch
BranchTrueFalseTotal
unless (/\G$END/) 7725 6727 14452
170 6727 ▶ @s or $x eq 'e' or E('missing word', $p0);
Branch: 1 branch
BranchTrueFalseTotal
@s or $x eq "e" or E("missing word", $p0) 6695 32 6727
Condition100%3/3
@s or $x eq "e"
l!l&&r!l&&!r
66801532
MC/DC100%2/2
@s or $x eq "e"
@s $x eq "e"
Truth table100%3/3
A or B
A= @sB= $x eq "e"
ABresult
1X1
011
000
171 6695 my $k = join '', map $$_[0], @s; my @v; # kinds: u(nquoted) q(uoted) g(lob char) x(pansion)
172 6695 ▶ push @v, defined $1 ? ['*', join '', map $$_[1], splice @s, 0, length $1] : (shift @s)->[1]
Branch: 2 branches
BranchTrueFalseTotal
$k =~ /([ug]*g[ug]*)|./g and do { push @v, defined $1 ? ["*", join("", map($_->[1], splice(@s, 0, length $1)))] : shift(@s)->[1] } 7636 6695 14331
defined $1 ? : 163 7473 7636
173 while $k =~ /([ug]*g[ug]*)|./g; # unquoted text next to a pattern character joins it
174 6695 ▶ dots(@v) and E("pattern that may match '.' or '..'", $p0); # dash: yes, bash 5.2: no (U2)
Branch: 1 branch
BranchTrueFalseTotal
dots(@v) and E("pattern that may match '.' or '..'", $p0) 12 6683 6695
175 6683 mkword(@v) }
176  
177 6695 ▶sub dots { # can a pattern in these Parts match a whole file name component '.' or '..'? (U2)
Subroutine dots: called CC=17 SCAR=28.3
Pod undocumented
178 6695 my ($re, $g) = ('', 0); # the component so far as a regex (only the character '.' matters); has it a pattern?
179 6695 for my $x (@_, '/') { # literal text and patterns, split at '/'; an expansion is taken to match no '.'
180 14325 ▶ for (ref $x ? $$x[0] eq '*' ? map [g => $_], split m{(/)}, $$x[1] : [x => ''] : map [l => $_], split m{(/)}, $x) {
Branch: 2 branches
BranchTrueFalseTotal
ref $x ? : 831 13494 14325
$x->[0] eq '*' ? : 163 668 831
181 22011 my ($k, $v) = @$_;
182 22011 ▶ if ($v eq '/') { return 1 if $g && $re =~ /^\\\./ && grep /^$re\z/, '.', '..'; ($re, $g) = ('', 0) } # only a written '.' matches a leading one
Branch: 4 branches
BranchTrueFalseTotal
if ($v eq '/') { } 7419 14592 22011
elsif ($k eq 'l') { } 13705 887 14592
elsif ($k eq 'x') { } 668 219 887
if $g and $re =~ /^\\\./ and grep /^$re\z/, ".", ".." 12 7407 7419
Condition100%6/6
$g and $re =~ /^\\\./ and grep /^$re\z/, ".", ".."
!ll&&!rl&&r
73911612
$g and $re =~ /^\\\./
!ll&&!rl&&r
726013128
MC/DC100%3/3
$g and $re =~ /^\\\./ and grep /^$re\z/, ".", ".."
$g $re =~ /^\\\./ grep /^$re\z/, ".", ".."
Truth table100%4/4
A and B and C
A= $gB= $re =~ /^\\\./C= grep /^$re\z/, ".", ".."
ABCresult
0XX0
10X0
1100
1111
183 13705 elsif ($k eq 'l') { $re .= quotemeta $v }
184 668 elsif ($k eq 'x') { $re .= '(?!)' }
185 219 ▶ else { $g ||= $v =~ /[*?[]/; $re .= $v =~ s{\[(!?)(\]?[^\]]*)\]|([*?])|(.)}{ # a bracket expression: can it match '.'?
Condition100%3/3
$g ||= $v =~ /[*?[]/
l!l&&r!l&&!r
615954
MC/DC100%2/2
$g ||= $v =~ /[*?[]/
$g $v =~ /[*?[]/
Truth table100%3/3
A ||= B
A= $gB= $v =~ /[*?[]/
ABresult
1X1
011
000
186 742 ▶ defined $2 ? (($1 ? $2 !~ /\./ : $2 =~ /[.\-]|\[:/) ? q{[.]} : q{(?!)}) : defined $3 ? ($3 eq '*' ? '.*' : '.') : quotemeta $4}gesr } } }
Branch: 5 branches
BranchTrueFalseTotal
defined $2 ? : 18 724 742
($1 ? !($2 =~ /\./) : $2 =~ /[.\-]|\[:/) ? : 10 8 18
$1 ? : 4 14 18
defined $3 ? : 159 565 724
$3 eq '*' ? : 145 14 159
187 6683 0 }
188  
189 6683 ▶sub mkword { # a Word from Parts: adjacent strings joined, a lone string bare, nothing ''
Subroutine mkword: called CC=8 SCAR=20.8
Pod undocumented
190 6683 ▶ my @w; !ref && @w && !ref $w[-1] ? $w[-1] .= $_ : push @w, $_ for @_;
Branch: 1 branch
BranchTrueFalseTotal
!ref($_) && @w && !ref($w[-1]) ? : 527 7083 7610
Condition100%6/6
not ref $_ and @w and not ref $w[-1]
!ll&&!rl&&r
6931152527
not ref $_ and @w
!ll&&!rl&&r
8156116679
MC/DC100%3/3
not ref $_ and @w and not ref $w[-1]
not ref $_ @w not ref $w[-1]
Truth table100%4/4
not(A) and B and not(C)
A= not ref $_B= @wC= not ref $w[-1]
ABCresult
0XX0
10X0
1100
1111
191 6683 ▶ @w == 1 && !ref $w[0] ? $w[0] : @w ? \@w : '' }
Branch: 2 branches
BranchTrueFalseTotal
@w == 1 && !ref($w[0]) ? : 5918 765 6683
@w ? : 750 15 765
Condition100%3/3
@w == 1 and not ref $w[0]
!ll&&!rl&&r
3174485918
MC/DC100%2/2
@w == 1 and not ref $w[0]
@w == 1 not ref $w[0]
Truth table100%3/3
A and not(B)
A= @w == 1B= not ref $w[0]
ABresult
0X0
100
111
192  
193 409 ▶sub dq { # after '"', up to the closing '"'
Subroutine dq: called CC=5 SCAR=16.1
Pod undocumented
194 409 my ($s, $p) = @_;
195 409 ▶ until (/\G"/gc) {
Branch: 1 branch
BranchTrueFalseTotal
unless (/\G"/cg) 753 340 1093
196 753 ▶ next if /\G\\\n/gc;
Branch: 1 branch
BranchTrueFalseTotal
if /\G\\\n/cg 2 751 753
197 751 ▶ if (/\G(?:([^"\\\$`]+)|\\([\$`"\\])|(\\))/gc) { push @$s, [q => $+] }
Branch: 2 branches
BranchTrueFalseTotal
if (/\G(?:([^"\\\$`]+)|\\([\$`"\\])|(\\))/cg) { } 459 292 751
elsif (/\G([\$`])/cg) { } 287 5 292
198 287 elsif (/\G([\$`])/gc) { push @$s, [x => $EX{$1}->('"', pos() - 1)] }
199 5 else { E('unterminated double quote', $p) } } }
200  
201 857 ▶sub dollar { # after '$'; $q is '"' inside double quotes
Subroutine dollar: called CC=8 SCAR=20.8
Pod undocumented
202 857 my ($q, $p) = @_;
203 857 ▶ return '$' unless /\G[A-Za-z_0-9{(@*#?\$!\[-]/ or !$q && /\G['"]/; # starts nothing: literal (C1)
Branch: 1 branch
BranchTrueFalseTotal
unless /\G[A-Za-z_0-9{(\@*#?\$!\[-]/ or not $q and /\G['"]/ 57 800 857
Condition100%6/6
/\G[A-Za-z_0-9{(\@*#?\$!\[-]/ or not $q and /\G['"]/
l!l&&r!l&&!r
794657
not $q and /\G['"]/
!ll&&!rl&&r
33246
MC/DC100%3/3
/\G[A-Za-z_0-9{(\@*#?\$!\[-]/ or not $q and /\G['"]/
/\G[A-Za-z_0-9{(\@*#?\$!\[-]/ not $q /\G['"]/
Truth table100%4/4
A or not(B) and C
A= /\G[A-Za-z_0-9{(\@*#?\$!\[-]/B= not $qC= /\G['"]/
ABCresult
1XX1
0111
00X0
0100
204 800 ▶ return [$q . '$((', arith($p)] if /\G\(\(/gc;
Branch: 1 branch
BranchTrueFalseTotal
if /\G\(\(/cg 49 751 800
205 751 ▶ if (/\G\(/gc) { my $l = shell(')', []); /\G\)/gc; return [$q . '$(', $l] }
Branch: 1 branch
BranchTrueFalseTotal
if (/\G\(/cg) 165 586 751
206 586 ▶ return [$q . '$', name("$1", $p)] if /\G(?|\{($NM|[?!])\}|($NM|[?!]))/gc; # $? and $! (corpus-round C6)
Branch: 1 branch
BranchTrueFalseTotal
if /\G(?|\{($NM|[?!])\}|($NM|[?!]))/cg 362 224 586
207 224 ▶ E(/\G['"\[]/ ? 'bash-only $ form' : 'unsupported parameter form', $p) }
Branch: 1 branch
BranchTrueFalseTotal
/\G['"\[]/ ? : 16 208 224
208  
209 508 ▶sub name {
Subroutine name: called CC=5 SCAR=16.6
Pod undocumented
210 508 my ($n, $p) = @_;
211 E("shell-set variable '$n'", $p) if $SH{$n} || $n =~ /^(?:BASH|COMP|READLINE)_/
212 508 ▶ || $n =~ /^(?:PATH|SHELL|TERM|HOSTNAME)\z/ && !defined $ENV{$n};
Branch: 1 branch
BranchTrueFalseTotal
if $SH{$n} or $n =~ /^(?:BASH|COMP|READLINE)_/ or $n =~ /^(?:PATH|SHELL|TERM|HOSTNAME)\z/ and not defined $ENV{$n} 10 498 508
Condition66%6/9
$SH{$n} or $n =~ /^(?:BASH|COMP|READLINE)_/ or $n =~ /^(?:PATH|SHELL|TERM|HOSTNAME)\z/ and not defined $ENV{$n}
l!l&&r!l&&!r
100498
$SH{$n} or $n =~ /^(?:BASH|COMP|READLINE)_/
l!l&&r!l&&!r
82498
$n =~ /^(?:PATH|SHELL|TERM|HOSTNAME)\z/ and not defined $ENV{$n}
!ll&&!rl&&r
49800
MC/DC50%2/4
$SH{$n} or $n =~ /^(?:BASH|COMP|READLINE)_/ or $n =~ /^(?:PATH|SHELL|TERM|HOSTNAME)\z/ and not defined $ENV{$n}
$SH{$n} $n =~ /^(?:BASH|COMP|READLINE)_/ $n =~ /^(?:PATH|SHELL|TERM|HOSTNAME)\z/ not defined $ENV{$n}
Truth table60%3/5
A or B or C and not(D)
A= $SH{$n}B= $n =~ /^(?:BASH|COMP|READLINE)_/C= $n =~ /^(?:PATH|SHELL|TERM|HOSTNAME)\z/D= not defined $ENV{$n}
ABCDresult
1XXX1
01XX1
00111
000X0
00100
213 498 $n }
214  
215 49 ▶sub arith { # after '$((': check the expression by its grammar, return its text
Subroutine arith: called CC=4 SCAR=13.9
Pod undocumented
216 49 my $p = shift;
217 49 ▶ /\G((?&e))(?&w)\)\)$ARITH/gc && $1 !~ /\+\+|--/ or E('bad arithmetic expression', $p);
Branch: 1 branch
BranchTrueFalseTotal
/\G((?&e))(?&w)\)\)$ARITH/cg and not $1 =~ /\+\+|--/ or E("bad arithmetic expression", $p) 27 22 49
Condition100%3/3
/\G((?&e))(?&w)\)\)$ARITH/cg and not $1 =~ /\+\+|--/
!ll&&!rl&&r
20227
MC/DC100%2/2
/\G((?&e))(?&w)\)\)$ARITH/cg and not $1 =~ /\+\+|--/
/\G((?&e))(?&w)\)\)$ARITH/cg not $1 =~ /\+\+|--/
Truth table100%3/3
A and not(B)
A= /\G((?&e))(?&w)\)\)$ARITH/cgB= not $1 =~ /\+\+|--/
ABresult
0X0
100
111
218 27 ▶ my $t = $1; name("$1", $p) while $t =~ /\b($NM)/g;
Branch: 1 branch
BranchTrueFalseTotal
$t =~ /\b($NM)/g and do { name("$1", $p) } 8 27 35
219 27 $t }
220  
221 101 ▶sub bq { # after '`': find the closing '`', undo its escapes, parse the result as its own string
Subroutine bq: called CC=4 SCAR=13.9
Pod undocumented
222 101 my ($q, $p) = @_; my $s = pos;
223 101 ▶ /\G((?:[^`\\]|\\.)*)`/sgc or E('unterminated backquote', $p);
Branch: 1 branch
BranchTrueFalseTotal
/\G((?:[^`\\]|\\.)*)`/cgs or E("unterminated backquote", $p) 96 5 101
224 96 my ($raw, $in, @m) = ($1, '');
225 96 ▶ while ($raw =~ /\\([\$`\\$q])|(\\\n)|(.)/sg) { # a backslash escapes $ ` \ and, inside double quotes, "
Branch: 1 branch
BranchTrueFalseTotal
if ($raw =~ /\\([\$`\\$q])|(\\\n)|(.)/gs) 1018 94 1112
226 1018 ▶ E('backslash-newline inside backquotes', $s + $-[0]) if defined $2;
Branch: 1 branch
BranchTrueFalseTotal
if defined $2 2 1016 1018
227 1016 $in .= $+; push @m, P($s + $-[$#-]) }
228 94 push @m, P(pos() - 1);
229 94 [$q . '$(', do { local $_ = $in; local $M = \@m; shell('', []) }] }
230  
231 1367 ▶sub xc { # B3: 'exec' only where nothing can follow it in the shell (or subshell) it replaces
Subroutine xc: called CC=12 SCAR=24.8
Pod undocumented
232 1367 my ($l, $ok) = @_; # $ok: nothing follows this list in its shell
233 1367 for my $ch (@$l) { my @p = grep ref, @$ch;
234 1505 for my $pl (@p) { my @c = grep ref, @$pl;
235 1658 ▶ my $last = @c > 1 # each element of a longer pipeline is a subshell
Condition100%15/15
@c > 1 || $pl == $p[-1] && $pl->[0] ne '!' && ($ch->[-1] eq '&' || $ok && $ch == $l->[-1])
l!l&&r!l&&!r
3201029309
$pl == $p[-1] and $pl->[0] ne "!" and $ch->[-1] eq "&" || $ok && $ch == $l->[-1]
!ll&&!rl&&r
1651441029
$pl == $p[-1] and $pl->[0] ne "!"
!ll&&!rl&&r
144211173
$ch->[-1] eq "&" or $ok and $ch == $l->[-1]
l!l&&r!l&&!r
34995144
$ok and $ch == $l->[-1]
!ll&&!rl&&r
7137995
MC/DC100%6/6
@c > 1 || $pl == $p[-1] && $pl->[0] ne '!' && ($ch->[-1] eq '&' || $ok && $ch == $l->[-1])
@c > 1 $pl == $p[-1] $pl->[0] ne "!" $ch->[-1] eq "&" $ok $ch == $l->[-1]
Truth table100%7/7
A || B and C and D or E and F
A= @c > 1B= $pl == $p[-1]C= $pl->[0] ne "!"D= $ch->[-1] eq "&"E= $okF= $ch == $l->[-1]
ABCDEFresult
1XXXXX1
0111XX1
0110111
00XXXX0
010XXX0
01100X0
0110100
236 || $pl == $p[-1] && $pl->[0] ne '!' && ($ch->[-1] eq '&' || $ok && $ch == $l->[-1]);
237 1658 for my $x (@c) {
238 2160 ▶ xc($x->{group}, $last) if $x->{group};
Branch: 1 branch
BranchTrueFalseTotal
if $x->{"group"} 49 2111 2160
239 2151 ▶ if (exists $x->{exec}) { my $xp = $x->{exec}; $x->{exec} = 1;
Branch: 1 branch
BranchTrueFalseTotal
if (exists $x->{"exec"}) 51 2100 2151
240 51 ▶ $x->{ERROR} = 1, die ["'exec' with something after it", $xp] if !$last } } } } }
Branch: 1 branch
BranchTrueFalseTotal
unless $last 17 34 51
241  
242 1 1;
243 __END__
« lib/Proc/Spawner/Loop/POSIX.pm ↑ Summary lib/Proc/ShellSpawn/Large.pm »