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 487 our $VERSION = '0.11';
3 487 ▶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 487 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 487 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 487 our %KW = map +($_ => 1), qw(if then else elif fi case esac for while until do done in [[ ]] function select coproc !);
42 487 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 487 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 487 our $NM = qr/[A-Za-z_][A-Za-z0-9_]*/;
50 487 our $END = qr/(?=[ \t\n;&|()<>]|\z)/;
51 487 our $B = qr/(?:[ \t]|\\\n|#.*)*+/; # blanks, line continuations, a comment
52 487 our $BN = qr/(?:[ \t\n]|\\\n|#.*)*+/; # the same, and newlines
53 487 our %STOP = (b => qr/\G(?:(?=[,}])|$END)/, map +($_ => qr/\G$END/), qw(a e r));
54 487 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 487 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 2604 ▶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 4187 ▶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 4053 4187
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 2637 ▶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 2608 29 2637
Condition100%2/2
$Proc::ShellSubset::ATT // -1
l!l
12421366
MC/DC100%1/1
$Proc::ShellSubset::ATT // -1
$Proc::ShellSubset::ATT
Truth table100%2/2
A
A= $Proc::ShellSubset::ATT
Aresult
11
00
68 239 ▶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 ? : 219 20 239
$1 eq "\n" ? : 0 219 219
69 5213 ▶sub parse {
Subroutine parse: called CC=9 SCAR=22.3
Pod undocumented
70 5213 my $s = shift; local %O = @_; local ($M, @OPEN, $ATT); local $LAST = 0; my @l;
71 5213 my $t = eval {
72 5213 local $_ = $s;
73 5213 ▶ E('NUL character', $-[0]) if /\0/;
Branch: 1 branch
BranchTrueFalseTotal
if /\0/ 1 5212 5213
74 5212 ▶ 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 5196 5212
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 5196 5196
Condition33%1/3
$Proc::ShellSubset::O{"check"} and my $why = $Proc::ShellSubset::O{"check"}->($s)
!ll&&!rl&&r
519600
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 5196 shell('', \@l);
77 2543 ▶ @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) 2531 12 2543
Condition100%3/3
@l or $Proc::ShellSubset::O{"empty"}
l!l&&r!l&&!r
25171412
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 5213 ▶ $t // (ref $@ eq 'ARRAY' ? { error => $@->[0], pos => $@->[1], last => $LAST, tree => \@l } : die $@) }
Branch: 1 branch
BranchTrueFalseTotal
ref $@ eq 'ARRAY' ? : 2682 0 2682
Condition100%2/2
$t // (ref $@ eq "ARRAY" ? {"error", $@->[0], "pos", $@->[1], "last", $Proc::ShellSubset::LAST, "tree", \@l} : die($@))
l!l
25312682
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 6454 ▶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 6454 ▶ 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
10711875196
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 6454 ▶ 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 6406 6454
$t eq ')' ? : 549 5857 6406
$t ? : 474 5383 5857
83 6454 ▶ 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/) 7856 560 8416
84 7856 push @$l, my $c = []; andor($c);
85 5241 ▶ if (/\G$B&(?!&)/gc) { push @$c, '&' }
Branch: 2 branches
BranchTrueFalseTotal
if (/\G$Proc::ShellSubset::B&(?!&)/cg) { } 155 5086 5241
elsif (not /\G$Proc::ShellSubset::B(?:;(?!;)|\n)/cg) { } 3271 1815 5086
86 3271 ▶ elsif (!/\G$B(?:;(?!;)|\n)/gc) { /\G$B/gc, /$e/ ? last : U() }
Branch: 1 branch
BranchTrueFalseTotal
/$e/ ? : 3038 233 3271
87 1970 ▶ $LAST = pos if $top;
Branch: 1 branch
BranchTrueFalseTotal
if $top 1302 668 1970
88 1970 ▶ 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 1962 1970
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
196208
$top and $Proc::ShellSubset::CUT and substr($_, pos($_) - 1, 1) eq "\n"
!ll&&!rl&&r
195758
$top and $Proc::ShellSubset::CUT
!ll&&!rl&&r
668128913
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 3606 $l }
92  
93 5932 ▶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 5932 local $LOOP = 0; my $l = list(@_); xc($l, 1); $l }
95  
96 7856 ▶sub andor {
Subroutine andor: called CC=3 SCAR=11.0
Pod undocumented
97 7856 my $ao = shift; local $OPEN[@OPEN] = $ao;
98 7856 ▶ 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) } } 349 5241 5590
Condition66%2/3
/\G$Proc::ShellSubset::B(&&|\|\|)$Proc::ShellSubset::BN/cg and push @$ao, $1
!ll&&!rl&&r
52410349
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 8205 ▶sub pipeline {
Subroutine pipeline: called CC=10 SCAR=23.0
Pod undocumented
101 8205 my $p = shift; local $OPEN[@OPEN] = $p;
102 8205 ▶ push @$p, '!' if /\G!(?=[ \t])$B/gc;
Branch: 1 branch
BranchTrueFalseTotal
if /\G!(?=[ \t])$Proc::ShellSubset::B/cg 57 8148 8205
103 8205 ▶ E("'! !'", pos) if @$p && /\G!$END/;
Branch: 1 branch
BranchTrueFalseTotal
if @$p and /\G!$Proc::ShellSubset::END/ 11 8194 8205
Condition100%3/3
@$p and /\G!$Proc::ShellSubset::END/
!ll&&!rl&&r
81484611
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 8194 ▶ 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) } } 1001 5594 6595
105 5594 my ($q, @c) = (pos, grep ref, @$p); # each element of a longer pipeline is a subshell: break/continue can't reach the loop
106 5594 ▶ @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 6521 6525
Condition100%8/8
@c > 1 and ($_->{"argv"} && $_->{"argv"}[0] // "") =~ /^(?:break|continue)\z/
!ll&&!rl&&r
495715644
$_->{"argv"} && $_->{"argv"}[0] // ""
l!l
1449119
$_->{"argv"} and $_->{"argv"}[0]
!ll&&!rl&&r
11661446
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 539 ▶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 102 ▶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 102 ▶ 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) 87 4 91
111 104 ▶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 104 my ($c, $p) = @_; local $LOOP = $LOOP + 1;
113 104 ▶ 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) 83 0 83
114 250 ▶sub vname { # a variable the string sets: by assignment (C5), for or read
Subroutine vname: called CC=2 SCAR=6.9
Pod undocumented
115 250 ▶ 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/ 12 238 250
116  
117 8770 ▶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 8770 my ($pl, $p) = @_; my $c;
119 8770 ▶ if ($O{if} && /\Gif$END/gc) {
Branch: 4 branches
BranchTrueFalseTotal
if ($Proc::ShellSubset::O{'if'} and /\Gif$Proc::ShellSubset::END/cg) { } 50 8720 8770
elsif ($Proc::ShellSubset::O{'while'} and /\G(while|until)$Proc::ShellSubset::END/cg) { } 50 8670 8720
elsif ($Proc::ShellSubset::O{'for'} and /\Gfor$Proc::ShellSubset::END/cg) { } 81 8589 8670
elsif ($Proc::ShellSubset::O{'case'} and /\Gcase$Proc::ShellSubset::END/cg) { } 47 11542 11589
Condition100%3/3
$Proc::ShellSubset::O{"if"} and /\Gif$Proc::ShellSubset::END/cg
!ll&&!rl&&r
3000572050
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 50 push @$pl, $c = { if => my $arms = [] };
121 50 ▶ 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 35 38
122 35 ▶ part($arms, 'fi', "'else' part", $p) if kw('else');
Branch: 1 branch
BranchTrueFalseTotal
if kw("else") 5 30 35
123 35 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
2998567250
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 50 push @$pl, $c = { $1 => my $cond = [], do => [] };
126 50 ▶ list('do', $cond); @$cond or E('empty condition', $p); kw('do'); body($c, $p) }
Branch: 1 branch
BranchTrueFalseTotal
@$cond or E("empty condition", $p) 48 0 48
127 ▶ elsif ($O{for} && /\Gfor$END/gc) {
Condition100%3/3
$Proc::ShellSubset::O{"for"} and /\Gfor$Proc::ShellSubset::END/cg
!ll&&!rl&&r
3010557981
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
3000554247
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 8693 $c }
143  
144 9181 ▶sub command { # pushes the command onto the pipeline @{$_[0]}
Subroutine command: called CC=9 SCAR=22.0
Pod undocumented
145 9181 my $pl = shift; my $p = pos; my $c;
146 9181 ▶ E("'((' at the start of a command", $p) if /\G\(\(/;
Branch: 1 branch
BranchTrueFalseTotal
if /\G\(\(/ 16 9165 9181
147 9165 ▶ if (/\G\(/gc) {
Branch: 2 branches
BranchTrueFalseTotal
if (/\G\(/cg) { } 177 8988 9165
elsif (/\G\{(?=[ \t\n])/cg) { } 218 8770 8988
148 177 push @$pl, $c = { sub => my $l = [] };
149 177 ▶ shell(')', $l); /\G\)/gc; @$l or E('empty subshell', $p) }
Branch: 1 branch
BranchTrueFalseTotal
@$l or E("empty subshell", $p) 142 8 150
150 elsif (/\G\{(?=[ \t\n])/gc) {
151 218 push @$pl, $c = { group => my $l = [] };
152 218 ▶ list('\}', $l); /\G\}/gc; @$l or E('empty group', $p) } # xc: by the parent
Branch: 1 branch
BranchTrueFalseTotal
@$l or E("empty group", $p) 186 1 187
153 8770 ▶ else { $c = compound($pl, $p) or return simple($pl) }
Branch: 1 branch
BranchTrueFalseTotal
$c = compound($pl, $p) or return simple($pl) 151 8542 8693
154 479 ▶ 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 476 559
155 476 ▶ $c->{redir} = \@r if @r;
Branch: 1 branch
BranchTrueFalseTotal
if @r 68 408 476
156 476 $c }
157  
158 15564 ▶sub redir { # a redirection, or nothing (pos unchanged) if none starts here
Subroutine redir: called CC=11 SCAR=24.0
Pod undocumented
159 15564 my $p = pos;
160 15564 ▶ E('process substitution (bash)', $p) if /\G[<>]\(/;
Branch: 1 branch
BranchTrueFalseTotal
if /\G[<>]\(/ 25 15539 15564
161 15539 ▶ /\G([0-9]*)(<<|>>|<>|>\||<&|>&|<|>)$B/gc or return;
Branch: 1 branch
BranchTrueFalseTotal
/\G([0-9]*)(<<|>>|<>|>\||<&|>&|<|>)$Proc::ShellSubset::B/cg or return 966 14573 15539
162 966 ▶ 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 954 966
163 954 my ($n, $op) = ($1, $2);
164 954 ▶ E('here-document', $p) if $op eq '<<';
Branch: 1 branch
BranchTrueFalseTotal
if $op eq "<<" 59 895 954
165 895 ▶ 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 888 895
Condition100%3/3
length $n > 1 and not $Proc::ShellSubset::O{"fdmulti"}
!ll&&!rl&&r
88087
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 888 ▶ my $fd = length $n ? 0 + $n : $op =~ /^</ ? 0 : 1;
Branch: 2 branches
BranchTrueFalseTotal
length $n ? : 199 689 888
$op =~ /^</ ? : 183 506 689
167 888 ▶ return [$fd, $op, /\G([0-9-])$END/gc ? $1 : E("'$op' takes one digit or '-'", pos)] if $op =~ /&/;
Branch: 2 branches
BranchTrueFalseTotal
if $op =~ /&/ 157 731 888
/\G([0-9-])$Proc::ShellSubset::END/cg ? : 144 13 157
168 731 [$fd, $op, word('r')] }
169  
170 6405 ▶sub simple {
Subroutine simple: called CC=60 SCAR=42.2
Pod undocumented
171 6405 my $pl = shift; my (@env, @np, @av, @ap, @r, $kw); my $p0 = pos; # @np: NAME, position, ... of the settings
172 6405 push @$pl, my $c = { argv => \@av }; local $OPEN[@OPEN] = \@av;
173 6405 ▶ while (/\G$B/gc, !/\G(?=[;&|()\n]|\z)/) {
Branch: 1 branch
BranchTrueFalseTotal
if (/\G$Proc::ShellSubset::B/cg, !/\G(?=[;&|()\n]|\z)/) 15171 5122 20293
174 15171 my $p = pos;
175 15171 ▶ if (my $r = redir()) { push @r, $r }
Branch: 2 branches
BranchTrueFalseTotal
if (my $r = redir()) { } 699 14257 14956
elsif (not @av and /\G($Proc::ShellSubset::NM)(\+?)=/cg) { } 464 13793 14257
176 464 ▶ 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 448 464
Condition100%3/3
not @av and /\G($Proc::ShellSubset::NM)(\+?)=/cg
!ll&&!rl&&r
78365957464
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 13793 ▶ 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
694558910
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 5122 ▶ 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"}) 140 4982 5122
Condition100%9/9
not @av and @env and not @r and $Proc::ShellSubset::O{"assign"}
!ll&&!rl&&r
491864140
not @av and @env and not @r
!ll&&!rl&&r
490117204
not @av and @env
!ll&&!rl&&r
481982221
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 140 ▶ vname(splice @np, 0, 2) while @np;
Branch: 1 branch
BranchTrueFalseTotal
@np and do { vname(splice(@np, 0, 2)) } 142 121 263
180 121 return %$c = (set => \@env) }
181 4982 name(@$_) for grep $$_[0] ne q{IFS}, pairs @np; # bash refuses its own names (UID=5 cmd)
182 4971 ▶ @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) 4810 161 4971
@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 4810 ▶ E('command name not literal', $ap[0]) if ref $av[0];
Branch: 1 branch
BranchTrueFalseTotal
if ref $av[0] 30 4780 4810
184 4780 my $n = $av[0];
185 4780 ▶ if ($n eq 'exec') {
Branch: 1 branch
BranchTrueFalseTotal
if ($n eq 'exec') { } 129 4651 4780
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 4651 ▶ 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 4589 4651
Condition100%3/3
$Proc::ShellSubset::KW{$n} and $kw eq $n
!ll&&!rl&&r
45791062
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 4589 ▶ 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 4564 4589
elsif ($n eq 'read' and $Proc::ShellSubset::O{'read'}) { } 62 4502 4564
elsif ($Proc::ShellSubset::BI{$n}) { } 336 4166 4502
Condition100%3/3
$n =~ /^(?:break|continue)\z/ and $Proc::ShellSubset::LOOP
!ll&&!rl&&r
45412325
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
44921062
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 336 elsif ($BI{$n}) { E("builtin '$n'", $ap[0]) }
200 4229 ▶ if ($n eq 'cd') {
Branch: 1 branch
BranchTrueFalseTotal
if ($n eq "cd") 139 4090 4229
201 139 ▶ @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]) 95 44 139
Condition85%12/14
@av <= 2 and not @env and not @r and not defined $ENV{"CDPATH"} and not +($av[1] // "") =~ /^-/
!ll&&!rl&&r
35995
@av <= 2 and not @env and not @r and not defined $ENV{"CDPATH"}
!ll&&!rl&&r
350104
@av <= 2 and not @env and not @r
!ll&&!rl&&r
296104
@av <= 2 and not @env
!ll&&!rl&&r
290110
$av[1] // ""
l!l
9311
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 95 95
Condition8%1/12
not defined $ENV{"HOME"} and @av == 1 || ref $av[1] && grep({ref $_ and $_->[0] =~ /^\$/;} @{$av[1];})
!ll&&!rl&&r
9500
@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 95 return %$c = (cd => $av[1]) }
206 4090 ▶ if ($n =~ /^(?::|exit)\z/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($n =~ /^(?::|exit)\z/) 125 3965 4090
207 125 ▶ E("settings before '$n'", $p0) if @env;
Branch: 1 branch
BranchTrueFalseTotal
if @env 11 114 125
208 114 ▶ 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) 22 92 114
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
524022
@av > 2 or @av == 2 and !($av[1] =~ /^(?:0|[1-9][0-9]{0,2})\z/) || $av[1] > 255
l!l&&r!l&&!r
02240
@av == 2 and !($av[1] =~ /^(?:0|[1-9][0-9]{0,2})\z/) || $av[1] > 255
!ll&&!rl&&r
93122
not $av[1] =~ /^(?:0|[1-9][0-9]{0,2})\z/ or $av[1] > 255
l!l&&r!l&&!r
17531
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 4156 ▶ $c->{env} = \@env if @env; $c->{redir} = \@r if @r;
Branch: 2 branches
BranchTrueFalseTotal
if @env 80 4076 4156
if @r 422 3734 4156
211 4156 $c }
212  
213 19800 ▶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 19800 ▶ my $x = shift; my $p0 = pos; my @s; local $ATT = $ATT // $#OPEN;
Condition100%2/2
$Proc::ShellSubset::ATT // $#Proc::ShellSubset::OPEN
l!l
130018500
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 19800 ▶ 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 19640 19800
Condition100%3/3
$x eq "a" and /\G\[$Proc::ShellSubset::END/cg
!ll&&!rl&&r
153018110160
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 19640 ▶ 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
643218995
$x eq "a" and $Proc::ShellSubset::O{"tilde_args"} and /\G($Proc::ShellSubset::NM=)/cg and push @s, ["u", $1]
!ll&&!rl&&r
1899502
$x eq "a" and $Proc::ShellSubset::O{"tilde_args"} and /\G($Proc::ShellSubset::NM=)/cg
!ll&&!rl&&r
1899322
$x eq "a" and $Proc::ShellSubset::O{"tilde_args"}
!ll&&!rl&&r
887181064
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 19640 ▶ my $te = $ta ? qr{(?=[/:])|$END} : qr{(?=/)|$END};
Branch: 1 branch
BranchTrueFalseTotal
$ta ? : 645 18995 19640
218 19640 my $p;
219 my %do = (
220 461 ▶ sq => sub { push @s, [q => shift] },
Subroutine __ANON__: called CC=1 SCAR=0.0
221 1090 ▶ dq => sub { push @s, [q => '']; dq(\@s, $p) },
Subroutine __ANON__: called CC=1 SCAR=0.0
222 221 ▶ 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 200 221
223 1935 ▶ ex => sub { push @s, [x => $EX{$_[0]}->('', $p)] }, # also in redirection targets (Q1)
Subroutine __ANON__: called CC=1 SCAR=0.0
224 364 ▶ 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 338 364
$Proc::ShellSubset::RLIT ? : 9 17 26
225 338 ▶ push @s, [$x eq 'e' ? 'u' : 'g', shift] },
Branch: 1 branch
BranchTrueFalseTotal
$x eq 'e' ? : 3 335 338
226 177 ▶ br => sub {
Subroutine __ANON__: called CC=10 SCAR=23.1
227 177 ▶ $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 175 177
$Proc::ShellSubset::RLIT ? : 2 0 2
228 175 ▶ push @s, $x eq 'e' ? [u => '['] : /\G(!?\]?[^\] \t\n;&|()<>'"\\\$`{}^\/,]*\])/gc ? [g => "[$1"]
Branch: 5 branches
BranchTrueFalseTotal
$x eq 'e' ? : 0 175 175
m(\G(!?\]?[^\] \t\n;&|()<>'"\\\$`{}^/,]*\]))cg ? : 48 127 175
$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 16237 ▶ 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 19640 // sprintf('control character \\x%02x', ord shift), $p) });
252 19640 ▶ until (/$STOP{$x}/) { $p = pos; /$PIECE/gc; my ($k, $v) = %+; $do{$k}($v) }
Branch: 1 branch
BranchTrueFalseTotal
unless (/$Proc::ShellSubset::STOP{$x}/) 21045 18419 39464
253 18419 ▶ @s or $x =~ /[eb]/ or E('missing word', $p0);
Branch: 1 branch
BranchTrueFalseTotal
@s or $x =~ /[eb]/ or E("missing word", $p0) 18339 80 18419
Condition100%3/3
@s or $x =~ /[eb]/
l!l&&r!l&&!r
182885180
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 18339 my $k = join '', map $$_[0], @s; my @v; # kinds: u(nquoted) q(uoted) g(lob char) x(pansion)
255 18339 ▶ 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] } 20933 18339 39272
defined $1 ? : 432 20501 20933
256 while $k =~ /([ug]*g[ug]*)|./g; # unquoted text next to a pattern character joins it
257 18339 ▶ 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 13825 4514 18339
Condition66%4/6
$Proc::ShellSubset::RLIT || dots(@v) && E(q[pattern that may match '.' or '..'], $p0)
l!l
4514138250
dots(@v) and E("pattern that may match '.' or '..'", $p0)
!ll
13797280
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 18311 mkword(@v) }
259  
260 61 ▶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 61 my ($s, $p, $xq) = @_; my $p0 = pos; my @b = [g => '[']; # shells: quoted characters are members, not operators;
262 61 ▶ push @b, [g => $1] if /\G([!^])/gc; # an unquoted expansion's characters are active. Pushes its
Branch: 1 branch
BranchTrueFalseTotal
if /\G([!^])/cg 7 54 61
263 61 ▶ 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 61 61
264 61 ▶ until (/\G\]/gc) { # the word ends first (then the '[' is literal)
Branch: 1 branch
BranchTrueFalseTotal
unless (/\G\]/cg) 84 44 128
265 84 my $q = pos;
266 0 ▶ if (/\G(\[:[a-z]+:\])/gc) { push @b, [g => $1] }
Branch: 7 branches
BranchTrueFalseTotal
if (/\G(\[:[a-z]+:\])/cg) { } 0 84 84
elsif (/\G([^\] \t\n;&|()<>'"\\\$`{}^,\[\x00-\x1f\x7f]+|\[)/cg) { } 24 60 84
elsif (/\G'([^']*)'/cg) { } 3 57 60
elsif (/\G\\([^\n])/cg) { } 12 45 57
elsif (/\G"/cg) { } 16 29 45
elsif (/\G([\$`])/cg) { } 12 17 29
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 12 ▶ elsif (/\G([\$`])/gc) { push @b, [x => $EX{$1}->($xq // '', $q)] } # $xq: inside "${...}"
Condition100%2/2
$xq // ""
l!l
111
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 44 push @$s, @b, [g => ']']; 1 }
275  
276 13825 ▶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 13825 my ($re, $g) = ('', 0); # the component so far as a regex (only the character '.' matters); has it a pattern?
278 13825 for my $x (@_, '/') { # literal text and patterns, split at '/'; an expansion is taken to match no '.'
279 29471 ▶ for (ref $x ? $$x[0] eq '*' ? map [g => $_], split m{(/)}, $$x[1] : [x => ''] : map [l => $_], split m{(/)}, $x) {
Branch: 2 branches
BranchTrueFalseTotal
ref $x ? : 1626 27845 29471
$x->[0] eq '*' ? : 309 1317 1626
280 45363 my ($k, $v) = @$_;
281 45363 ▶ 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 '/') { } 15297 30066 45363
elsif ($k eq 'l') { } 28338 1728 30066
elsif ($k eq 'x') { } 1317 411 1728
if $g and $re =~ /^\\\./ and grep /^$re\z/, ".", ".." 28 15269 15297
Condition100%6/6
$g and $re =~ /^\\\./ and grep /^$re\z/, ".", ".."
!ll&&!rl&&r
152412828
$g and $re =~ /^\\\./
!ll&&!rl&&r
1499424756
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 28338 elsif ($k eq 'l') { $re .= quotemeta $v }
283 1317 elsif ($k eq 'x') { $re .= '(?!)' }
284 411 ▶ else { $g ||= $v =~ /[*?[]/; $re .= $v =~ s{\[(!?)(\]?[^\]]*)\]|([*?])|(.)}{ # a bracket expression: can it match '.'?
Condition100%3/3
$g ||= $v =~ /[*?[]/
l!l&&r!l&&!r
930399
MC/DC100%2/2
$g ||= $v =~ /[*?[]/
$g $v =~ /[*?[]/
Truth table100%3/3
A ||= B
A= $gB= $v =~ /[*?[]/
ABresult
1X1
011
000
285 1347 ▶ defined $2 ? (($1 ? $2 !~ /\./ : $2 =~ /[.\-]|\[:/) ? q{[.]} : q{(?!)}) : defined $3 ? ($3 eq '*' ? '.*' : '.') : quotemeta $4}gesr } } }
Branch: 5 branches
BranchTrueFalseTotal
defined $2 ? : 38 1309 1347
($1 ? !($2 =~ /\./) : $2 =~ /[.\-]|\[:/) ? : 19 19 38
$1 ? : 10 28 38
defined $3 ? : 291 1018 1309
$3 eq '*' ? : 268 23 291
286 13797 0 }
287  
288 18493 ▶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 18493 ▶ my @w; !ref && @w && !ref $w[-1] ? $w[-1] .= $_ : push @w, $_ for @_;
Branch: 1 branch
BranchTrueFalseTotal
!ref($_) && @w && !ref($w[-1]) ? : 1397 19730 21127
Condition100%6/6
not ref $_ and @w and not ref $w[-1]
!ll&&!rl&&r
193054251397
not ref $_ and @w
!ll&&!rl&&r
2441168641822
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 18493 ▶ @w == 1 && !ref $w[0] ? $w[0] : @w ? \@w : '' }
Branch: 2 branches
BranchTrueFalseTotal
@w == 1 && !ref($w[0]) ? : 16224 2269 18493
@w ? : 2210 59 2269
Condition100%3/3
@w == 1 and not ref $w[0]
!ll&&!rl&&r
941132816224
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 1122 ▶sub dq { # after '"', up to the closing '"'
Subroutine dq: called CC=5 SCAR=16.1
Pod undocumented
293 1122 my ($s, $p) = @_;
294 1122 ▶ until (/\G"/gc) {
Branch: 1 branch
BranchTrueFalseTotal
unless (/\G"/cg) 1994 945 2939
295 1994 ▶ next if /\G\\\n/gc;
Branch: 1 branch
BranchTrueFalseTotal
if /\G\\\n/cg 3 1991 1994
296 1991 ▶ if (/\G(?:([^"\\\$`]+)|\\([\$`"\\])|(\\))/gc) { push @$s, [q => $+] }
Branch: 2 branches
BranchTrueFalseTotal
if (/\G(?:([^"\\\$`]+)|\\([\$`"\\])|(\\))/cg) { } 1150 841 1991
elsif (/\G([\$`])/cg) { } 826 15 841
297 826 elsif (/\G([\$`])/gc) { push @$s, [x => $EX{$1}->('"', pos() - 1)] }
298 15 else { E('unterminated double quote', $p) } } }
299  
300 1842 ▶sub dollar { # after '$'; $q is '"' inside double quotes
Subroutine dollar: called CC=19 SCAR=29.4
Pod undocumented
301 1842 my ($q, $p) = @_;
302 1842 ▶ 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 1758 1842
Condition100%6/6
/\G[A-Za-z_0-9{(\@*#?\$!\[-]/ or not $q and /\G['"]/
l!l&&r!l&&!r
17481084
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 1758 ▶ return [$q . '$((', arith($p)] if /\G\(\(/gc;
Branch: 1 branch
BranchTrueFalseTotal
if /\G\(\(/cg 140 1618 1758
304 1618 ▶ if (/\G\(/gc) { my $l = shell(')', []); /\G\)/gc; return [$q . '$(', $l] }
Branch: 1 branch
BranchTrueFalseTotal
if (/\G\(/cg) 310 1308 1618
305 1308 ▶ 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 795 513 1308
306 513 ▶ if ($O{param_ops}) { # (C7)
Branch: 1 branch
BranchTrueFalseTotal
if ($Proc::ShellSubset::O{"param_ops"}) 299 214 513
307 299 ▶ return [$q . '${#', name("$1", $p)] if /\G\{#($NM)\}/gc;
Branch: 1 branch
BranchTrueFalseTotal
if /\G\{#($Proc::ShellSubset::NM)\}/cg 5 294 299
308 294 ▶ if (/\G\{($NM)(:?[-+])/gc) {
Branch: 1 branch
BranchTrueFalseTotal
if (/\G\{($Proc::ShellSubset::NM)(:?[-+])/cg) 55 239 294
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 453 ▶ E(/\G['"\[]/ ? 'bash-only $ form' : 'unsupported parameter form', $p) }
Branch: 1 branch
BranchTrueFalseTotal
/\G['"\[]/ ? : 28 425 453
318  
319 2247 ▶sub name {
Subroutine name: called CC=7 SCAR=19.5
Pod undocumented
320 2247 my ($n, $p) = @_;
321 E("shell-set variable '$n'", $p) if $SH{$n} || $n eq 'PWD' && $O{nopwd} || $n =~ /^(?:BASH|COMP|READLINE)_/
322 2247 ▶ || $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 2182 2247
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
6502182
$Proc::ShellSubset::SH{$n} or $n eq "PWD" and $Proc::ShellSubset::O{"nopwd"} or $n =~ /^(?:BASH|COMP|READLINE)_/
l!l&&r!l&&!r
6052182
$Proc::ShellSubset::SH{$n} or $n eq "PWD" and $Proc::ShellSubset::O{"nopwd"}
l!l&&r!l&&!r
5642187
$n eq "PWD" and $Proc::ShellSubset::O{"nopwd"}
!ll&&!rl&&r
2173144
$n =~ /^(?:PATH|SHELL|TERM|HOSTNAME)\z/ and not defined $ENV{$n}
!ll&&!rl&&r
217660
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 2182 $n }
324  
325 140 ▶sub arith { # after '$((': check the expression by its grammar, return its text
Subroutine arith: called CC=4 SCAR=13.9
Pod undocumented
326 140 my $p = shift;
327 140 ▶ /\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 68 140
Condition100%3/3
/\G((?&e))(?&w)\)\)$Proc::ShellSubset::ARITH/cg and not $1 =~ /\+\+|--/
!ll&&!rl&&r
64472
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 2604 ▶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 2604 my ($l, $ok) = @_; # $ok: nothing follows this list in its shell
343 2604 for my $ch (@$l) { my @p = grep ref, @$ch;
344 3074 for my $pl (@p) { my @c = grep ref, @$pl;
345 3332 ▶ 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
5611918853
$pl == $p[-1] and $pl->[0] ne "!" and $ch->[-1] eq "&" || $ok && $ch == $l->[-1]
!ll&&!rl&&r
2825711918
$pl == $p[-1] and $pl->[0] ne "!"
!ll&&!rl&&r
247352489
$ch->[-1] eq "&" or $ok and $ch == $l->[-1]
l!l&&r!l&&!r
571861571
$ok and $ch == $l->[-1]
!ll&&!rl&&r
1354361861
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 3332 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 4169 ▶ xc($x->{group}, $last) if $x->{group};
Branch: 1 branch
BranchTrueFalseTotal
if $x->{"group"} 110 4059 4169
349 4152 ▶ 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 4136 4152
$_ % 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 4149 xc($x->{$_}, 0) for grep $x->{$_}, qw(while until do);
351 4146 ▶ if (exists $x->{case}) { xc($_, $last) for pairvalues @{$x->{in}} }
Branch: 1 branch
BranchTrueFalseTotal
if (exists $x->{"case"}) 22 4124 4146
352 4146 ▶ if (exists $x->{exec}) { my $xp = $x->{exec}; $x->{exec} = 1;
Branch: 1 branch
BranchTrueFalseTotal
if (exists $x->{"exec"}) 99 4047 4146
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 487 1;
356 __END__
« lib/Proc/ShellSpawn.pm ↑ Summary lib/Proc/ShellSpawn/Programs.pm »