lib/Proc/ShellSubset.pm

filter: Statementstmt 99.7% 375 / 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 90.1% 1084 / 1202 CC 277 SCAR 31.0
CC
277
Cov
94%
simple
66.4
compound
22.0
xc
20.0
CRAP 22.3
« lib/Proc/ShellSubset/Large.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 551 our $VERSION = '0.13';
3 550 ▶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 551 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 551 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 551 our %KW = map +($_ => 1), qw(if then else elif fi case esac for while until do done in [[ ]] function select coproc !);
42 550 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 550 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 550 our $NM = qr/[A-Za-z_][A-Za-z0-9_]*/;
50 550 our $END = qr/(?=[ \t\n;&|()<>]|\z)/;
51 550 our $B = qr/(?:[ \t]|\\\n|#.*)*+/; # blanks, line continuations, a comment
52 550 our $BN = qr/(?:[ \t\n]|\\\n|#.*)*+/; # the same, and newlines
53 550 our %STOP = (b => qr/\G(?:(?=[,}])|$END)/, map +($_ => qr/\G$END/), qw(a e r));
54 550 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 550 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 3330 ▶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 4239 ▶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 4098 4232
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 2689 ▶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 2653 29 2682
Condition100%2/2
$Proc::ShellSubset::ATT // -1
l!l
12531400
MC/DC100%1/1
$Proc::ShellSubset::ATT // -1
$Proc::ShellSubset::ATT
Truth table100%2/2
A
A= $Proc::ShellSubset::ATT
Aresult
11
00
68 247 ▶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 5342 ▶sub parse {
Subroutine parse: called CC=9 SCAR=22.1
Pod undocumented
70 5349 my $s = shift; local %O = @_; local ($M, @OPEN, $ATT); local $LAST = 0; my @l;
71 5349 my $t = eval {
72 5349 local $_ = $s;
73 5349 ▶ E('NUL character', $-[0]) if /\0/;
Branch: 1 branch
BranchTrueFalseTotal
if /\0/ 1 5348 5349
74 5348 ▶ 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 5332 5348
75 5332 ▶ 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 5332 5332
Condition33%1/3
$Proc::ShellSubset::O{"check"} and my $why = $Proc::ShellSubset::O{"check"}->($s)
!ll&&!rl&&r
533200
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 5332 shell('', \@l);
77 2634 ▶ @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) 2622 12 2634
Condition100%3/3
@l or $Proc::ShellSubset::O{"empty"}
l!l&&r!l&&!r
26061612
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 5349 ▶ $t // (ref $@ eq 'ARRAY' ? { error => $@->[0], pos => $@->[1], last => $LAST, tree => \@l } : die $@) }
Branch: 1 branch
BranchTrueFalseTotal
ref $@ eq 'ARRAY' ? : 2727 0 2727
Condition100%2/2
$t // (ref $@ eq "ARRAY" ? {"error", $@->[0], "pos", $@->[1], "last", $Proc::ShellSubset::LAST, "tree", \@l} : die($@))
l!l
26222727
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 6604 ▶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 6611 ▶ 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
10921875332
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 6604 ▶ 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 ? : 51 6560 6611
$t eq ')' ? : 557 6003 6560
$t ? : 484 5519 6003
83 6611 ▶ 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/) 8147 577 8724
84 8147 push @$l, my $c = []; andor($c);
85 5486 ▶ if (/\G$B&(?!&)/gc) { push @$c, '&' }
Branch: 2 branches
BranchTrueFalseTotal
if (/\G$Proc::ShellSubset::B&(?!&)/cg) { } 162 5324 5486
elsif (not /\G$Proc::ShellSubset::B(?:;(?!;)|\n)/cg) { } 3365 1959 5324
86 3372 ▶ elsif (!/\G$B(?:;(?!;)|\n)/gc) { /\G$B/gc, /$e/ ? last : U() }
Branch: 1 branch
BranchTrueFalseTotal
/$e/ ? : 3131 234 3365
87 2121 ▶ $LAST = pos if $top;
Branch: 1 branch
BranchTrueFalseTotal
if $top 1439 682 2121
88 2121 ▶ 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 2113 2121
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
211308
$top and $Proc::ShellSubset::CUT and substr($_, pos($_) - 1, 1) eq "\n"
!ll&&!rl&&r
210858
$top and $Proc::ShellSubset::CUT
!ll&&!rl&&r
682142613
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 16 my $p = opos(pos); # definition known only when it runs: the rest
90 16 push @$l, [[{ rest => substr($SRC, $p), lineoff => $LOFF + (substr($SRC, 0, $p) =~ tr/\n//) }]]; last } } # of the text, parsed then
91 3717 $l }
92  
93 6069 ▶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 6077 local $LOOP = 0; my $l = list(@_); xc($l, 1); $l }
95  
96 8140 ▶sub andor {
Subroutine andor: called CC=3 SCAR=11.0
Pod undocumented
97 8148 my $ao = shift; local $OPEN[@OPEN] = $ao;
98 8140 ▶ 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 5486 5844
Condition66%2/3
/\G$Proc::ShellSubset::B(&&|\|\|)$Proc::ShellSubset::BN/cg and push @$ao, $1
!ll&&!rl&&r
54860358
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 8505 ▶sub pipeline {
Subroutine pipeline: called CC=10 SCAR=23.0
Pod undocumented
101 8497 my $p = shift; local $OPEN[@OPEN] = $p;
102 8497 ▶ push @$p, '!' if /\G!(?=[ \t])$B/gc;
Branch: 1 branch
BranchTrueFalseTotal
if /\G!(?=[ \t])$Proc::ShellSubset::B/cg 59 8446 8505
103 8497 ▶ E("'! !'", pos) if @$p && /\G!$END/;
Branch: 1 branch
BranchTrueFalseTotal
if @$p and /\G!$Proc::ShellSubset::END/ 11 8494 8505
Condition100%3/3
@$p and /\G!$Proc::ShellSubset::END/
!ll&&!rl&&r
84464811
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 8486 ▶ 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) } } 1008 5848 6856
105 5840 my ($q, @c) = (pos, grep ref, @$p); # each element of a longer pipeline is a subshell: break/continue can't reach the loop
106 5840 ▶ @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 6782 6786
Condition100%8/8
@c > 1 and ($_->{"argv"} && $_->{"argv"}[0] // "") =~ /^(?:break|continue)\z/
!ll&&!rl&&r
520415784
$_->{"argv"} && $_->{"argv"}[0] // ""
l!l
1460122
$_->{"argv"} and $_->{"argv"}[0]
!ll&&!rl&&r
11961457
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 552 ▶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 127 ▶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 113 ▶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 113 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 599 ▶sub vname { # a variable the string sets: by assignment (C5), for or read
Subroutine vname: called CC=2 SCAR=6.9
Pod undocumented
115 577 ▶ 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 564 577
116  
117 9060 ▶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 9060 my ($pl, $p) = @_; my $c;
119 9060 ▶ if ($O{if} && /\Gif$END/gc) {
Branch: 4 branches
BranchTrueFalseTotal
if ($Proc::ShellSubset::O{'if'} and /\Gif$Proc::ShellSubset::END/cg) { } 52 9016 9068
elsif ($Proc::ShellSubset::O{'while'} and /\G(while|until)$Proc::ShellSubset::END/cg) { } 51 8965 9016
elsif ($Proc::ShellSubset::O{'for'} and /\Gfor$Proc::ShellSubset::END/cg) { } 81 8884 8965
elsif ($Proc::ShellSubset::O{'case'} and /\Gcase$Proc::ShellSubset::END/cg) { } 49 11835 11884
Condition100%3/3
$Proc::ShellSubset::O{"if"} and /\Gif$Proc::ShellSubset::END/cg
!ll&&!rl&&r
3000601652
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
2998596751
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
3010587481
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
3000583549
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 49 push @$pl, $c = { case => '', in => my $in = [] }; local $OPEN[@OPEN] = $in;
137 49 ▶ /\G$B/gc; $c->{case} = word('a'); kw('in') or U();
Branch: 1 branch
BranchTrueFalseTotal
kw("in") or U() 41 4 45
138 41 ▶ until (kw('esac')) {
Branch: 1 branch
BranchTrueFalseTotal
unless (kw("esac")) 53 35 88
139 61 /\G\(/gc; push @$in, my $pat = [];
140 61 ▶ { 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") } } 301 51 352
141 51 ▶ /\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() 51 0 51
142 8982 $c }
143  
144 9485 ▶sub command { # pushes the command onto the pipeline @{$_[0]}
Subroutine command: called CC=9 SCAR=22.0
Pod undocumented
145 9480 my $pl = shift; my $p = pos; my $c;
146 9480 ▶ E("'((' at the start of a command", $p) if /\G\(\(/;
Branch: 1 branch
BranchTrueFalseTotal
if /\G\(\(/ 16 9472 9488
147 9464 ▶ if (/\G\(/gc) {
Branch: 2 branches
BranchTrueFalseTotal
if (/\G\(/cg) { } 181 9291 9472
elsif (/\G\{(?=[ \t\n])/cg) { } 223 9068 9291
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 245 push @$pl, $c = { group => my $l = [] };
152 224 ▶ list('\}', $l); /\G\}/gc; @$l or E('empty group', $p) } # xc: by the parent
Branch: 1 branch
BranchTrueFalseTotal
@$l or E("empty group", $p) 191 1 192
153 9061 ▶ else { $c = compound($pl, $p) or return simple($pl) }
Branch: 1 branch
BranchTrueFalseTotal
$c = compound($pl, $p) or return simple($pl) 155 8835 8990
154 492 ▶ 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 488 571
155 489 ▶ $c->{redir} = \@r if @r;
Branch: 1 branch
BranchTrueFalseTotal
if @r 68 420 488
156 496 $c }
157  
158 17046 ▶sub redir { # a redirection, or nothing (pos unchanged) if none starts here
Subroutine redir: called CC=11 SCAR=24.0
Pod undocumented
159 17054 my $p = pos;
160 17054 ▶ E('process substitution (bash)', $p) if /\G[<>]\(/;
Branch: 1 branch
BranchTrueFalseTotal
if /\G[<>]\(/ 25 17043 17068
161 17029 ▶ /\G([0-9]*)(<<|>>|<>|>\||<&|>&|<|>)$B/gc or return;
Branch: 1 branch
BranchTrueFalseTotal
/\G([0-9]*)(<<|>>|<>|>\||<&|>&|<|>)$Proc::ShellSubset::B/cg or return 1277 15766 17043
162 1284 ▶ 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 1265 1277
163 1272 my ($n, $op) = ($1, $2);
164 1286 ▶ E('here-document', $p) if $op eq '<<';
Branch: 1 branch
BranchTrueFalseTotal
if $op eq "<<" 63 1202 1265
165 1223 ▶ 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 1195 1202
Condition100%3/3
length $n > 1 and not $Proc::ShellSubset::O{"fdmulti"}
!ll&&!rl&&r
118787
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 1195 ▶ my $fd = length $n ? 0 + $n : $op =~ /^</ ? 0 : 1;
Branch: 2 branches
BranchTrueFalseTotal
length $n ? : 503 692 1195
$op =~ /^</ ? : 183 509 692
167 1194 ▶ return [$fd, $op, /\G([0-9-])$END/gc ? $1 : E("'$op' takes one digit or '-'", pos)] if $op =~ /&/;
Branch: 2 branches
BranchTrueFalseTotal
if $op =~ /&/ 457 738 1195
/\G([0-9-])$Proc::ShellSubset::END/cg ? : 444 13 457
168 737 [$fd, $op, word('r')] }
169  
170 6545 ▶sub simple {
Subroutine simple: called CC=60 SCAR=42.0
Pod undocumented
171 6545 my $pl = shift; my (@env, @np, @av, @ap, @r, $kw); my $p0 = pos; # @np: NAME, position, ... of the settings
172 6566 push @$pl, my $c = { argv => \@av }; local $OPEN[@OPEN] = \@av;
173 6545 ▶ while (/\G$B/gc, !/\G(?=[;&|()\n]|\z)/) {
Branch: 1 branch
BranchTrueFalseTotal
if (/\G$Proc::ShellSubset::B/cg, !/\G(?=[;&|()\n]|\z)/) 16671 5255 21926
174 16649 my $p = pos;
175 16657 ▶ if (my $r = redir()) { push @r, $r }
Branch: 2 branches
BranchTrueFalseTotal
if (my $r = redir()) { } 1006 15446 16452
elsif (not @av and /\G($Proc::ShellSubset::NM)(\+?)=/cg) { } 1091 14355 15446
176 1099 ▶ 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 1075 1091
Condition100%3/3
not @av and /\G($Proc::ShellSubset::NM)(\+?)=/cg
!ll&&!rl&&r
827660791091
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 14334 ▶ 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
737460130
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 5247 ▶ 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"}) 166 5089 5255
Condition100%9/9
not @av and @env and not @r and $Proc::ShellSubset::O{"assign"}
!ll&&!rl&&r
502564166
not @av and @env and not @r
!ll&&!rl&&r
500817230
not @av and @env
!ll&&!rl&&r
492682247
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 166 ▶ vname(splice @np, 0, 2) while @np;
Branch: 1 branch
BranchTrueFalseTotal
@np and do { vname(splice(@np, 0, 2)) } 467 146 613
180 154 return %$c = (set => \@env) }
181 5089 name(@$_) for grep $$_[0] ne q{IFS}, pairs @np; # bash refuses its own names (UID=5 cmd)
182 5070 ▶ @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) 4917 161 5078
@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 4909 ▶ E('command name not literal', $ap[0]) if ref $av[0];
Branch: 1 branch
BranchTrueFalseTotal
if ref $av[0] 30 4887 4917
184 4879 my $n = $av[0];
185 4879 ▶ if ($n eq 'exec') {
Branch: 1 branch
BranchTrueFalseTotal
if ($n eq 'exec') { } 129 4758 4887
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 123 ▶ 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 4750 ▶ 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 4696 4758
Condition100%3/3
$Proc::ShellSubset::KW{$n} and $kw eq $n
!ll&&!rl&&r
46861062
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 4688 ▶ 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 4671 4696
elsif ($n eq 'read' and $Proc::ShellSubset::O{'read'}) { } 64 4607 4671
elsif ($Proc::ShellSubset::BI{$n}) { } 361 4246 4607
Condition100%3/3
$n =~ /^(?:break|continue)\z/ and $Proc::ShellSubset::LOOP
!ll&&!rl&&r
46482325
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
45971064
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 64 ▶ my $i = ($av[1] // '') eq '-r' ? 2 : 1;
Branch: 1 branch
BranchTrueFalseTotal
($av[1] // '') eq '-r' ? : 11 53 64
Condition100%2/2
$av[1] // ""
l!l
604
MC/DC100%1/1
$av[1] // ""
$av[1]
Truth table100%2/2
A
A= $av[1]
Aresult
11
00
197 72 ▶ $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]) 60 4 64
198 60 ▶ 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]) 62 12 74
199 369 elsif ($BI{$n}) { E("builtin '$n'", $ap[0]) }
200 4311 ▶ if ($n eq 'cd') {
Branch: 1 branch
BranchTrueFalseTotal
if ($n eq "cd") 155 4156 4311
201 177 ▶ @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 132 ▶ && (@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 132 return %$c = (cd => $av[1]) }
206 4170 ▶ if ($n =~ /^(?::|exit)\z/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($n =~ /^(?::|exit)\z/) 130 4026 4156
207 152 ▶ E("settings before '$n'", $p0) if @env;
Branch: 1 branch
BranchTrueFalseTotal
if @env 11 119 130
208 141 ▶ 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 95 119
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
554024
@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 4234 ▶ $c->{env} = \@env if @env; $c->{redir} = \@r if @r;
Branch: 2 branches
BranchTrueFalseTotal
if @env 83 4137 4220
if @r 429 3791 4220
211 4234 $c }
212  
213 21570 ▶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 21592 ▶ my $x = shift; my $p0 = pos; my @s; local $ATT = $ATT // $#OPEN;
Condition100%2/2
$Proc::ShellSubset::ATT // $#Proc::ShellSubset::OPEN
l!l
130820284
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 21592 ▶ 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 21432 21592
Condition100%3/3
$x eq "a" and /\G\[$Proc::ShellSubset::END/cg
!ll&&!rl&&r
218819244160
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 21432 ▶ 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
1289220141
$x eq "a" and $Proc::ShellSubset::O{"tilde_args"} and /\G($Proc::ShellSubset::NM=)/cg and push @s, ["u", $1]
!ll&&!rl&&r
2014102
$x eq "a" and $Proc::ShellSubset::O{"tilde_args"} and /\G($Proc::ShellSubset::NM=)/cg
!ll&&!rl&&r
2013922
$x eq "a" and $Proc::ShellSubset::O{"tilde_args"}
!ll&&!rl&&r
899192404
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 21432 ▶ my $te = $ta ? qr{(?=[/:])|$END} : qr{(?=/)|$END};
Branch: 1 branch
BranchTrueFalseTotal
$ta ? : 1291 20141 21432
218 21432 my $p;
219 my %do = (
220 462 ▶ sq => sub { push @s, [q => shift] },
Subroutine __ANON__: called CC=1 SCAR=0.0
221 1454 ▶ 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 2015 ▶ ex => sub { push @s, [x => $EX{$_[0]}->('', $p)] }, # also in redirection targets (Q1)
Subroutine __ANON__: called CC=1 SCAR=0.0
224 370 ▶ 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 344 370
$Proc::ShellSubset::RLIT ? : 9 17 26
225 344 ▶ push @s, [$x eq 'e' ? 'u' : 'g', shift] },
Branch: 1 branch
BranchTrueFalseTotal
$x eq 'e' ? : 3 341 344
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 209 ▶ 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 17881 ▶ 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 21432 // sprintf('control character \\x%02x', ord shift), $p) });
252 21410 ▶ until (/$STOP{$x}/) { $p = pos; /$PIECE/gc; my ($k, $v) = %+; $do{$k}($v) }
Branch: 1 branch
BranchTrueFalseTotal
unless (/$Proc::ShellSubset::STOP{$x}/) 23168 20200 43368
253 20178 ▶ @s or $x =~ /[eb]/ or E('missing word', $p0);
Branch: 1 branch
BranchTrueFalseTotal
@s or $x =~ /[eb]/ or E("missing word", $p0) 20120 80 20200
Condition100%3/3
@s or $x =~ /[eb]/
l!l&&r!l&&!r
200675380
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 20098 my $k = join '', map $$_[0], @s; my @v; # kinds: u(nquoted) q(uoted) g(lob char) x(pansion)
255 20098 ▶ 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] } 23726 20120 43846
defined $1 ? : 438 23288 23726
256 while $k =~ /([ug]*g[ug]*)|./g; # unquoted text next to a pattern character joins it
257 20098 ▶ 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 15314 4806 20120
Condition66%4/6
$Proc::ShellSubset::RLIT || dots(@v) && E(q[pattern that may match '.' or '..'], $p0)
l!l
4806153140
dots(@v) and E("pattern that may match '.' or '..'", $p0)
!ll
15286280
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 20070 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 46 elsif (/\G([^\] \t\n;&|()<>'"\\\$`{}^,\[\x00-\x1f\x7f]+|\[)/gc) { push @b, [g => $1] }
268 25 elsif (/\G'([^']*)'/gc) { push @b, [q => $1] }
269 61 elsif (/\G\\([^\n])/gc) { push @b, [q => $1] }
270 88 elsif (/\G"/gc) { push @b, [q => '']; dq(\@b, $q) }
271 38 ▶ 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 27 elsif (/\G[{}^,]/) { E('bracket expression with a quote, expansion or slash', $p) }
273 62 else { pos = $p0; return 0 } }
274 45 push @$s, @b, [g => ']']; 1 }
275  
276 15292 ▶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 15292 my ($re, $g) = ('', 0); # the component so far as a regex (only the character '.' matters); has it a pattern?
278 15314 for my $x (@_, '/') { # literal text and patterns, split at '/'; an expansion is taken to match no '.'
279 33374 ▶ for (ref $x ? $$x[0] eq '*' ? map [g => $_], split m{(/)}, $$x[1] : [x => ''] : map [l => $_], split m{(/)}, $x) {
Branch: 2 branches
BranchTrueFalseTotal
ref $x ? : 1966 31435 33401
$x->[0] eq '*' ? : 315 1651 1966
280 50423 my ($k, $v) = @$_;
281 50423 ▶ 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 '/') { } 16799 33674 50473
elsif ($k eq 'l') { } 31606 2068 33674
elsif ($k eq 'x') { } 1651 417 2068
if $g and $re =~ /^\\\./ and grep /^$re\z/, ".", ".." 28 16771 16799
Condition100%6/6
$g and $re =~ /^\\\./ and grep /^$re\z/, ".", ".."
!ll&&!rl&&r
167432828
$g and $re =~ /^\\\./
!ll&&!rl&&r
1649025356
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 31564 elsif ($k eq 'l') { $re .= quotemeta $v }
283 1656 elsif ($k eq 'x') { $re .= '(?!)' }
284 422 ▶ else { $g ||= $v =~ /[*?[]/; $re .= $v =~ s{\[(!?)(\]?[^\]]*)\]|([*?])|(.)}{ # a bracket expression: can it match '.'?
Condition100%3/3
$g ||= $v =~ /[*?[]/
l!l&&r!l&&!r
930999
MC/DC100%2/2
$g ||= $v =~ /[*?[]/
$g $v =~ /[*?[]/
Truth table100%3/3
A ||= B
A= $gB= $v =~ /[*?[]/
ABresult
1X1
011
000
285 1371 ▶ defined $2 ? (($1 ? $2 !~ /\./ : $2 =~ /[.\-]|\[:/) ? q{[.]} : q{(?!)}) : defined $3 ? ($3 eq '*' ? '.*' : '.') : quotemeta $4}gesr } } }
Branch: 5 branches
BranchTrueFalseTotal
defined $2 ? : 43 1328 1371
($1 ? !($2 =~ /\./) : $2 =~ /[.\-]|\[:/) ? : 24 19 43
$1 ? : 11 32 43
defined $3 ? : 297 1031 1328
$3 eq '*' ? : 274 23 297
286 15264 0 }
287  
288 20268 ▶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 20268 ▶ my @w; !ref && @w && !ref $w[-1] ? $w[-1] .= $_ : push @w, $_ for @_;
Branch: 1 branch
BranchTrueFalseTotal
!ref($_) && @w && !ref($w[-1]) ? : 2062 22484 24546
Condition100%6/6
not ref $_ and @w and not ref $w[-1]
!ll&&!rl&&r
217497352062
not ref $_ and @w
!ll&&!rl&&r
3158185912797
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 20268 ▶ @w == 1 && !ref $w[0] ? $w[0] : @w ? \@w : '' }
Branch: 2 branches
BranchTrueFalseTotal
@w == 1 && !ref($w[0]) ? : 17902 2388 20290
@w ? : 2327 61 2388
Condition100%3/3
@w == 1 and not ref $w[0]
!ll&&!rl&&r
1000138817902
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 1494 ▶sub dq { # after '"', up to the closing '"'
Subroutine dq: called CC=5 SCAR=16.1
Pod undocumented
293 1487 my ($s, $p) = @_;
294 1487 ▶ until (/\G"/gc) {
Branch: 1 branch
BranchTrueFalseTotal
unless (/\G"/cg) 2690 1313 4003
295 2685 ▶ next if /\G\\\n/gc;
Branch: 1 branch
BranchTrueFalseTotal
if /\G\\\n/cg 3 2687 2690
296 2682 ▶ if (/\G(?:([^"\\\$`]+)|\\([\$`"\\])|(\\))/gc) { push @$s, [q => $+] }
Branch: 2 branches
BranchTrueFalseTotal
if (/\G(?:([^"\\\$`]+)|\\([\$`"\\])|(\\))/cg) { } 1519 1168 2687
elsif (/\G([\$`])/cg) { } 1153 15 1168
297 1153 elsif (/\G([\$`])/gc) { push @$s, [x => $EX{$1}->('"', pos() - 1)] }
298 15 else { E('unterminated double quote', $p) } } }
299  
300 2188 ▶sub dollar { # after '$'; $q is '"' inside double quotes
Subroutine dollar: called CC=19 SCAR=29.4
Pod undocumented
301 2187 my ($q, $p) = @_;
302 2187 ▶ 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 2103 2187
Condition100%6/6
/\G[A-Za-z_0-9{(\@*#?\$!\[-]/ or not $q and /\G['"]/
l!l&&r!l&&!r
20931084
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 2103 ▶ return [$q . '$((', arith($p)] if /\G\(\(/gc;
Branch: 1 branch
BranchTrueFalseTotal
if /\G\(\(/cg 141 1962 2103
304 1962 ▶ if (/\G\(/gc) { my $l = shell(')', []); /\G\)/gc; return [$q . '$(', $l] }
Branch: 1 branch
BranchTrueFalseTotal
if (/\G\(/cg) 312 1650 1962
305 1650 ▶ 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 1127 523 1650
306 523 ▶ if ($O{param_ops}) { # (C7)
Branch: 1 branch
BranchTrueFalseTotal
if ($Proc::ShellSubset::O{"param_ops"}) 309 214 523
307 309 ▶ return [$q . '${#', name("$1", $p)] if /\G\{#($NM)\}/gc;
Branch: 1 branch
BranchTrueFalseTotal
if /\G\{#($Proc::ShellSubset::NM)\}/cg 5 304 309
308 304 ▶ if (/\G\{($NM)(:?[-+])/gc) {
Branch: 1 branch
BranchTrueFalseTotal
if (/\G\{($Proc::ShellSubset::NM)(:?[-+])/cg) 55 249 304
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 463 ▶ E(/\G['"\[]/ ? 'bash-only $ form' : 'unsupported parameter form', $p) }
Branch: 1 branch
BranchTrueFalseTotal
/\G['"\[]/ ? : 28 435 463
318  
319 3898 ▶sub name {
Subroutine name: called CC=7 SCAR=19.5
Pod undocumented
320 3897 my ($n, $p) = @_;
321 E("shell-set variable '$n'", $p) if $SH{$n} || $n eq 'PWD' && $O{nopwd} || $n =~ /^(?:BASH|COMP|READLINE)_/
322 3897 ▶ || $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 3832 3897
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
6503832
$Proc::ShellSubset::SH{$n} or $n eq "PWD" and $Proc::ShellSubset::O{"nopwd"} or $n =~ /^(?:BASH|COMP|READLINE)_/
l!l&&r!l&&!r
6053832
$Proc::ShellSubset::SH{$n} or $n eq "PWD" and $Proc::ShellSubset::O{"nopwd"}
l!l&&r!l&&!r
5643837
$n eq "PWD" and $Proc::ShellSubset::O{"nopwd"}
!ll&&!rl&&r
3823144
$n =~ /^(?:PATH|SHELL|TERM|HOSTNAME)\z/ and not defined $ENV{$n}
!ll&&!rl&&r
382660
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 3832 $n }
324  
325 142 ▶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 209 ▶ /\G((?:[^`\\]|\\.)*)`/sgc or E('unterminated backquote', $p);
Branch: 1 branch
BranchTrueFalseTotal
/\G((?:[^`\\]|\\.)*)`/cgs or E("unterminated backquote", $p) 191 11 202
334 198 my ($raw, $in, @m) = ($1, '');
335 198 ▶ 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 1952 ▶ E('backslash-newline inside backquotes', $s + $-[0]) if defined $2;
Branch: 1 branch
BranchTrueFalseTotal
if defined $2 4 1941 1945
337 1949 $in .= $+; push @m, P($s + $-[$#-]) }
338 195 push @m, P(pos() - 1);
339 195 [$q . '$(', do { local $_ = $in; local $M = \@m; shell('', []) }] }
340  
341 2642 ▶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 2650 my ($l, $ok) = @_; # $ok: nothing follows this list in its shell
343 2642 for my $ch (@$l) { my @p = grep ref, @$ch;
344 3151 for my $pl (@p) { my @c = grep ref, @$pl;
345 3405 ▶ 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
5631963887
$pl == $p[-1] and $pl->[0] ne "!" and $ch->[-1] eq "&" || $ok && $ch == $l->[-1]
!ll&&!rl&&r
2876001963
$pl == $p[-1] and $pl->[0] ne "!"
!ll&&!rl&&r
252352563
$ch->[-1] eq "&" or $ok and $ch == $l->[-1]
l!l&&r!l&&!r
641899600
$ok and $ch == $l->[-1]
!ll&&!rl&&r
1354651899
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 3405 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 4246 ▶ xc($x->{group}, $last) if $x->{group};
Branch: 1 branch
BranchTrueFalseTotal
if $x->{"group"} 112 4140 4252
349 4229 ▶ 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 4219 4235
$_ % 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 4226 xc($x->{$_}, 0) for grep $x->{$_}, qw(while until do);
351 4223 ▶ if (exists $x->{case}) { xc($_, $last) for pairvalues @{$x->{in}} }
Branch: 1 branch
BranchTrueFalseTotal
if (exists $x->{"case"}) 24 4205 4229
352 4223 ▶ if (exists $x->{exec}) { my $xp = $x->{exec}; $x->{exec} = 1;
Branch: 1 branch
BranchTrueFalseTotal
if (exists $x->{"exec"}) 99 4130 4229
353 100 ▶ $x->{ERROR} = 1, die ["'exec' with something after it", $xp] if !$last } } } } }
Branch: 1 branch
BranchTrueFalseTotal
unless $last 45 54 99
354  
355 550 1;
356 __END__
« lib/Proc/ShellSubset/Large.pm ↑ Summary lib/Proc/ShellSpawn/Programs.pm »