lib/Proc/ShellSubset.pm

filter: Statementstmt 98.9% 372 / 376 Branchbran 95.8% 324 / 338 Conditioncond 85.2% 237 / 278 MC/DCmcdc 75.0% 105 / 140 Subroutinesub 100% 43 / 43 Podpod 0.0% 0 / 27 totaltotal 89.9% 1081 / 1202 CC 277 SCAR 31.2
CC
277
Cov
94%
simple
68.2
compound
22.0
xc
20.0
CRAP 22.6
« lib/Proc/ShellSpawn.pm ↑ Summary lib/Proc/ShellSpawn/Programs.pm »
1 package Proc::ShellSubset; # Parser for the Bourne-shell subset of doc/parsers/shell-subset-spec.md
2 534 our $VERSION = '0.12';
3 534 ▶use strict; use warnings; use List::Util qw(pairs pairvalues);
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 # Proc::ShellSubset::parse($string, %opt) 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 # %opt: nocaret (reject ^, as the Bourne shell reads it as |), nopwd (reject $PWD), check (sub: returns a reason to reject), empty (accept
10 # an empty string), fdmulti (multi-digit fds), tilde_args (~ after NAME= in arguments),
11 # brace (parse brace expansion), assign (commands with only settings), param_ops (${x:-w} ${x-w} ${x:+w} ${x+w} ${#x}),
12 # if (if/elif/else), while (while, until; break and continue inside), for (for NAME in ...; break, continue), case, read.
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 # (Proc::ShellSubset::Large adds cd_p => 1 for 'cd -P')
20 # | { set => [NAME, Word, NAME, Word, ...] } (option assign)
21 # | { if => [Cond, Then, Cond, Then, ..., Else (if present)] } (Cond, Then, Else: Lists; option if)
22 # | { while => Cond, do => List } | { until => Cond, do => List } (option while)
23 # | { for => NAME, in => [Word, ...], do => List } (option for)
24 # | { case => Word, in => [[Word, ...], List, [Word, ...], List, ...] } (patterns, body; option case)
25 # (all compound commands may also have redir => [...]; break, continue and read are simple commands)
26 # (keys only when non-empty; argv->[0] is a plain string; cd alone has cd => undef)
27 # Redir = [ fd, op, Word ] (for <& and >&: [ fd, op, 'digit or -' ])
28 # Word = 'literal text' | [ Part, ... ]
29 # Part = 'literal text' | [ '$', NAME or '?' or '!' ] | [ '$((', 'expr' ] | [ '$(', List ]
30 # | [ '${', NAME, ':-' | '-' | ':+' | '+', Word ] | [ '${#', NAME ] (option param_ops)
31 # | the same five with '"' in front ('"$' ...) when inside double quotes
32 # | [ '~', 'user' or '' ] | [ '*', 'pattern text' ]
33 # | [ '{', Word, Word, ... ] | [ '{..', from, to ]
34  
35 534 our ($CUT, $SRC, $LOFF, @ASH) = (0, '', 0); # P1, set by Proc::ShellSubset::Large: stop after this line; the text; lines before
36 23 ▶sub opos { my $q = shift; $q -= $$_[1] for grep $$_[0] <= $q, @ASH; P($q) } # it; [where, how much] alias values moved the rest (B1)
Subroutine opos: called CC=2 SCAR=6.9
Pod undocumented
37 534 our (%O, $M, @OPEN, $ATT, $LAST, $LOOP, $FORALL, $RLIT); # options; position map of a backquote's inside;
38 # arrays being filled (for the partial tree); how many of them are in the tree; end of the last top-level chain;
39 # depth of the loops around the current command in its shell; Proc::ShellSubset::Large: 'for NAME' loops over "$@",
40 # and a pattern in a redirection target is literal text (P6: dash, and bash in POSIX mode, do not expand it)
41 534 our %KW = map +($_ => 1), qw(if then else elif fi case esac for while until do done in [[ ]] function select coproc !);
42 534 our %BI = map +($_ => 1), qw(. break continue eval export readonly return set shift times trap unset alias
43 unalias read wait umask ulimit jobs fg bg command getopts hash type fc chdir local source let declare
44 typeset shopt enable builtin caller dirs pushd popd disown mapfile readarray suspend logout help
45 history bind compgen complete compopt);
46 534 our %SH = map +($_ => 1), qw(IFS PS1 PS2 PS4 OPTIND PPID OLDPWD LINENO _ BASH BASHOPTS BASHPID DIRSTACK
47 EPOCHREALTIME EPOCHSECONDS EUID FUNCNAME GROUPS HISTCMD HOSTTYPE MACHTYPE OPTERR OSTYPE PIPESTATUS
48 POSIXLY_CORRECT RANDOM SECONDS SHELLOPTS SHLVL SRANDOM UID);
49 534 our $NM = qr/[A-Za-z_][A-Za-z0-9_]*/;
50 534 our $END = qr/(?=[ \t\n;&|()<>]|\z)/;
51 534 our $B = qr/(?:[ \t]|\\\n|#.*)*+/; # blanks, line continuations, a comment
52 534 our $BN = qr/(?:[ \t\n]|\\\n|#.*)*+/; # the same, and newlines
53 534 our %STOP = (b => qr/\G(?:(?=[,}])|$END)/, map +($_ => qr/\G$END/), qw(a e r));
54 534 our $PIECE = qr/\G(?: '(?<sq>[^']*)' | (?<dq>") | \\(?<bs>.) | (?<ex>[\$`]) | (?<gl>[*?]) | (?<br>\[)
55 | (?<cb>\{(?!\})) | (?<ti>~) | (?<ca>\^) | (?<lit>(?:\{\}|[^ \t\n;&|()<>'"\\\$`*?\[{}^~,\x00-\x1f\x7f])+|,) | (?<bad>.) )/sx; # {} is literal (C2)
56 534 our $ARITH = qr{(?(DEFINE) # the expression grammar of $((...))
57 (?<w> [ \t\n]* )
58 (?<num> (?: 0[xX][0-9a-fA-F]+ | 0[0-7]* | [1-9][0-9]* ) (?![0-9A-Za-z_]) )
59 (?<atom> (?&w) (?: [-+!~] (?&w) )* (?: (?&num) | \$? [A-Za-z_][A-Za-z0-9_]* | \$\{[A-Za-z_][A-Za-z0-9_]*\} | \$[?!] | \$\{[?!]\}
60 | \( (?&e) (?&w) \) ) ) # $NAME, ${NAME}: substituted as text first (C9)
61 (?<op> (?&w) (?: << | >> | <= | >= | == | != | && | \|\| | [-+*/%<>&^|] ) )
62 (?<e> (?&atom) (?: (?&op) (?&atom) )* (?: (?&w) \? (?&e) (?&w) : (?&e) )? ) )}x;
63  
64 2689 ▶our %EX = (q{$} => sub { dollar(@_) }, q{`} => sub { bq(@_) }); # the expansion a $ or ` starts: ($q, $p) -> Part; by name, so Proc::ShellSubset::Large can replace them
Subroutine __ANON__: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=1 SCAR=0.0
65  
66 4223 ▶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::M ? : 134 4089 4223
Condition33%1/3
$Proc::ShellSubset::M->[$p] // $Proc::ShellSubset::M->[-1]
l!l&&r!l&&!r
13400
MC/DC0%0/2
$Proc::ShellSubset::M->[$p] // $Proc::ShellSubset::M->[-1]
$Proc::ShellSubset::M->[$p] $Proc::ShellSubset::M->[-1]
Truth table33%1/3
A // B
A= $Proc::ShellSubset::M->[$p]B= $Proc::ShellSubset::M->[-1]
ABresult
1X1
011
000
67 2673 ▶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::OPEN 2644 29 2673
Condition100%2/2
$Proc::ShellSubset::ATT // -1
l!l
12461398
MC/DC100%1/1
$Proc::ShellSubset::ATT // -1
$Proc::ShellSubset::ATT
Truth table100%2/2
A
A= $Proc::ShellSubset::ATT
Aresult
11
00
68 240 ▶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 ? : 220 20 240
$1 eq "\n" ? : 0 220 220
69 5316 ▶sub parse {
Subroutine parse: called CC=9 SCAR=22.3
Pod undocumented
70 5316 my $s = shift; local %O = @_; local ($M, @OPEN, $ATT); local $LAST = 0; my @l;
71 5316 my $t = eval {
72 5316 local $_ = $s;
73 5316 ▶ E('NUL character', $-[0]) if /\0/;
Branch: 1 branch
BranchTrueFalseTotal
if /\0/ 1 5315 5316
74 5315 ▶ 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]*([-+])/ 16 5299 5315
75 0 ▶ if ($O{check} and my $why = $O{check}->($s)) { E($why, 0) }
Branch: 1 branch
BranchTrueFalseTotal
if ($Proc::ShellSubset::O{"check"} and my $why = $Proc::ShellSubset::O{"check"}->($s)) 0 5299 5299
Condition33%1/3
$Proc::ShellSubset::O{"check"} and my $why = $Proc::ShellSubset::O{"check"}->($s)
!ll&&!rl&&r
529900
MC/DC0%0/2
$Proc::ShellSubset::O{"check"} and my $why = $Proc::ShellSubset::O{"check"}->($s)
$Proc::ShellSubset::O{"check"} my $why = $Proc::ShellSubset::O{"check"}->($s)
Truth table33%1/3
A and B
A= $Proc::ShellSubset::O{"check"}B= my $why = $Proc::ShellSubset::O{"check"}->($s)
ABresult
0X0
100
111
76 5299 shell('', \@l);
77 2610 ▶ @l or $O{empty} or E('empty command', 0); \@l };
Branch: 1 branch
BranchTrueFalseTotal
@l or $Proc::ShellSubset::O{"empty"} or E("empty command", 0) 2598 12 2610
Condition100%3/3
@l or $Proc::ShellSubset::O{"empty"}
l!l&&r!l&&!r
25821612
MC/DC100%2/2
@l or $Proc::ShellSubset::O{"empty"}
@l $Proc::ShellSubset::O{"empty"}
Truth table100%3/3
A or B
A= @lB= $Proc::ShellSubset::O{"empty"}
ABresult
1X1
011
000
78 5316 ▶ $t // (ref $@ eq 'ARRAY' ? { error => $@->[0], pos => $@->[1], last => $LAST, tree => \@l } : die $@) }
Branch: 1 branch
BranchTrueFalseTotal
ref $@ eq 'ARRAY' ? : 2718 0 2718
Condition100%2/2
$t // (ref $@ eq "ARRAY" ? {"error", $@->[0], "pos", $@->[1], "last", $Proc::ShellSubset::LAST, "tree", \@l} : die($@))
l!l
25982718
MC/DC100%1/1
$t // (ref $@ eq "ARRAY" ? {"error", $@->[0], "pos", $@->[1], "last", $Proc::ShellSubset::LAST, "tree", \@l} : die($@))
$t
Truth table100%2/2
A
A= $t
Aresult
11
00
79  
80 6573 ▶sub list { # up to ')' (subshell, $()), a word in $t ('\}', 'then', 'elif|else|fi', ...), or the end ('')
Subroutine list: called CC=14 SCAR=26.4
Pod undocumented
81 6573 ▶ my ($t, $l) = @_; local $OPEN[@OPEN] = $l; my $top = !$t && !$M; # fills @$l in place
Condition100%3/3
$t || $Proc::ShellSubset::M
l!l&&r!l&&!r
10871875299
MC/DC100%2/2
$t || $Proc::ShellSubset::M
$t $Proc::ShellSubset::M
Truth table100%3/3
A || B
A= $tB= $Proc::ShellSubset::M
ABresult
1X1
011
000
82 6573 ▶ my $e = ref $t ? $t : $t eq ')' ? qr/\G(?=\))/ : $t ? qr/\G(?=(?:$t)$END)/ : qr/\G\z/; # or a ready regex
Branch: 3 branches
BranchTrueFalseTotal
ref $t ? : 48 6525 6573
$t eq ')' ? : 557 5968 6525
$t ? : 482 5486 5968
83 6573 ▶ while (/\G$BN/gc, !/$e/) { # (zero-length /gc matches can't repeat at one place: test with plain //)
Branch: 1 branch
BranchTrueFalseTotal
if (/\G$Proc::ShellSubset::BN/cg, !/$e/) 8084 574 8658
84 8084 push @$l, my $c = []; andor($c);
85 5432 ▶ if (/\G$B&(?!&)/gc) { push @$c, '&' }
Branch: 2 branches
BranchTrueFalseTotal
if (/\G$Proc::ShellSubset::B&(?!&)/cg) { } 160 5272 5432
elsif (not /\G$Proc::ShellSubset::B(?:;(?!;)|\n)/cg) { } 3339 1933 5272
86 3339 ▶ elsif (!/\G$B(?:;(?!;)|\n)/gc) { /\G$B/gc, /$e/ ? last : U() }
Branch: 1 branch
BranchTrueFalseTotal
/$e/ ? : 3105 234 3339
87 2093 ▶ $LAST = pos if $top;
Branch: 1 branch
BranchTrueFalseTotal
if $top 1415 678 2093
88 2093 ▶ if ($top && $CUT && substr($_, pos() - 1, 1) eq "\n" and /\G$BN/gc, !/$e/) { # P1 (Proc::ShellSubset::Large): an alias
Branch: 1 branch
BranchTrueFalseTotal
if ($top and $Proc::ShellSubset::CUT and substr($_, pos($_) - 1, 1) eq "\n" and /\G$Proc::ShellSubset::BN/cg, !/$e/) 8 2085 2093
Condition88%8/9
$top and $Proc::ShellSubset::CUT and substr($_, pos($_) - 1, 1) eq "\n" and /\G$Proc::ShellSubset::BN/cg, !/$e/
!ll&&!rl&&r
208508
$top and $Proc::ShellSubset::CUT and substr($_, pos($_) - 1, 1) eq "\n"
!ll&&!rl&&r
208058
$top and $Proc::ShellSubset::CUT
!ll&&!rl&&r
678140213
MC/DC75%3/4
$top and $Proc::ShellSubset::CUT and substr($_, pos($_) - 1, 1) eq "\n" and /\G$Proc::ShellSubset::BN/cg, !/$e/
$top $Proc::ShellSubset::CUT substr($_, pos($_) - 1, 1) eq "\n" /\G$Proc::ShellSubset::BN/cg, !/$e/
Truth table80%4/5
A and B and C and D
A= $topB= $Proc::ShellSubset::CUTC= substr($_, pos($_) - 1, 1) eq "\n"D= /\G$Proc::ShellSubset::BN/cg, !/$e/
ABCDresult
0XXX0
10XX0
110X0
11100
11111
89 8 my $p = opos(pos); # definition known only when it runs: the rest
90 8 push @$l, [[{ rest => substr($SRC, $p), lineoff => $LOFF + (substr($SRC, 0, $p) =~ tr/\n//) }]]; last } } # of the text, parsed then
91 3687 $l }
92  
93 6043 ▶sub shell { # a list that runs in a shell of its own: the loops around it don't count, and exec is checked at its end
Subroutine shell: called CC=1 SCAR=0.0
Pod undocumented
94 6043 local $LOOP = 0; my $l = list(@_); xc($l, 1); $l }
95  
96 8084 ▶sub andor {
Subroutine andor: called CC=3 SCAR=11.0
Pod undocumented
97 8084 my $ao = shift; local $OPEN[@OPEN] = $ao;
98 8084 ▶ do { push @$ao, my $p = []; pipeline($p) } while /\G$B(&&|\|\|)$BN/gc && push @$ao, $1 }
Branch: 1 branch
BranchTrueFalseTotal
/\G$Proc::ShellSubset::B(&&|\|\|)$Proc::ShellSubset::BN/cg and push @$ao, $1 and do { do { push @$ao, my $p = []; pipeline($p) } } 358 5432 5790
Condition66%2/3
/\G$Proc::ShellSubset::B(&&|\|\|)$Proc::ShellSubset::BN/cg and push @$ao, $1
!ll&&!rl&&r
54320358
MC/DC50%1/2
/\G$Proc::ShellSubset::B(&&|\|\|)$Proc::ShellSubset::BN/cg and push @$ao, $1
/\G$Proc::ShellSubset::B(&&|\|\|)$Proc::ShellSubset::BN/cg push @$ao, $1
Truth table66%2/3
A and B
A= /\G$Proc::ShellSubset::B(&&|\|\|)$Proc::ShellSubset::BN/cgB= push @$ao, $1
ABresult
0X0
100
111
99  
100 8442 ▶sub pipeline {
Subroutine pipeline: called CC=10 SCAR=23.0
Pod undocumented
101 8442 my $p = shift; local $OPEN[@OPEN] = $p;
102 8442 ▶ push @$p, '!' if /\G!(?=[ \t])$B/gc;
Branch: 1 branch
BranchTrueFalseTotal
if /\G!(?=[ \t])$Proc::ShellSubset::B/cg 59 8383 8442
103 8442 ▶ E("'! !'", pos) if @$p && /\G!$END/;
Branch: 1 branch
BranchTrueFalseTotal
if @$p and /\G!$Proc::ShellSubset::END/ 11 8431 8442
Condition100%3/3
@$p and /\G!$Proc::ShellSubset::END/
!ll&&!rl&&r
83834811
MC/DC100%2/2
@$p and /\G!$Proc::ShellSubset::END/
@$p /\G!$Proc::ShellSubset::END/
Truth table100%3/3
A and B
A= @$pB= /\G!$Proc::ShellSubset::END/
ABresult
0X0
100
111
104 8431 ▶ do { command($p) } while /\G$B\|(?![|&])$BN/gc;
Branch: 1 branch
BranchTrueFalseTotal
/\G$Proc::ShellSubset::B\|(?![|&])$Proc::ShellSubset::BN/cg and do { do { command($p) } } 1006 5794 6800
105 5794 my ($q, @c) = (pos, grep ref, @$p); # each element of a longer pipeline is a subshell: break/continue can't reach the loop
106 5794 ▶ @c > 1 and ($_->{argv} && $_->{argv}[0] // q{}) =~ /^(?:break|continue)\z/ and E("'$_->{argv}[0]' in a pipeline", $q) for @c }
Branch: 1 branch
BranchTrueFalseTotal
@c > 1 and ($_->{"argv"} && $_->{"argv"}[0] // "") =~ /^(?:break|continue)\z/ and E(qq['$_->{"argv"}[0]' in a pipeline], $q) 4 6726 6730
Condition100%8/8
@c > 1 and ($_->{"argv"} && $_->{"argv"}[0] // "") =~ /^(?:break|continue)\z/
!ll&&!rl&&r
515215744
$_->{"argv"} && $_->{"argv"}[0] // ""
l!l
1458120
$_->{"argv"} and $_->{"argv"}[0]
!ll&&!rl&&r
11761455
MC/DC100%3/3
@c > 1 and ($_->{"argv"} && $_->{"argv"}[0] // "") =~ /^(?:break|continue)\z/
@c > 1 $_->{"argv"} $_->{"argv"}[0]
Truth table100%4/4
A and B and C
A= @c > 1B= $_->{"argv"}C= $_->{"argv"}[0]
ABCresult
0XX0
10X0
1100
1111
107  
108 545 ▶sub kw { /\G$BN/gc; /\G$_[0]$END/gc } # a reserved word, after blanks and newlines
Subroutine kw: called CC=1 SCAR=0.0
Pod undocumented
109 105 ▶sub part { # a list up to one of the words in $t, into a new array pushed onto @$to; must not be empty
Subroutine part: called CC=2 SCAR=6.9
Pod undocumented
110 105 ▶ my ($to, $t, $what, $p) = @_; push @$to, my $l = []; list($t, $l); @$l or E("empty $what", $p); $l }
Branch: 1 branch
BranchTrueFalseTotal
@$l or E("empty $what", $p) 89 4 93
111 105 ▶sub body { # a loop's 'do' list up to 'done', one loop deeper for break and continue
Subroutine body: called CC=2 SCAR=7.0
Pod undocumented
112 105 my ($c, $p) = @_; local $LOOP = $LOOP + 1;
113 105 ▶ list('done', $c->{do}); @{$c->{do}} or E('empty loop body', $p); kw('done') }
Branch: 1 branch
BranchTrueFalseTotal
@{$c->{"do"};} or E("empty loop body", $p) 84 0 84
114 272 ▶sub vname { # a variable the string sets: by assignment (C5), for or read
Subroutine vname: called CC=2 SCAR=6.9
Pod undocumented
115 272 ▶ my ($n, $p) = @_; E("assignment to '$n'", $p) if $n =~ /^(?:HOME|CDPATH|PPID)\z/; name($n, $p) } # PPID: read-only in bash
Branch: 1 branch
BranchTrueFalseTotal
if $n =~ /^(?:HOME|CDPATH|PPID)\z/ 13 259 272
116  
117 9005 ▶sub compound { # if, while, until, for, case (each with its option); pushes the node onto @$pl
Subroutine compound: called CC=22 SCAR=30.9
Pod undocumented
118 9005 my ($pl, $p) = @_; my $c;
119 9005 ▶ if ($O{if} && /\Gif$END/gc) {
Branch: 4 branches
BranchTrueFalseTotal
if ($Proc::ShellSubset::O{'if'} and /\Gif$Proc::ShellSubset::END/cg) { } 52 8953 9005
elsif ($Proc::ShellSubset::O{'while'} and /\G(while|until)$Proc::ShellSubset::END/cg) { } 51 8902 8953
elsif ($Proc::ShellSubset::O{'for'} and /\Gfor$Proc::ShellSubset::END/cg) { } 81 8821 8902
elsif ($Proc::ShellSubset::O{'case'} and /\Gcase$Proc::ShellSubset::END/cg) { } 47 11774 11821
Condition100%3/3
$Proc::ShellSubset::O{"if"} and /\Gif$Proc::ShellSubset::END/cg
!ll&&!rl&&r
3000595352
MC/DC100%2/2
$Proc::ShellSubset::O{"if"} and /\Gif$Proc::ShellSubset::END/cg
$Proc::ShellSubset::O{"if"} /\Gif$Proc::ShellSubset::END/cg
Truth table100%3/3
A and B
A= $Proc::ShellSubset::O{"if"}B= /\Gif$Proc::ShellSubset::END/cg
ABresult
0X0
100
111
120 52 push @$pl, $c = { if => my $arms = [] };
121 52 ▶ do { part($arms, 'then', 'condition', $p); kw('then'); part($arms, 'elif|else|fi', "'then' part", $p) } while kw('elif');
Branch: 1 branch
BranchTrueFalseTotal
kw("elif") and do { do { part($arms, "then", "condition", $p); kw("then"); part($arms, "elif|else|fi", "'then' part", $p) } } 3 36 39
122 36 ▶ part($arms, 'fi', "'else' part", $p) if kw('else');
Branch: 1 branch
BranchTrueFalseTotal
if kw("else") 5 31 36
123 36 kw('fi') }
124 ▶ elsif ($O{while} && /\G(while|until)$END/gc) {
Condition100%3/3
$Proc::ShellSubset::O{"while"} and /\G(while|until)$Proc::ShellSubset::END/cg
!ll&&!rl&&r
2998590451
MC/DC100%2/2
$Proc::ShellSubset::O{"while"} and /\G(while|until)$Proc::ShellSubset::END/cg
$Proc::ShellSubset::O{"while"} /\G(while|until)$Proc::ShellSubset::END/cg
Truth table100%3/3
A and B
A= $Proc::ShellSubset::O{"while"}B= /\G(while|until)$Proc::ShellSubset::END/cg
ABresult
0X0
100
111
125 51 push @$pl, $c = { $1 => my $cond = [], do => [] };
126 51 ▶ list('do', $cond); @$cond or E('empty condition', $p); kw('do'); body($c, $p) }
Branch: 1 branch
BranchTrueFalseTotal
@$cond or E("empty condition", $p) 49 0 49
127 ▶ elsif ($O{for} && /\Gfor$END/gc) {
Condition100%3/3
$Proc::ShellSubset::O{"for"} and /\Gfor$Proc::ShellSubset::END/cg
!ll&&!rl&&r
3010581181
MC/DC100%2/2
$Proc::ShellSubset::O{"for"} and /\Gfor$Proc::ShellSubset::END/cg
$Proc::ShellSubset::O{"for"} /\Gfor$Proc::ShellSubset::END/cg
Truth table100%3/3
A and B
A= $Proc::ShellSubset::O{"for"}B= /\Gfor$Proc::ShellSubset::END/cg
ABresult
0X0
100
111
128 81 ▶ /\G$B/gc; my $q = pos; /\G($NM)$END/gc or E("'for' needs a variable name", $q);
Branch: 1 branch
BranchTrueFalseTotal
/\G($Proc::ShellSubset::NM)$Proc::ShellSubset::END/cg or E("'for' needs a variable name", $q) 77 4 81
129 77 push @$pl, $c = { for => vname("$1", $q), in => my $in = [], do => [] };
130 72 ▶ if (kw('in')) { { local $OPEN[@OPEN] = $in; push @$in, word('a') while /\G$B/gc, !/\G(?=[;\n]|\z)/ }
Branch: 2 branches
BranchTrueFalseTotal
if (kw('in')) { } 52 20 72
/\G$Proc::ShellSubset::B/cg, !/\G(?=[;\n]|\z)/ and do { push @$in, word("a") } 79 47 126
131 47 ▶ /\G$B[;\n]/gc or U() }
Branch: 1 branch
BranchTrueFalseTotal
/\G$Proc::ShellSubset::B[;\n]/cg or U() 47 0 47
132 20 ▶ else { $FORALL or E("'for' without 'in' (it would loop over \$@)", pos); # for NAME: as for NAME in "$@"
Branch: 1 branch
BranchTrueFalseTotal
$Proc::ShellSubset::FORALL or E("'for' without 'in' (it would loop over \$\@)", pos $_) 11 9 20
133 11 push @$in, ['', ['"$', '@']]; /\G$B[;\n]/gc }
134 58 ▶ kw('do') or U(); body($c, $p) }
Branch: 1 branch
BranchTrueFalseTotal
kw("do") or U() 56 2 58
135 ▶ elsif ($O{case} && /\Gcase$END/gc) {
Condition100%3/3
$Proc::ShellSubset::O{"case"} and /\Gcase$Proc::ShellSubset::END/cg
!ll&&!rl&&r
3000577447
MC/DC100%2/2
$Proc::ShellSubset::O{"case"} and /\Gcase$Proc::ShellSubset::END/cg
$Proc::ShellSubset::O{"case"} /\Gcase$Proc::ShellSubset::END/cg
Truth table100%3/3
A and B
A= $Proc::ShellSubset::O{"case"}B= /\Gcase$Proc::ShellSubset::END/cg
ABresult
0X0
100
111
136 47 push @$pl, $c = { case => '', in => my $in = [] }; local $OPEN[@OPEN] = $in;
137 47 ▶ /\G$B/gc; $c->{case} = word('a'); kw('in') or U();
Branch: 1 branch
BranchTrueFalseTotal
kw("in") or U() 39 4 43
138 39 ▶ until (kw('esac')) {
Branch: 1 branch
BranchTrueFalseTotal
unless (kw("esac")) 50 33 83
139 50 /\G\(/gc; push @$in, my $pat = [];
140 50 ▶ { local $OPEN[@OPEN] = $pat; do { /\G$B/gc; push @$pat, word('a') } while /\G$B\|/gc }
Branch: 1 branch
BranchTrueFalseTotal
/\G$Proc::ShellSubset::B\|/cg and do { do { /\G$Proc::ShellSubset::B/cg; push @$pat, word("a") } } 2 48 50
141 48 ▶ /\G$B\)/gc or U(); push @$in, my $l = []; list(qr/\G(?=;;|esac$END)/, $l); /\G;;/gc } }
Branch: 1 branch
BranchTrueFalseTotal
/\G$Proc::ShellSubset::B\)/cg or U() 48 0 48
142 8927 $c }
143  
144 9423 ▶sub command { # pushes the command onto the pipeline @{$_[0]}
Subroutine command: called CC=9 SCAR=22.0
Pod undocumented
145 9423 my $pl = shift; my $p = pos; my $c;
146 9423 ▶ E("'((' at the start of a command", $p) if /\G\(\(/;
Branch: 1 branch
BranchTrueFalseTotal
if /\G\(\(/ 16 9407 9423
147 9407 ▶ if (/\G\(/gc) {
Branch: 2 branches
BranchTrueFalseTotal
if (/\G\(/cg) { } 181 9226 9407
elsif (/\G\{(?=[ \t\n])/cg) { } 221 9005 9226
148 181 push @$pl, $c = { sub => my $l = [] };
149 181 ▶ shell(')', $l); /\G\)/gc; @$l or E('empty subshell', $p) }
Branch: 1 branch
BranchTrueFalseTotal
@$l or E("empty subshell", $p) 145 8 153
150 elsif (/\G\{(?=[ \t\n])/gc) {
151 221 push @$pl, $c = { group => my $l = [] };
152 221 ▶ list('\}', $l); /\G\}/gc; @$l or E('empty group', $p) } # xc: by the parent
Branch: 1 branch
BranchTrueFalseTotal
@$l or E("empty group", $p) 189 1 190
153 9005 ▶ else { $c = compound($pl, $p) or return simple($pl) }
Branch: 1 branch
BranchTrueFalseTotal
$c = compound($pl, $p) or return simple($pl) 153 8774 8927
154 487 ▶ my ($r, @r); push @r, $r while /\G$B/gc, $r = redir();
Branch: 1 branch
BranchTrueFalseTotal
/\G$Proc::ShellSubset::B/cg, $r = redir() and do { push @r, $r } 83 484 567
155 484 ▶ $c->{redir} = \@r if @r;
Branch: 1 branch
BranchTrueFalseTotal
if @r 68 416 484
156 484 $c }
157  
158 15768 ▶sub redir { # a redirection, or nothing (pos unchanged) if none starts here
Subroutine redir: called CC=11 SCAR=24.0
Pod undocumented
159 15768 my $p = pos;
160 15768 ▶ E('process substitution (bash)', $p) if /\G[<>]\(/;
Branch: 1 branch
BranchTrueFalseTotal
if /\G[<>]\(/ 25 15743 15768
161 15743 ▶ /\G([0-9]*)(<<|>>|<>|>\||<&|>&|<|>)$B/gc or return;
Branch: 1 branch
BranchTrueFalseTotal
/\G([0-9]*)(<<|>>|<>|>\||<&|>&|<|>)$Proc::ShellSubset::B/cg or return 974 14769 15743
162 974 ▶ 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]+[<>]/ 12 962 974
163 962 my ($n, $op) = ($1, $2);
164 962 ▶ E('here-document', $p) if $op eq '<<';
Branch: 1 branch
BranchTrueFalseTotal
if $op eq "<<" 62 900 962
165 900 ▶ E('multi-digit descriptor', $p) if length $n > 1 && !$O{fdmulti};
Branch: 1 branch
BranchTrueFalseTotal
if length $n > 1 and not $Proc::ShellSubset::O{"fdmulti"} 7 893 900
Condition100%3/3
length $n > 1 and not $Proc::ShellSubset::O{"fdmulti"}
!ll&&!rl&&r
88587
MC/DC100%2/2
length $n > 1 and not $Proc::ShellSubset::O{"fdmulti"}
length $n > 1 not $Proc::ShellSubset::O{"fdmulti"}
Truth table100%3/3
A and not(B)
A= length $n > 1B= not $Proc::ShellSubset::O{"fdmulti"}
ABresult
0X0
100
111
166 893 ▶ my $fd = length $n ? 0 + $n : $op =~ /^</ ? 0 : 1;
Branch: 2 branches
BranchTrueFalseTotal
length $n ? : 203 690 893
$op =~ /^</ ? : 183 507 690
167 893 ▶ return [$fd, $op, /\G([0-9-])$END/gc ? $1 : E("'$op' takes one digit or '-'", pos)] if $op =~ /&/;
Branch: 2 branches
BranchTrueFalseTotal
if $op =~ /&/ 159 734 893
/\G([0-9-])$Proc::ShellSubset::END/cg ? : 146 13 159
168 734 [$fd, $op, word('r')] }
169  
170 6509 ▶sub simple {
Subroutine simple: called CC=60 SCAR=42.2
Pod undocumented
171 6509 my $pl = shift; my (@env, @np, @av, @ap, @r, $kw); my $p0 = pos; # @np: NAME, position, ... of the settings
172 6509 push @$pl, my $c = { argv => \@av }; local $OPEN[@OPEN] = \@av;
173 6509 ▶ while (/\G$B/gc, !/\G(?=[;&|()\n]|\z)/) {
Branch: 1 branch
BranchTrueFalseTotal
if (/\G$Proc::ShellSubset::B/cg, !/\G(?=[;&|()\n]|\z)/) 15375 5219 20594
174 15375 my $p = pos;
175 15375 ▶ if (my $r = redir()) { push @r, $r }
Branch: 2 branches
BranchTrueFalseTotal
if (my $r = redir()) { } 704 14453 15157
elsif (not @av and /\G($Proc::ShellSubset::NM)(\+?)=/cg) { } 486 13967 14453
176 486 ▶ 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 16 470 486
Condition100%3/3
not @av and /\G($Proc::ShellSubset::NM)(\+?)=/cg
!ll&&!rl&&r
79286039486
MC/DC100%2/2
not @av and /\G($Proc::ShellSubset::NM)(\+?)=/cg
not @av /\G($Proc::ShellSubset::NM)(\+?)=/cg
Truth table100%3/3
not(A) and B
A= not @avB= /\G($Proc::ShellSubset::NM)(\+?)=/cg
ABresult
0X0
100
111
177 13967 ▶ 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
703359730
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
178 5219 ▶ if (!@av && @env && !@r && $O{assign}) { # only settings (C5)
Branch: 1 branch
BranchTrueFalseTotal
if (not @av and @env and not @r and $Proc::ShellSubset::O{"assign"}) 162 5057 5219
Condition100%9/9
not @av and @env and not @r and $Proc::ShellSubset::O{"assign"}
!ll&&!rl&&r
499364162
not @av and @env and not @r
!ll&&!rl&&r
497617226
not @av and @env
!ll&&!rl&&r
489482243
MC/DC100%4/4
not @av and @env and not @r and $Proc::ShellSubset::O{"assign"}
not @av @env not @r $Proc::ShellSubset::O{"assign"}
Truth table100%5/5
not(A) and B and not(C) and D
A= not @avB= @envC= not @rD= $Proc::ShellSubset::O{"assign"}
ABCDresult
0XXX0
10XX0
110X0
11100
11111
179 162 ▶ vname(splice @np, 0, 2) while @np;
Branch: 1 branch
BranchTrueFalseTotal
@np and do { vname(splice(@np, 0, 2)) } 164 142 306
180 142 return %$c = (set => \@env) }
181 5057 name(@$_) for grep $$_[0] ne q{IFS}, pairs @np; # bash refuses its own names (UID=5 cmd)
182 5046 ▶ @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) 4885 161 5046
@env || @r ? : 145 16 161
Condition100%3/3
@env or @r
l!l&&r!l&&!r
796616
MC/DC100%2/2
@env or @r
@env @r
Truth table100%3/3
A or B
A= @envB= @r
ABresult
1X1
011
000
183 4885 ▶ E('command name not literal', $ap[0]) if ref $av[0];
Branch: 1 branch
BranchTrueFalseTotal
if ref $av[0] 30 4855 4885
184 4855 my $n = $av[0];
185 4855 ▶ if ($n eq 'exec') {
Branch: 1 branch
BranchTrueFalseTotal
if ($n eq 'exec') { } 129 4726 4855
186 129 shift @av; my $xp = shift @ap;
187 129 ▶ @av or E("'exec' without a command", $p0);
Branch: 1 branch
BranchTrueFalseTotal
@av or E("'exec' without a command", $p0) 115 14 129
188 115 ▶ 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/ 16 99 115
Condition66%2/3
ref $av[0] or $av[0] =~ /^-|^(?:cd|:|exit)\z/
l!l&&r!l&&!r
01699
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
189 99 $c->{exec} = P($xp) } # its position, until xc() has checked it and made it 1
190 else {
191 4726 ▶ E("keyword '$n'", $ap[0]) if $KW{$n} && $kw eq $n;
Branch: 1 branch
BranchTrueFalseTotal
if $Proc::ShellSubset::KW{$n} and $kw eq $n 62 4664 4726
Condition100%3/3
$Proc::ShellSubset::KW{$n} and $kw eq $n
!ll&&!rl&&r
46541062
MC/DC100%2/2
$Proc::ShellSubset::KW{$n} and $kw eq $n
$Proc::ShellSubset::KW{$n} $kw eq $n
Truth table100%3/3
A and B
A= $Proc::ShellSubset::KW{$n}B= $kw eq $n
ABresult
0X0
100
111
192 4664 ▶ if ($n =~ /^(?:break|continue)\z/ && $LOOP) { # inside a loop (options while, for)
Branch: 3 branches
BranchTrueFalseTotal
if ($n =~ /^(?:break|continue)\z/ and $Proc::ShellSubset::LOOP) { } 25 4639 4664
elsif ($n eq 'read' and $Proc::ShellSubset::O{'read'}) { } 62 4577 4639
elsif ($Proc::ShellSubset::BI{$n}) { } 360 4217 4577
Condition100%3/3
$n =~ /^(?:break|continue)\z/ and $Proc::ShellSubset::LOOP
!ll&&!rl&&r
46162325
MC/DC100%2/2
$n =~ /^(?:break|continue)\z/ and $Proc::ShellSubset::LOOP
$n =~ /^(?:break|continue)\z/ $Proc::ShellSubset::LOOP
Truth table100%3/3
A and B
A= $n =~ /^(?:break|continue)\z/B= $Proc::ShellSubset::LOOP
ABresult
0X0
100
111
193 25 ▶ E("unsupported '$n' form", $ap[0]) if @env || @r || @av > 2
Branch: 1 branch
BranchTrueFalseTotal
if @env or @r or @av > 2 or @av == 2 and !($av[1] =~ /^[1-9][0-9]*\z/) || $av[1] > $Proc::ShellSubset::LOOP 3 22 25
Condition60%9/15
@env or @r or @av > 2 or @av == 2 and !($av[1] =~ /^[1-9][0-9]*\z/) || $av[1] > $Proc::ShellSubset::LOOP
l!l&&r!l&&!r
0322
@env or @r or @av > 2
l!l&&r!l&&!r
0025
@env or @r
l!l&&r!l&&!r
0025
@av == 2 and !($av[1] =~ /^[1-9][0-9]*\z/) || $av[1] > $Proc::ShellSubset::LOOP
!ll&&!rl&&r
12103
not $av[1] =~ /^[1-9][0-9]*\z/ or $av[1] > $Proc::ShellSubset::LOOP
l!l&&r!l&&!r
0310
MC/DC33%2/6
@env or @r or @av > 2 or @av == 2 and !($av[1] =~ /^[1-9][0-9]*\z/) || $av[1] > $Proc::ShellSubset::LOOP
@env @r @av > 2 @av == 2 not $av[1] =~ /^[1-9][0-9]*\z/ $av[1] > $Proc::ShellSubset::LOOP
Truth table42%3/7
A or B or C or D and not(E) or F
A= @envB= @rC= @av > 2D= @av == 2E= not $av[1] =~ /^[1-9][0-9]*\z/F= $av[1] > $Proc::ShellSubset::LOOP
ABCDEFresult
1XXXXX1
01XXXX1
001XXX1
00011X1
0001011
0000XX0
0001000
194 || @av == 2 && ($av[1] !~ /^[1-9][0-9]*\z/ || $av[1] > $LOOP) }
195 ▶ elsif ($n eq 'read' && $O{read}) { # read [-r] NAME... (option read)
Condition100%3/3
$n eq "read" and $Proc::ShellSubset::O{"read"}
!ll&&!rl&&r
45671062
MC/DC100%2/2
$n eq "read" and $Proc::ShellSubset::O{"read"}
$n eq "read" $Proc::ShellSubset::O{"read"}
Truth table100%3/3
A and B
A= $n eq "read"B= $Proc::ShellSubset::O{"read"}
ABresult
0X0
100
111
196 62 ▶ my $i = ($av[1] // '') eq '-r' ? 2 : 1;
Branch: 1 branch
BranchTrueFalseTotal
($av[1] // '') eq '-r' ? : 10 52 62
Condition100%2/2
$av[1] // ""
l!l
584
MC/DC100%1/1
$av[1] // ""
$av[1]
Truth table100%2/2
A
A= $av[1]
Aresult
11
00
197 62 ▶ $i <= $#av or E("'read' without a variable name", $ap[0]);
Branch: 1 branch
BranchTrueFalseTotal
$i <= $#av or E("'read' without a variable name", $ap[0]) 58 4 62
198 58 ▶ for my $j ($i .. $#av) { $av[$j] =~ /^$NM\z/ or E("unsupported 'read' argument", $ap[$j]); vname($av[$j], $ap[$j]) } }
Branch: 1 branch
BranchTrueFalseTotal
$av[$j] =~ /^$Proc::ShellSubset::NM\z/ or E("unsupported 'read' argument", $ap[$j]) 60 12 72
199 360 elsif ($BI{$n}) { E("builtin '$n'", $ap[0]) }
200 4280 ▶ if ($n eq 'cd') {
Branch: 1 branch
BranchTrueFalseTotal
if ($n eq "cd") 155 4125 4280
201 155 ▶ @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]) 110 45 155
Condition85%12/14
@av <= 2 and not @env and not @r and not defined $ENV{"CDPATH"} and not +($av[1] // "") =~ /^-/
!ll&&!rl&&r
369110
@av <= 2 and not @env and not @r and not defined $ENV{"CDPATH"}
!ll&&!rl&&r
360119
@av <= 2 and not @env and not @r
!ll&&!rl&&r
306119
@av <= 2 and not @env
!ll&&!rl&&r
300125
$av[1] // ""
l!l
10811
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
202 or E('unsupported cd form', $ap[0]); # C8: the argument may have expansions; cd alone goes home
203 E('cd to $HOME without HOME', $ap[0]) if !defined $ENV{HOME}
204 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 110 110
Condition8%1/12
not defined $ENV{"HOME"} and @av == 1 || ref $av[1] && grep({ref $_ and $_->[0] =~ /^\$/;} @{$av[1];})
!ll&&!rl&&r
11000
@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
205 110 return %$c = (cd => $av[1]) }
206 4125 ▶ if ($n =~ /^(?::|exit)\z/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($n =~ /^(?::|exit)\z/) 128 3997 4125
207 128 ▶ E("settings before '$n'", $p0) if @env;
Branch: 1 branch
BranchTrueFalseTotal
if @env 11 117 128
208 117 ▶ 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) 24 93 117
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
534024
@av > 2 or @av == 2 and !($av[1] =~ /^(?:0|[1-9][0-9]{0,2})\z/) || $av[1] > 255
l!l&&r!l&&!r
02440
@av == 2 and !($av[1] =~ /^(?:0|[1-9][0-9]{0,2})\z/) || $av[1] > 255
!ll&&!rl&&r
93124
not $av[1] =~ /^(?:0|[1-9][0-9]{0,2})\z/ or $av[1] > 255
l!l&&r!l&&!r
19531
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
209 && ($av[1] !~ /^(?:0|[1-9][0-9]{0,2})\z/ || $av[1] > 255)) } }
210 4189 ▶ $c->{env} = \@env if @env; $c->{redir} = \@r if @r;
Branch: 2 branches
BranchTrueFalseTotal
if @env 80 4109 4189
if @r 426 3763 4189
211 4189 $c }
212  
213 20251 ▶sub word { # $x: a(rgument), e(nv value), r(edirection target), b(race alternative)
Subroutine word: called CC=16 SCAR=27.8
Pod undocumented
214 20251 ▶ my $x = shift; my $p0 = pos; my @s; local $ATT = $ATT // $#OPEN;
Condition100%2/2
$Proc::ShellSubset::ATT // $#Proc::ShellSubset::OPEN
l!l
130818943
MC/DC100%1/1
$Proc::ShellSubset::ATT // $#Proc::ShellSubset::OPEN
$Proc::ShellSubset::ATT
Truth table100%2/2
A
A= $Proc::ShellSubset::ATT
Aresult
11
00
215 20251 ▶ return '[' if $x eq 'a' and /\G\[$END/gc; # '[' alone: literal
Branch: 1 branch
BranchTrueFalseTotal
if $x eq "a" and /\G\[$Proc::ShellSubset::END/cg 160 20091 20251
Condition100%3/3
$x eq "a" and /\G\[$Proc::ShellSubset::END/cg
!ll&&!rl&&r
157818513160
MC/DC100%2/2
$x eq "a" and /\G\[$Proc::ShellSubset::END/cg
$x eq "a" /\G\[$Proc::ShellSubset::END/cg
Truth table100%3/3
A and B
A= $x eq "a"B= /\G\[$Proc::ShellSubset::END/cg
ABresult
0X0
100
111
216 20091 ▶ my $ta = $x eq 'e' || $x eq 'a' && $O{tilde_args} && /\G($NM=)/gc && push @s, [u => $1]; # ~ also after '=' and ':'
Condition91%11/12
$x eq 'e' || $x eq 'a' && $Proc::ShellSubset::O{'tilde_args'} && /\G($Proc::ShellSubset::NM=)/cg && push(@s, ['u', $1])
l!l&&r!l&&!r
683219406
$x eq "a" and $Proc::ShellSubset::O{"tilde_args"} and /\G($Proc::ShellSubset::NM=)/cg and push @s, ["u", $1]
!ll&&!rl&&r
1940602
$x eq "a" and $Proc::ShellSubset::O{"tilde_args"} and /\G($Proc::ShellSubset::NM=)/cg
!ll&&!rl&&r
1940422
$x eq "a" and $Proc::ShellSubset::O{"tilde_args"}
!ll&&!rl&&r
895185094
MC/DC80%4/5
$x eq 'e' || $x eq 'a' && $Proc::ShellSubset::O{'tilde_args'} && /\G($Proc::ShellSubset::NM=)/cg && push(@s, ['u', $1])
$x eq 'e' $x eq "a" $Proc::ShellSubset::O{"tilde_args"} /\G($Proc::ShellSubset::NM=)/cg push @s, ["u", $1]
Truth table83%5/6
A || B and C and D and E
A= $x eq 'e'B= $x eq "a"C= $Proc::ShellSubset::O{"tilde_args"}D= /\G($Proc::ShellSubset::NM=)/cgE= push @s, ["u", $1]
ABCDEresult
1XXXX1
011111
00XXX0
010XX0
0110X0
011100
217 20091 ▶ my $te = $ta ? qr{(?=[/:])|$END} : qr{(?=/)|$END};
Branch: 1 branch
BranchTrueFalseTotal
$ta ? : 685 19406 20091
218 20091 my $p;
219 my %do = (
220 461 ▶ sq => sub { push @s, [q => shift] },
Subroutine __ANON__: called CC=1 SCAR=0.0
221 1153 ▶ dq => sub { push @s, [q => '']; dq(\@s, $p) },
Subroutine __ANON__: called CC=1 SCAR=0.0
222 222 ▶ 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" ? : 21 201 222
223 1983 ▶ ex => sub { push @s, [x => $EX{$_[0]}->('', $p)] }, # also in redirection targets (Q1)
Subroutine __ANON__: called CC=1 SCAR=0.0
224 369 ▶ gl => sub { $x eq 'r' and return $RLIT ? push(@s, [q => shift]) : E('pattern in a redirection target', $p);
Subroutine __ANON__: called CC=4 SCAR=13.9
Branch: 2 branches
BranchTrueFalseTotal
$x eq "r" and return $Proc::ShellSubset::RLIT ? push(@s, ["q", shift()]) : E("pattern in a redirection target", $p) 26 343 369
$Proc::ShellSubset::RLIT ? : 9 17 26
225 343 ▶ push @s, [$x eq 'e' ? 'u' : 'g', shift] },
Branch: 1 branch
BranchTrueFalseTotal
$x eq 'e' ? : 3 340 343
226 182 ▶ br => sub {
Subroutine __ANON__: called CC=10 SCAR=23.1
227 182 ▶ $x eq 'r' and return $RLIT ? push(@s, [q => '[']) : E('pattern in a redirection target', $p);
Branch: 2 branches
BranchTrueFalseTotal
$x eq "r" and return $Proc::ShellSubset::RLIT ? push(@s, ["q", "["]) : E("pattern in a redirection target", $p) 2 180 182
$Proc::ShellSubset::RLIT ? : 2 0 2
228 180 ▶ push @s, $x eq 'e' ? [u => '['] : /\G(!?\]?[^\] \t\n;&|()<>'"\\\$`{}^\/,]*\])/gc ? [g => "[$1"]
Branch: 5 branches
BranchTrueFalseTotal
$x eq 'e' ? : 0 180 180
m(\G(!?\]?[^\] \t\n;&|()<>'"\\\$`{}^/,]*\]))cg ? : 53 127 180
$Proc::ShellSubset::RLIT && m(\G\^(\]?[^\] \t\n;&|()<>'"\\\$`{}^/,]*\]))cg ? : 4 123 127
$Proc::ShellSubset::RLIT && bracket(\@s, $p) ? : 40 81 121
/\G(?:\\.|'[^']*'|"(?:[^"\\]|\\.)*"|[^ \t\n;&|()<>\\'"])*?\]/s ? : 38 43 81
Condition100%6/6
$Proc::ShellSubset::RLIT and m(\G\^(\]?[^\] \t\n;&|()<>'"\\\$`{}^/,]*\]))cg
!ll&&!rl&&r
66574
$Proc::ShellSubset::RLIT and bracket(\@s, $p)
!ll&&!rl&&r
661740
MC/DC100%2/2
$Proc::ShellSubset::RLIT and m(\G\^(\]?[^\] \t\n;&|()<>'"\\\$`{}^/,]*\]))cg
$Proc::ShellSubset::RLIT m(\G\^(\]?[^\] \t\n;&|()<>'"\\\$`{}^/,]*\]))cg
MC/DC100%2/2
$Proc::ShellSubset::RLIT and bracket(\@s, $p)
$Proc::ShellSubset::RLIT bracket(\@s, $p)
Truth table100%3/3
A and B
A= $Proc::ShellSubset::RLITB= m(\G\^(\]?[^\] \t\n;&|()<>'"\\\$`{}^/,]*\]))cg
ABresult
0X0
100
111
Truth table100%3/3
A and B
A= $Proc::ShellSubset::RLITB= bracket(\@s, $p)
ABresult
0X0
100
111
229 : $RLIT && /\G\^(\]?[^\] \t\n;&|()<>'"\\\$`{}^\/,]*\])/gc ? [g => "[^$1"] # Large: [^...] negates (rule E; the executor reads it)
230 : $RLIT && bracket(\@s, $p) ? () # Large: quotes, expansions, '/' inside (post4-0.04)
231 : /\G(?:\\.|'[^']*'|"(?:[^"\\]|\\.)*"|[^ \t\n;&|()<>\\'"])*?\]/s # a ] later in the word, past quotes
232 ? E('bracket expression with a quote, expansion or slash', $p) : [g => '['] },
233 219 ▶ cb => sub { # a '{' not followed by '}'
Subroutine __ANON__: called CC=9 SCAR=22.1
234 219 ▶ $O{brace} && $x eq 'a' or E("unquoted '{'", $p);
Branch: 1 branch
BranchTrueFalseTotal
$Proc::ShellSubset::O{"brace"} and $x eq "a" or E("unquoted '{'", $p) 12 207 219
Condition100%3/3
$Proc::ShellSubset::O{"brace"} and $x eq "a"
!ll&&!rl&&r
205212
MC/DC100%2/2
$Proc::ShellSubset::O{"brace"} and $x eq "a"
$Proc::ShellSubset::O{"brace"} $x eq "a"
Truth table100%3/3
A and B
A= $Proc::ShellSubset::O{"brace"}B= $x eq "a"
ABresult
0X0
100
111
235 12 ▶ if (/\G(-?[0-9]+|[A-Za-z])\.\.(-?[0-9]+|[A-Za-z])\}/gc) {
Branch: 1 branch
BranchTrueFalseTotal
if (/\G(-?[0-9]+|[A-Za-z])\.\.(-?[0-9]+|[A-Za-z])\}/cg) 4 8 12
236 4 my ($f, $t) = ($1, $2);
237 4 ▶ E('mixed brace sequence', $p) if $f =~ /[0-9]/ xor $t =~ /[0-9]/;
Branch: 1 branch
BranchTrueFalseTotal
if $f =~ /[0-9]/ xor $t =~ /[0-9]/ 2 2 4
Condition50%2/4
$f =~ /[0-9]/ xor $t =~ /[0-9]/
l&&rl&&!r!l&&r!l&&!r
2200
MC/DC50%1/2
$f =~ /[0-9]/ xor $t =~ /[0-9]/
$f =~ /[0-9]/ $t =~ /[0-9]/
Truth table50%2/4
A xor B
A= $f =~ /[0-9]/B= $t =~ /[0-9]/
ABresult
110
101
011
000
238 2 return push @s, [x => ['{..', $f, $t]] }
239 8 ▶ my @alt; do { push @alt, word('b') } while /\G,/gc;
Branch: 1 branch
BranchTrueFalseTotal
/\G,/cg and do { do { push @alt, word("b") } } 8 6 14
240 6 ▶ /\G\}/gc && @alt > 1 or E('unsupported brace form', $p);
Branch: 1 branch
BranchTrueFalseTotal
/\G\}/cg and @alt > 1 or E("unsupported brace form", $p) 4 2 6
Condition66%2/3
/\G\}/cg and @alt > 1
!ll&&!rl&&r
024
MC/DC50%1/2
/\G\}/cg and @alt > 1
/\G\}/cg @alt > 1
Truth table66%2/3
A and B
A= /\G\}/cgB= @alt > 1
ABresult
0X0
100
111
241 4 push @s, [x => ['{', @alt]] },
242 187 ▶ ti => sub { # ~ at the start of the word, and with $ta after the NAME= of an argument or an unquoted ':'
Subroutine __ANON__: called CC=12 SCAR=25.5
243 187 ▶ return push @s, [u => '~'] if @s && !($ta && $s[-1][0] eq 'u' && ($s[-1][1] =~ /:\z/ || @s == 1 && $x eq 'a'));
Branch: 1 branch
BranchTrueFalseTotal
if @s and not $ta && $s[-1][0] eq "u" && ($s[-1][1] =~ /:\z/ || @s == 1 && $x eq "a") 31 156 187
Condition93%14/15
@s and not $ta && $s[-1][0] eq "u" && ($s[-1][1] =~ /:\z/ || @s == 1 && $x eq "a")
!ll&&!rl&&r
1431331
$ta && $s[-1][0] eq 'u' && ($s[-1][1] =~ /:\z/ || @s == 1 && $x eq 'a')
!ll&&!rl&&r
30113
$ta and $s[-1][0] eq "u"
!ll&&!rl&&r
28214
$s[-1][1] =~ /:\z/ or @s == 1 and $x eq "a"
l!l&&r!l&&!r
1121
@s == 1 and $x eq "a"
!ll&&!rl&&r
012
MC/DC83%5/6
@s and not $ta && $s[-1][0] eq "u" && ($s[-1][1] =~ /:\z/ || @s == 1 && $x eq "a")
@s $ta $s[-1][0] eq "u" $s[-1][1] =~ /:\z/ @s == 1 $x eq "a"
Truth table85%6/7
A and not(B and C && D or E and F)
A= @sB= $taC= $s[-1][0] eq "u"D= $s[-1][1] =~ /:\z/E= @s == 1F= $x eq "a"
ABCDEFresult
0XXXXX0
1111XX0
1110110
10XXXX1
110XXX1
11100X1
1110101
244 156 ▶ E('~ in a brace alternative', $p) if $x eq 'b';
Branch: 1 branch
BranchTrueFalseTotal
if $x eq "b" 0 156 156
245 156 ▶ /\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) 138 18 156
246 138 ▶ E('~ without HOME', $p) if $1 eq '' && !defined $ENV{HOME} && !$Proc::ShellSubset::TILDEPW;
Branch: 1 branch
BranchTrueFalseTotal
if $1 eq "" and not defined $ENV{"HOME"} and not $Proc::ShellSubset::TILDEPW 0 138 138
Condition50%3/6
$1 eq "" and not defined $ENV{"HOME"} and not $Proc::ShellSubset::TILDEPW
!ll&&!rl&&r
13800
$1 eq "" and not defined $ENV{"HOME"}
!ll&&!rl&&r
161220
MC/DC0%0/3
$1 eq "" and not defined $ENV{"HOME"} and not $Proc::ShellSubset::TILDEPW
$1 eq "" not defined $ENV{"HOME"} not $Proc::ShellSubset::TILDEPW
Truth table50%2/4
A and not(B) and not(C)
A= $1 eq ""B= not defined $ENV{"HOME"}C= not $Proc::ShellSubset::TILDEPW
ABCresult
0XX0
10X0
1100
1111
247 138 push @s, [x => ['~', $1]] },
248 88 ▶ ca => sub { E("unquoted '^'", $p) if $O{nocaret}; push @s, [u => '^'] }, # ordinary unless nocaret (C3)
Subroutine __ANON__: called CC=2 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
if $Proc::ShellSubset::O{"nocaret"} 4 84 88
249 16584 ▶ lit => sub { push @s, [u => shift] },
Subroutine __ANON__: called CC=1 SCAR=0.0
250 66 ▶ bad => sub { E({"'" => 'unterminated quote', '\\' => 'final backslash', '}' => "unquoted '}'"}->{$_[0]}
Subroutine __ANON__: called CC=2 SCAR=6.9
Condition100%2/2
{"'", "unterminated quote", "\\", "final backslash", "}", "unquoted '}'"}->{$_[0]} // sprintf("control character \\x%02x", ord shift())
l!l
606
MC/DC100%1/1
{"'", "unterminated quote", "\\", "final backslash", "}", "unquoted '}'"}->{$_[0]} // sprintf("control character \\x%02x", ord shift())
{"'", "unterminated quote", "\\", "final backslash", "}", "unquoted '}'"}->{$_[0]}
Truth table100%2/2
A
A= {"'", "unterminated quote", "\\", "final backslash", "}", "unquoted '}'"}->{$_[0]}
Aresult
11
00
251 20091 // sprintf('control character \\x%02x', ord shift), $p) });
252 20091 ▶ until (/$STOP{$x}/) { $p = pos; /$PIECE/gc; my ($k, $v) = %+; $do{$k}($v) }
Branch: 1 branch
BranchTrueFalseTotal
unless (/$Proc::ShellSubset::STOP{$x}/) 21514 18866 40380
253 18866 ▶ @s or $x =~ /[eb]/ or E('missing word', $p0);
Branch: 1 branch
BranchTrueFalseTotal
@s or $x =~ /[eb]/ or E("missing word", $p0) 18786 80 18866
Condition100%3/3
@s or $x =~ /[eb]/
l!l&&r!l&&!r
187335380
MC/DC100%2/2
@s or $x =~ /[eb]/
@s $x =~ /[eb]/
Truth table100%3/3
A or B
A= @sB= $x =~ /[eb]/
ABresult
1X1
011
000
254 18786 my $k = join '', map $$_[0], @s; my @v; # kinds: u(nquoted) q(uoted) g(lob char) x(pansion)
255 18786 ▶ 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] } 21470 18786 40256
defined $1 ? : 437 21033 21470
256 while $k =~ /([ug]*g[ug]*)|./g; # unquoted text next to a pattern character joins it
257 18786 ▶ dots(@v) and E("pattern that may match '.' or '..'", $p0) unless $RLIT; # dash: yes, bash 5.2: no (U2); Large: never (rule E)
Branch: 1 branch
BranchTrueFalseTotal
unless $Proc::ShellSubset::RLIT 14020 4766 18786
Condition66%4/6
$Proc::ShellSubset::RLIT || dots(@v) && E(q[pattern that may match '.' or '..'], $p0)
l!l
4766140200
dots(@v) and E("pattern that may match '.' or '..'", $p0)
!ll
13992280
MC/DC0%0/3
$Proc::ShellSubset::RLIT || dots(@v) && E(q[pattern that may match '.' or '..'], $p0)
$Proc::ShellSubset::RLIT dots(@v) E("pattern that may match '.' or '..'", $p0)
Truth table0%0/4
A || B and C
A= $Proc::ShellSubset::RLITB= dots(@v)C= E("pattern that may match '.' or '..'", $p0)
ABCresult
1XX1
0111
00X0
0100
258 18758 mkword(@v) }
259  
260 62 ▶sub bracket { # Large, after '[' (post4-0.04): a bracket expression with quoted members, expansions or '/', as both
Subroutine bracket: called CC=12 SCAR=24.9
Pod undocumented
261 62 my ($s, $p, $xq) = @_; my $p0 = pos; my @b = [g => '[']; # shells: quoted characters are members, not operators;
262 62 ▶ push @b, [g => $1] if /\G([!^])/gc; # an unquoted expansion's characters are active. Pushes its
Branch: 1 branch
BranchTrueFalseTotal
if /\G([!^])/cg 7 55 62
263 62 ▶ push @b, [g => ']'] if /\G\]/gc; # Parts on @$s and returns 1; or 0 with pos unchanged, if
Branch: 1 branch
BranchTrueFalseTotal
if /\G\]/cg 0 62 62
264 62 ▶ until (/\G\]/gc) { # the word ends first (then the '[' is literal)
Branch: 1 branch
BranchTrueFalseTotal
unless (/\G\]/cg) 85 45 130
265 85 my $q = pos;
266 0 ▶ if (/\G(\[:[a-z]+:\])/gc) { push @b, [g => $1] }
Branch: 7 branches
BranchTrueFalseTotal
if (/\G(\[:[a-z]+:\])/cg) { } 0 85 85
elsif (/\G([^\] \t\n;&|()<>'"\\\$`{}^,\[\x00-\x1f\x7f]+|\[)/cg) { } 24 61 85
elsif (/\G'([^']*)'/cg) { } 3 58 61
elsif (/\G\\([^\n])/cg) { } 12 46 58
elsif (/\G"/cg) { } 16 30 46
elsif (/\G([\$`])/cg) { } 13 17 30
elsif (/\G[{}^,]/) { } 2 15 17
267 24 elsif (/\G([^\] \t\n;&|()<>'"\\\$`{}^,\[\x00-\x1f\x7f]+|\[)/gc) { push @b, [g => $1] }
268 3 elsif (/\G'([^']*)'/gc) { push @b, [q => $1] }
269 12 elsif (/\G\\([^\n])/gc) { push @b, [q => $1] }
270 16 elsif (/\G"/gc) { push @b, [q => '']; dq(\@b, $q) }
271 13 ▶ elsif (/\G([\$`])/gc) { push @b, [x => $EX{$1}->($xq // '', $q)] } # $xq: inside "${...}"
Condition100%2/2
$xq // ""
l!l
211
MC/DC100%1/1
$xq // ""
$xq
Truth table100%2/2
A
A= $xq
Aresult
11
00
272 2 elsif (/\G[{}^,]/) { E('bracket expression with a quote, expansion or slash', $p) }
273 15 else { pos = $p0; return 0 } }
274 45 push @$s, @b, [g => ']']; 1 }
275  
276 14020 ▶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
277 14020 my ($re, $g) = ('', 0); # the component so far as a regex (only the character '.' matters); has it a pattern?
278 14020 for my $x (@_, '/') { # literal text and patterns, split at '/'; an expansion is taken to match no '.'
279 29898 ▶ for (ref $x ? $$x[0] eq '*' ? map [g => $_], split m{(/)}, $$x[1] : [x => ''] : map [l => $_], split m{(/)}, $x) {
Branch: 2 branches
BranchTrueFalseTotal
ref $x ? : 1652 28246 29898
$x->[0] eq '*' ? : 314 1338 1652
280 45974 my ($k, $v) = @$_;
281 45974 ▶ 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 '/') { } 15501 30473 45974
elsif ($k eq 'l') { } 28719 1754 30473
elsif ($k eq 'x') { } 1338 416 1754
if $g and $re =~ /^\\\./ and grep /^$re\z/, ".", ".." 28 15473 15501
Condition100%6/6
$g and $re =~ /^\\\./ and grep /^$re\z/, ".", ".."
!ll&&!rl&&r
154452828
$g and $re =~ /^\\\./
!ll&&!rl&&r
1519325256
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
282 28719 elsif ($k eq 'l') { $re .= quotemeta $v }
283 1338 elsif ($k eq 'x') { $re .= '(?!)' }
284 416 ▶ else { $g ||= $v =~ /[*?[]/; $re .= $v =~ s{\[(!?)(\]?[^\]]*)\]|([*?])|(.)}{ # a bracket expression: can it match '.'?
Condition100%3/3
$g ||= $v =~ /[*?[]/
l!l&&r!l&&!r
930899
MC/DC100%2/2
$g ||= $v =~ /[*?[]/
$g $v =~ /[*?[]/
Truth table100%3/3
A ||= B
A= $gB= $v =~ /[*?[]/
ABresult
1X1
011
000
285 1370 ▶ defined $2 ? (($1 ? $2 !~ /\./ : $2 =~ /[.\-]|\[:/) ? q{[.]} : q{(?!)}) : defined $3 ? ($3 eq '*' ? '.*' : '.') : quotemeta $4}gesr } } }
Branch: 5 branches
BranchTrueFalseTotal
defined $2 ? : 43 1327 1370
($1 ? !($2 =~ /\./) : $2 =~ /[.\-]|\[:/) ? : 24 19 43
$1 ? : 11 32 43
defined $3 ? : 296 1031 1327
$3 eq '*' ? : 273 23 296
286 13992 0 }
287  
288 18955 ▶sub mkword { # a Word from Parts: adjacent strings joined, a lone string bare, nothing ''
Subroutine mkword: called CC=8 SCAR=20.8
Pod undocumented
289 18955 ▶ my @w; !ref && @w && !ref $w[-1] ? $w[-1] .= $_ : push @w, $_ for @_;
Branch: 1 branch
BranchTrueFalseTotal
!ref($_) && @w && !ref($w[-1]) ? : 1458 20232 21690
Condition100%6/6
not ref $_ and @w and not ref $w[-1]
!ll&&!rl&&r
197994331458
not ref $_ and @w
!ll&&!rl&&r
2530172691891
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
290 18955 ▶ @w == 1 && !ref $w[0] ? $w[0] : @w ? \@w : '' }
Branch: 2 branches
BranchTrueFalseTotal
@w == 1 && !ref($w[0]) ? : 16597 2358 18955
@w ? : 2297 61 2358
Condition100%3/3
@w == 1 and not ref $w[0]
!ll&&!rl&&r
982137616597
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
291  
292 1186 ▶sub dq { # after '"', up to the closing '"'
Subroutine dq: called CC=5 SCAR=16.1
Pod undocumented
293 1186 my ($s, $p) = @_;
294 1186 ▶ until (/\G"/gc) {
Branch: 1 branch
BranchTrueFalseTotal
unless (/\G"/cg) 2081 1007 3088
295 2081 ▶ next if /\G\\\n/gc;
Branch: 1 branch
BranchTrueFalseTotal
if /\G\\\n/cg 3 2078 2081
296 2078 ▶ if (/\G(?:([^"\\\$`]+)|\\([\$`"\\])|(\\))/gc) { push @$s, [q => $+] }
Branch: 2 branches
BranchTrueFalseTotal
if (/\G(?:([^"\\\$`]+)|\\([\$`"\\])|(\\))/cg) { } 1212 866 2078
elsif (/\G([\$`])/cg) { } 851 15 866
297 851 elsif (/\G([\$`])/gc) { push @$s, [x => $EX{$1}->('"', pos() - 1)] }
298 15 else { E('unterminated double quote', $p) } } }
299  
300 1867 ▶sub dollar { # after '$'; $q is '"' inside double quotes
Subroutine dollar: called CC=19 SCAR=29.4
Pod undocumented
301 1867 my ($q, $p) = @_;
302 1867 ▶ 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['"]/ 84 1783 1867
Condition100%6/6
/\G[A-Za-z_0-9{(\@*#?\$!\[-]/ or not $q and /\G['"]/
l!l&&r!l&&!r
17731084
not $q and /\G['"]/
!ll&&!rl&&r
493510
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
303 1783 ▶ return [$q . '$((', arith($p)] if /\G\(\(/gc;
Branch: 1 branch
BranchTrueFalseTotal
if /\G\(\(/cg 141 1642 1783
304 1642 ▶ if (/\G\(/gc) { my $l = shell(')', []); /\G\)/gc; return [$q . '$(', $l] }
Branch: 1 branch
BranchTrueFalseTotal
if (/\G\(/cg) 312 1330 1642
305 1330 ▶ return [$q . '$', name("$1", $p)] if /\G(?|\{($NM|[?!])\}|($NM|[?!]))/gc; # $? and $! (corpus-round C6)
Branch: 1 branch
BranchTrueFalseTotal
if /\G(?|\{($Proc::ShellSubset::NM|[?!])\}|($Proc::ShellSubset::NM|[?!]))/cg 814 516 1330
306 516 ▶ if ($O{param_ops}) { # (C7)
Branch: 1 branch
BranchTrueFalseTotal
if ($Proc::ShellSubset::O{"param_ops"}) 302 214 516
307 302 ▶ return [$q . '${#', name("$1", $p)] if /\G\{#($NM)\}/gc;
Branch: 1 branch
BranchTrueFalseTotal
if /\G\{#($Proc::ShellSubset::NM)\}/cg 5 297 302
308 297 ▶ if (/\G\{($NM)(:?[-+])/gc) {
Branch: 1 branch
BranchTrueFalseTotal
if (/\G\{($Proc::ShellSubset::NM)(:?[-+])/cg) 55 242 297
309 55 my ($n, $op, @w) = ($1, $2); name($n, $p);
310 55 ▶ until (/\G\}/gc) {
Branch: 1 branch
BranchTrueFalseTotal
unless (/\G\}/cg) 61 27 88
311 61 ▶ if (/\G([^"'\\~*?\[{}\$`\n]+)/gc) { push @w, $1 }
Branch: 2 branches
BranchTrueFalseTotal
if (/\G([^"'\\~*?\[{}\$`\n]+)/cg) { } 23 38 61
elsif (/\G([\$`])/cg) { } 15 23 38
312 15 elsif (/\G([\$`])/gc) { my $x = $1; # \" in `...` inside "${...}": " in bash, \" in dash (U3)
313 15 ▶ E('\\" in backquotes inside "${...}"', pos() - 1) if $x eq '`' && $q && /\G((?:[^`\\]|\\.)*)/s && $1 =~ /\\"/;
Branch: 1 branch
BranchTrueFalseTotal
if $x eq "`" and $q and /\G((?:[^`\\]|\\.)*)/s and $1 =~ /\\"/ 5 10 15
Condition88%8/9
$x eq "`" and $q and /\G((?:[^`\\]|\\.)*)/s and $1 =~ /\\"/
!ll&&!rl&&r
825
$x eq "`" and $q and /\G((?:[^`\\]|\\.)*)/s
!ll&&!rl&&r
807
$x eq "`" and $q
!ll&&!rl&&r
447
MC/DC75%3/4
$x eq "`" and $q and /\G((?:[^`\\]|\\.)*)/s and $1 =~ /\\"/
$x eq "`" $q /\G((?:[^`\\]|\\.)*)/s $1 =~ /\\"/
Truth table80%4/5
A and B and C and D
A= $x eq "`"B= $qC= /\G((?:[^`\\]|\\.)*)/sD= $1 =~ /\\"/
ABCDresult
0XXX0
10XX0
110X0
11100
11111
314 10 push @w, $EX{$x}->($q, pos() - 1) }
315 23 ▶ else { E(/\G\z/ ? "unterminated '\${'" : "unsupported character in '\${$n$op...}'", pos) } }
Branch: 1 branch
BranchTrueFalseTotal
/\G\z/ ? : 3 20 23
316 27 return [$q . '${', $n, $op, mkword(@w)] } }
317 456 ▶ E(/\G['"\[]/ ? 'bash-only $ form' : 'unsupported parameter form', $p) }
Branch: 1 branch
BranchTrueFalseTotal
/\G['"\[]/ ? : 28 428 456
318  
319 2362 ▶sub name {
Subroutine name: called CC=7 SCAR=19.5
Pod undocumented
320 2362 my ($n, $p) = @_;
321 E("shell-set variable '$n'", $p) if $SH{$n} || $n eq 'PWD' && $O{nopwd} || $n =~ /^(?:BASH|COMP|READLINE)_/
322 2362 ▶ || $n =~ /^(?:PATH|SHELL|TERM|HOSTNAME)\z/ && !defined $ENV{$n};
Branch: 1 branch
BranchTrueFalseTotal
if $Proc::ShellSubset::SH{$n} or $n eq "PWD" and $Proc::ShellSubset::O{"nopwd"} or $n =~ /^(?:BASH|COMP|READLINE)_/ or $n =~ /^(?:PATH|SHELL|TERM|HOSTNAME)\z/ and not defined $ENV{$n} 65 2297 2362
Condition86%13/15
$Proc::ShellSubset::SH{$n} or $n eq "PWD" and $Proc::ShellSubset::O{"nopwd"} or $n =~ /^(?:BASH|COMP|READLINE)_/ or $n =~ /^(?:PATH|SHELL|TERM|HOSTNAME)\z/ and not defined $ENV{$n}
l!l&&r!l&&!r
6502297
$Proc::ShellSubset::SH{$n} or $n eq "PWD" and $Proc::ShellSubset::O{"nopwd"} or $n =~ /^(?:BASH|COMP|READLINE)_/
l!l&&r!l&&!r
6052297
$Proc::ShellSubset::SH{$n} or $n eq "PWD" and $Proc::ShellSubset::O{"nopwd"}
l!l&&r!l&&!r
5642302
$n eq "PWD" and $Proc::ShellSubset::O{"nopwd"}
!ll&&!rl&&r
2288144
$n =~ /^(?:PATH|SHELL|TERM|HOSTNAME)\z/ and not defined $ENV{$n}
!ll&&!rl&&r
229160
MC/DC66%4/6
$Proc::ShellSubset::SH{$n} or $n eq "PWD" and $Proc::ShellSubset::O{"nopwd"} or $n =~ /^(?:BASH|COMP|READLINE)_/ or $n =~ /^(?:PATH|SHELL|TERM|HOSTNAME)\z/ and not defined $ENV{$n}
$Proc::ShellSubset::SH{$n} $n eq "PWD" $Proc::ShellSubset::O{"nopwd"} $n =~ /^(?:BASH|COMP|READLINE)_/ $n =~ /^(?:PATH|SHELL|TERM|HOSTNAME)\z/ not defined $ENV{$n}
Truth table60%6/10
A or B and C or D or E and not(F)
A= $Proc::ShellSubset::SH{$n}B= $n eq "PWD"C= $Proc::ShellSubset::O{"nopwd"}D= $n =~ /^(?:BASH|COMP|READLINE)_/E= $n =~ /^(?:PATH|SHELL|TERM|HOSTNAME)\z/F= not defined $ENV{$n}
ABCDEFresult
1XXXXX1
011XXX1
00X1XX1
0101XX1
00X0111
0100111
00X00X0
00X0100
01000X0
0100100
323 2297 $n }
324  
325 141 ▶sub arith { # after '$((': check the expression by its grammar, return its text
Subroutine arith: called CC=4 SCAR=13.9
Pod undocumented
326 141 my $p = shift;
327 141 ▶ /\G((?&e))(?&w)\)\)$ARITH/gc && $1 !~ /\+\+|--/ or E('bad arithmetic expression', $p);
Branch: 1 branch
BranchTrueFalseTotal
/\G((?&e))(?&w)\)\)$Proc::ShellSubset::ARITH/cg and not $1 =~ /\+\+|--/ or E("bad arithmetic expression", $p) 72 69 141
Condition100%3/3
/\G((?&e))(?&w)\)\)$Proc::ShellSubset::ARITH/cg and not $1 =~ /\+\+|--/
!ll&&!rl&&r
65472
MC/DC100%2/2
/\G((?&e))(?&w)\)\)$Proc::ShellSubset::ARITH/cg and not $1 =~ /\+\+|--/
/\G((?&e))(?&w)\)\)$Proc::ShellSubset::ARITH/cg not $1 =~ /\+\+|--/
Truth table100%3/3
A and not(B)
A= /\G((?&e))(?&w)\)\)$Proc::ShellSubset::ARITH/cgB= not $1 =~ /\+\+|--/
ABresult
0X0
100
111
328 72 ▶ my $t = $1; name("$1", $p) while $t =~ /\b($NM)/g;
Branch: 1 branch
BranchTrueFalseTotal
$t =~ /\b($Proc::ShellSubset::NM)/g and do { name("$1", $p) } 23 72 95
329 72 $t }
330  
331 202 ▶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
332 202 my ($q, $p) = @_; my $s = pos;
333 202 ▶ /\G((?:[^`\\]|\\.)*)`/sgc or E('unterminated backquote', $p);
Branch: 1 branch
BranchTrueFalseTotal
/\G((?:[^`\\]|\\.)*)`/cgs or E("unterminated backquote", $p) 191 11 202
334 191 my ($raw, $in, @m) = ($1, '');
335 191 ▶ while ($raw =~ /\\([\$`\\$q])|(\\\n)|(.)/sg) { # a backslash escapes $ ` \ and, inside double quotes, "
Branch: 1 branch
BranchTrueFalseTotal
if ($raw =~ /\\([\$`\\$q])|(\\\n)|(.)/gs) 1945 187 2132
336 1945 ▶ E('backslash-newline inside backquotes', $s + $-[0]) if defined $2;
Branch: 1 branch
BranchTrueFalseTotal
if defined $2 4 1941 1945
337 1941 $in .= $+; push @m, P($s + $-[$#-]) }
338 187 push @m, P(pos() - 1);
339 187 [$q . '$(', do { local $_ = $in; local $M = \@m; shell('', []) }] }
340  
341 2629 ▶sub xc { # B3: 'exec' only where nothing can follow it in the shell (or subshell) it replaces
Subroutine xc: called CC=20 SCAR=30.0
Pod undocumented
342 2629 my ($l, $ok) = @_; # $ok: nothing follows this list in its shell
343 2629 for my $ch (@$l) { my @p = grep ref, @$ch;
344 3114 for my $pl (@p) { my @c = grep ref, @$pl;
345 3377 ▶ 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
5611941875
$pl == $p[-1] and $pl->[0] ne "!" and $ch->[-1] eq "&" || $ok && $ch == $l->[-1]
!ll&&!rl&&r
2875881941
$pl == $p[-1] and $pl->[0] ne "!"
!ll&&!rl&&r
252352529
$ch->[-1] eq "&" or $ok and $ch == $l->[-1]
l!l&&r!l&&!r
621879588
$ok and $ch == $l->[-1]
!ll&&!rl&&r
1354531879
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
346 || $pl == $p[-1] && $pl->[0] ne '!' && ($ch->[-1] eq '&' || $ok && $ch == $l->[-1]);
347 3377 for my $x (@c) { # a loop's condition and body, and an if's conditions, are followed by more of the loop or if
348 4214 ▶ xc($x->{group}, $last) if $x->{group};
Branch: 1 branch
BranchTrueFalseTotal
if $x->{"group"} 110 4104 4214
349 4197 ▶ if (my $arms = $x->{if}) { xc($arms->[$_], $_ % 2 || @$arms % 2 && $_ == $#$arms ? $last : 0) for 0 .. $#$arms }
Branch: 2 branches
BranchTrueFalseTotal
if (my $arms = $x->{"if"}) 16 4181 4197
$_ % 2 || @$arms % 2 && $_ == $arms->$#* ? : 21 19 40
Condition100%6/6
$_ % 2 or @$arms % 2 and $_ == $arms->$#*
l!l&&r!l&&!r
16519
@$arms % 2 and $_ == $arms->$#*
!ll&&!rl&&r
1185
MC/DC100%3/3
$_ % 2 or @$arms % 2 and $_ == $arms->$#*
$_ % 2 @$arms % 2 $_ == $arms->$#*
Truth table100%4/4
A or B and C
A= $_ % 2B= @$arms % 2C= $_ == $arms->$#*
ABCresult
1XX1
0111
00X0
0100
350 4194 xc($x->{$_}, 0) for grep $x->{$_}, qw(while until do);
351 4191 ▶ if (exists $x->{case}) { xc($_, $last) for pairvalues @{$x->{in}} }
Branch: 1 branch
BranchTrueFalseTotal
if (exists $x->{"case"}) 22 4169 4191
352 4191 ▶ if (exists $x->{exec}) { my $xp = $x->{exec}; $x->{exec} = 1;
Branch: 1 branch
BranchTrueFalseTotal
if (exists $x->{"exec"}) 99 4092 4191
353 99 ▶ $x->{ERROR} = 1, die ["'exec' with something after it", $xp] if !$last } } } } }
Branch: 1 branch
BranchTrueFalseTotal
unless $last 45 54 99
354  
355 534 1;
356 __END__
« lib/Proc/ShellSpawn.pm ↑ Summary lib/Proc/ShellSpawn/Programs.pm »