lib/Proc/ShellSpawn/Programs.pm

filter: Statementstmt 94.8% 383 / 404 Branchbran 92.0% 335 / 364 Conditioncond 82.9% 209 / 252 MC/DCmcdc 67.1% 98 / 146 Subroutinesub 92.1% 47 / 51 Podpod 0.0% 0 / 36 totaltotal 85.5% 1072 / 1253 CC 277 SCAR 29.6
CC
277
Cov
91%
printf
43.1
pwd
31.6
echo
26.3
CRAP 19.3
« lib/Proc/ShellSubset.pm ↑ Summary blib/lib/Proc/Spawner/Loop/Win32.pm »
1 package Proc::ShellSpawn::Programs;
2 # echo, printf, test and [ (and true, false) as GNU coreutils 9.4 does them, inside the Perl process (X21; the user,
3 # 2026-11-08). The subset runs them as programs, and their behaviour is part of the subset's meaning
4 # (large-subset-state.md, section 2), so these follow coreutils, not the shells' builtins. Each function takes
5 # (ARGV, ENV, OPT) and returns (STDOUT, STDERR, STATUS, ORDER), ORDER (printf only; else undef) the same text as
6 # [FD, TEXT] pieces in the order coreutils writes them:
7 # ARGV the command's words, ARGV->[0] its name as written (the messages name it so, as coreutils does)
8 # ENV the command's environment (a hash): POSIXLY_CORRECT for echo, LC_ALL/LC_CTYPE/LC_MESSAGES/LANG for quotes
9 # OPT { isatty => CODE } for test -t FD (the command's FD, not Perl's); { cwd => DIR }: test's relative file names
10 # are taken from DIR (the shell's directory, not Perl's)
11 # Differences known (doc/pspawn-known-issues.md, X21): --help and --version print a short text; printf's floating
12 # conversions use Perl's double (coreutils: long double); %q follows gnulib's fixed rule (decision IP2).
13 # Integers go through Perl's own sprintf, so a perl with 64-bit integers is assumed (ivsize 8: Strawberry, Linux).
14 443 ▶use strict; use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
15 443 ▶use POSIX (); use File::Spec (); use Math::BigInt ();
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
16 443 our $VERSION = '0.13';
17  
18 443 my $IMAX = Math::BigInt->new('9223372036854775807'); my $IMIN = -$IMAX - 1;
19 443 my $UMAX = Math::BigInt->new('18446744073709551615');
20 443 my %CESC = ("\a" => 'a', "\b" => 'b', "\f" => 'f', "\n" => 'n', "\r" => 'r', "\t" => 't', "\013" => 'v');
21 443 my $UTF8 = qr/[\xc2-\xdf][\x80-\xbf]|\xe0[\xa0-\xbf][\x80-\xbf]|[\xe1-\xec\xee\xef][\x80-\xbf]{2}|\xed[\x80-\x9f][\x80-\xbf]
22 |\xf0[\x90-\xbf][\x80-\xbf]{2}|[\xf1-\xf3][\x80-\xbf]{3}|\xf4[\x80-\x8f][\x80-\xbf]{2}/x; # one valid character
23 1359 ▶sub utf8_locale { my ($env, @cat) = @_; (grep $_, map $env->{$_}, 'LC_ALL', @cat, 'LANG')[0] // '' }
Subroutine utf8_locale: called CC=2 SCAR=6.9
Pod undocumented
Condition100%2/2
(grep $_, map($env->{$_}, "LC_ALL", @cat, "LANG"))[0] // ""
l!l
13563
MC/DC100%1/1
(grep $_, map($env->{$_}, "LC_ALL", @cat, "LANG"))[0] // ""
(grep $_, map($env->{$_}, "LC_ALL", @cat, "LANG"))[0]
Truth table100%2/2
A
A= (grep $_, map($env->{$_}, "LC_ALL", @cat, "LANG"))[0]
Aresult
11
00
24 1359 ▶sub is_utf8 { utf8_locale(@_) =~ /utf-?8/i }
Subroutine is_utf8: called CC=1 SCAR=0.0
Pod undocumented
25 4993 ▶sub printable { my ($c, $u) = @_; # a character (one byte, or a valid UTF-8 sequence in a UTF-8 locale)
Subroutine printable: called CC=3 SCAR=11.0
Pod undocumented
26 4993 ▶ return $c =~ /\A[\x20-\x7e]\z/ if length $c == 1; return 0 unless $u; utf8::decode($c); $c =~ /\A\p{Print}\z/ }
Branch: 2 branches
BranchTrueFalseTotal
if length $c == 1 4972 21 4993
unless $u 0 21 21
27 1331 ▶sub chars { my ($s, $u) = @_; $u ? $s =~ /$UTF8|./gs : split //, $s }
Subroutine chars: called CC=2 SCAR=6.9
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
$u ? : 663 668 1331
28 82 ▶sub c_esc { my ($s, $t) = @_; # bytes that cannot be printed: each as C's escape from the table %$t, else in octal
Subroutine c_esc: called CC=2 SCAR=6.9
Pod undocumented
29 82 ▶ join '', map $t->{$_} ? "\\$t->{$_}" : sprintf('\\%03o', ord), split //, $s }
Branch: 1 branch
BranchTrueFalseTotal
$t->{$_} ? : 36 46 82
30  
31 # "The same file?" is Proc::ShellSpawn's files_eq (the user, 2026-11-14: who uses whom decides the place), loaded only
32 # when test -ef or pwd -L asks: everything else here runs without that module
33 26 ▶sub files_eq { require Proc::ShellSpawn; Proc::ShellSpawn::files_eq(@_) }
Subroutine files_eq: called CC=1 SCAR=0.0
Pod undocumented
34  
35 1305 ▶sub q_ { my ($env, $s) = @_; # coreutils' quote(): 'x' in the C locale, curly quotes in a UTF-8 one; inside, a backslash
Subroutine q_: called CC=6 SCAR=17.9
Pod undocumented
36 # doubled, control characters as C escapes, what the locale cannot print in octal, and (C locale) \' for '
37 1305 my $u = is_utf8($env, 'LC_MESSAGES');
38 my $t = join '',
39 1305 ▶ map { printable($_, $u) ? ($_ eq '\\' ? '\\\\' : $_ eq "'" && !$u ? "\\'" : $_) : c_esc($_, \%CESC) } chars($s, $u);
Branch: 3 branches
BranchTrueFalseTotal
printable($_, $u) ? : 4800 72 4872
$_ eq '\\' ? : 252 4548 4800
$_ eq q['] && !$u ? : 24 4524 4548
Condition100%3/3
$_ eq "'" and not $u
!ll&&!rl&&r
45002424
MC/DC100%2/2
$_ eq "'" and not $u
$_ eq "'" not $u
Truth table100%3/3
A and not(B)
A= $_ eq "'"B= not $u
ABresult
0X0
100
111
40 1305 ▶ $u ? "\xe2\x80\x98$t\xe2\x80\x99" : "'$t'" }
Branch: 1 branch
BranchTrueFalseTotal
$u ? : 650 655 1305
41  
42 # ------------------------------------------------------------------ echo
43 # OPT's echo (Proc::ShellSpawn: PROC_SHELLSPAWN_ECHO; decision EC1, the user, 2026-11-09) picks whose echo this is:
44 # coreutils (the default): coreutils 9.4's; POSIXLY_CORRECT in ENV changes it (escapes always, options only a first -n)
45 # dash: dash 0.5.12's builtin: escapes always (not \x), options only a first -n; POSIXLY_CORRECT changes nothing
46 # bash: bash 5.2's builtin (xpg_echo off, as bash --posix starts): options -n -e -E, escapes with -e (also \E, \u, \U)
47 443 our @ECHO = qw(coreutils dash bash);
48 1649 ▶sub echo {
Subroutine echo: called CC=26 SCAR=32.7
Pod undocumented
49 1649 ▶ my ($argv, $env, $opt) = @_; $env //= {}; my $style = ($opt && $opt->{echo}) || 'coreutils';
Condition71%5/7
$env //= {}
l!l
16490
$opt && $opt->{'echo'} || 'coreutils'
l!l
1309340
$opt and $opt->{"echo"}
!ll&&!rl&&r
34001309
MC/DC0%0/1
$env //= {}
$env
MC/DC50%1/2
$opt && $opt->{'echo'} || 'coreutils'
$opt $opt->{"echo"}
Truth table50%1/2
A
A= $env
Aresult
11
00
Truth table66%2/3
A and B
A= $optB= $opt->{"echo"}
ABresult
111
0X0
100
50 1649 my @a = @$argv[1 .. $#$argv];
51 1649 ▶ my ($nl, $esc, $mode) = (1, 0, $style eq 'coreutils' ? 'echo' : $style);
Branch: 1 branch
BranchTrueFalseTotal
$style eq 'coreutils' ? : 425 1224 1649
52 1649 ▶ if ($style eq 'dash') { $esc = 1; if (@a && $a[0] eq '-n') { shift @a; $nl = 0 } }
Branch: 4 branches
BranchTrueFalseTotal
if ($style eq 'dash') { } 856 793 1649
elsif ($style eq 'bash') { } 368 425 793
elsif ($style eq 'coreutils') { } 425 0 425
if (@a and $a[0] eq "-n") 43 813 856
Condition100%3/3
@a and $a[0] eq "-n"
!ll&&!rl&&r
5276143
MC/DC100%2/2
@a and $a[0] eq "-n"
@a $a[0] eq "-n"
Truth table100%3/3
A and B
A= @aB= $a[0] eq "-n"
ABresult
0X0
100
111
53 368 ▶ elsif ($style eq 'bash') { while (@a && $a[0] =~ /^-([eEn]+)\z/) { shift @a;
Branch: 1 branch
BranchTrueFalseTotal
if (@a and $a[0] =~ /^-([eEn]+)\z/) 174 368 542
Condition100%3/3
@a and $a[0] =~ /^-([eEn]+)\z/
!ll&&!rl&&r
66302174
MC/DC100%2/2
@a and $a[0] =~ /^-([eEn]+)\z/
@a $a[0] =~ /^-([eEn]+)\z/
Truth table100%3/3
A and B
A= @aB= $a[0] =~ /^-([eEn]+)\z/
ABresult
0X0
100
111
54 174 ▶ for (split //, $1) { $_ eq 'n' ? ($nl = 0) : ($esc = $_ eq 'e') } } }
Branch: 1 branch
BranchTrueFalseTotal
$_ eq 'n' ? : 98 126 224
55 elsif ($style eq 'coreutils') {
56 425 my $posix = defined $env->{POSIXLY_CORRECT};
57 425 $esc = $posix; # POSIXLY_CORRECT: escapes always, options only for a first -n
58 425 ▶ if (!$posix || (@a && $a[0] eq '-n')) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $posix or @a and $a[0] eq "-n") 370 55 425
Condition100%6/6
not $posix or @a and $a[0] eq "-n"
l!l&&r!l&&!r
366455
@a and $a[0] eq "-n"
!ll&&!rl&&r
14414
MC/DC100%3/3
not $posix or @a and $a[0] eq "-n"
not $posix @a $a[0] eq "-n"
Truth table100%4/4
not(A) or B and C
A= not $posixB= @aC= $a[0] eq "-n"
ABCresult
1XX1
0111
00X0
0100
59 0 ▶ if (my @i = info('echo', @a)) { return @i }
Branch: 1 branch
BranchTrueFalseTotal
if (my(@i) = info("echo", @a)) 0 370 370
60 370 ▶ while (@a && $a[0] =~ /^-([eEn]+)\z/) { shift @a;
Branch: 1 branch
BranchTrueFalseTotal
if (@a and $a[0] =~ /^-([eEn]+)\z/) 139 370 509
Condition100%3/3
@a and $a[0] =~ /^-([eEn]+)\z/
!ll&&!rl&&r
52318139
MC/DC100%2/2
@a and $a[0] =~ /^-([eEn]+)\z/
@a $a[0] =~ /^-([eEn]+)\z/
Truth table100%3/3
A and B
A= @aB= $a[0] =~ /^-([eEn]+)\z/
ABresult
0X0
100
111
61 139 ▶ for (split //, $1) { $_ eq 'n' ? ($nl = 0) : ($esc = $_ eq 'e' || $posix) } } } }
Branch: 1 branch
BranchTrueFalseTotal
$_ eq 'n' ? : 86 101 187
Condition100%3/3
$_ eq 'e' || $posix
l!l&&r!l&&!r
61238
MC/DC100%2/2
$_ eq 'e' || $posix
$_ eq 'e' $posix
Truth table100%3/3
A || B
A= $_ eq 'e'B= $posix
ABresult
1X1
011
000
62 0 else { die "PROC_SHELLSPAWN_ECHO: '$style' is none of @ECHO\n" }
63 1649 my $out = join ' ', @a;
64 1649 ▶ if ($esc) { ($out, my $stop) = esc($out, $mode, $env); return ($out, '', 0) if $stop } # \c: nothing more, not the newline
Branch: 2 branches
BranchTrueFalseTotal
if ($esc) 1034 615 1649
if $stop 72 962 1034
65 1577 ▶ ($out . ($nl ? "\n" : ''), '', 0) }
Branch: 1 branch
BranchTrueFalseTotal
$nl ? : 1375 202 1577
66  
67 # The backslash escapes of echo -e and printf's %b (MODE 'echo' or 'b'), or of printf's format ('fmt'); of dash's and
68 # bash's builtin echo (MODE 'dash', 'bash'). Returns (TEXT, STOP, ERROR): STOP after \c, ERROR for printf's "missing
69 # hexadecimal number" and "invalid universal character name". ENV: the command's environment, for \u and \U (the locale).
70 443 my %SIMPLE = (a => "\a", b => "\b", e => "\e", f => "\f", n => "\n", r => "\r", t => "\t", v => "\013", '\\' => '\\');
71 1960 ▶sub esc {
Subroutine esc: called CC=26 SCAR=32.6
Pod undocumented
72 1960 ▶ my ($s, $mode, $env) = @_; my $o = ''; my $printf = $mode eq 'b' || $mode eq 'fmt';
Condition100%3/3
$mode eq 'b' || $mode eq 'fmt'
l!l&&r!l&&!r
219051034
MC/DC100%2/2
$mode eq 'b' || $mode eq 'fmt'
$mode eq 'b' $mode eq 'fmt'
Truth table100%3/3
A || B
A= $mode eq 'b'B= $mode eq 'fmt'
ABresult
1X1
011
000
73 1960 ▶ my $oct = $mode eq 'fmt' ? qr/([0-7]{1,3})/ : $mode eq 'bash' ? qr/0([0-7]{0,3})/ # bash: \1 stays as it is
Branch: 2 branches
BranchTrueFalseTotal
$mode eq 'fmt' ? : 905 1055 1960
$mode eq 'bash' ? : 68 987 1055
74 : qr/0([0-7]{0,3})|([1-7][0-7]{0,2})/; # echo, dash and %b: \0NNN or \NNN
75 1960 ▶ while ($s =~ /\G(?:([^\\]+)|\\)/gc) {
Branch: 1 branch
BranchTrueFalseTotal
if ($s =~ /\G(?:([^\\]+)|\\)/cg) 2676 1872 4548
76 2676 ▶ if (defined $1) { $o .= $1; next }
Branch: 1 branch
BranchTrueFalseTotal
if (defined $1) 1270 1406 2676
77 1406 ▶ if ($s =~ /\G$oct/gc) { $o .= chr(oct('0' . ($1 // $2)) & 255) }
Branch: 9 branches
BranchTrueFalseTotal
if ($s =~ /\G$oct/cg) { } 86 1320 1406
elsif ($s =~ /\G([abefnrtv\\])/cg) { } 1010 310 1320
elsif ($s =~ /\Gc/cg) { } 76 234 310
elsif ($mode eq 'bash' and $s =~ /\GE/cg) { } 2 232 234
elsif ($mode ne 'dash' and $s =~ /\Gx([0-9A-Fa-f]{1,2})/cg) { } 20 212 232
elsif ($mode eq 'bash' and $s =~ /\G(?:u([0-9A-Fa-f]{1,4})|U([0-9A-Fa-f]{1,8}))/cg) { } 22 190 212
elsif ($printf and $s =~ /\G(?:(u)([0-9A-Fa-f]{4})|(U)([0-9A-Fa-f]{8}))/cg) { } 26 164 190
elsif ($printf and $s =~ /\G[xuU]/cg) { } 6 158 164
elsif ($mode eq 'fmt' and $s =~ /\G"/cg) { } 0 158 158
Condition100%3/3
$1 // $2
l!l&&r!l&&!r
52304
MC/DC100%2/2
$1 // $2
$1 $2
Truth table100%3/3
A // B
A= $1B= $2
ABresult
1X1
011
000
78 1010 elsif ($s =~ /\G([abefnrtv\\])/gc) { $o .= $SIMPLE{$1} }
79 76 elsif ($s =~ /\Gc/gc) { return ($o, 1) }
80 2 ▶ elsif ($mode eq 'bash' && $s =~ /\GE/gc) { $o .= "\e" }
Condition100%3/3
$mode eq "bash" and $s =~ /\GE/cg
!ll&&!rl&&r
176562
MC/DC100%2/2
$mode eq "bash" and $s =~ /\GE/cg
$mode eq "bash" $s =~ /\GE/cg
Truth table100%3/3
A and B
A= $mode eq "bash"B= $s =~ /\GE/cg
ABresult
0X0
100
111
81 20 ▶ elsif ($mode ne 'dash' && $s =~ /\Gx([0-9A-Fa-f]{1,2})/gc) { $o .= chr hex $1 }
Condition100%3/3
$mode ne "dash" and $s =~ /\Gx([0-9A-Fa-f]{1,2})/cg
!ll&&!rl&&r
1169620
MC/DC100%2/2
$mode ne "dash" and $s =~ /\Gx([0-9A-Fa-f]{1,2})/cg
$mode ne "dash" $s =~ /\Gx([0-9A-Fa-f]{1,2})/cg
Truth table100%3/3
A and B
A= $mode ne "dash"B= $s =~ /\Gx([0-9A-Fa-f]{1,2})/cg
ABresult
0X0
100
111
82 22 ▶ elsif ($mode eq 'bash' && $s =~ /\G(?:u([0-9A-Fa-f]{1,4})|U([0-9A-Fa-f]{1,8}))/gc) { $o .= bash_unichar(hex($1 // $2), $env) }
Condition83%5/6
$mode eq "bash" and $s =~ /\G(?:u([0-9A-Fa-f]{1,4})|U([0-9A-Fa-f]{1,8}))/cg
!ll&&!rl&&r
1642622
$1 // $2
l!l&&r!l&&!r
8140
MC/DC100%2/2
$mode eq "bash" and $s =~ /\G(?:u([0-9A-Fa-f]{1,4})|U([0-9A-Fa-f]{1,8}))/cg
$mode eq "bash" $s =~ /\G(?:u([0-9A-Fa-f]{1,4})|U([0-9A-Fa-f]{1,8}))/cg
MC/DC0%0/2
$1 // $2
$1 $2
Truth table100%3/3
A and B
A= $mode eq "bash"B= $s =~ /\G(?:u([0-9A-Fa-f]{1,4})|U([0-9A-Fa-f]{1,8}))/cg
ABresult
0X0
100
111
Truth table66%2/3
A // B
A= $1B= $2
ABresult
1X1
011
000
83 ▶ elsif ($printf && $s =~ /\G(?:(u)([0-9A-Fa-f]{4})|(U)([0-9A-Fa-f]{8}))/gc) {
Condition100%3/3
$printf and $s =~ /\G(?:(u)([0-9A-Fa-f]{4})|(U)([0-9A-Fa-f]{8}))/cg
!ll&&!rl&&r
156826
MC/DC100%2/2
$printf and $s =~ /\G(?:(u)([0-9A-Fa-f]{4})|(U)([0-9A-Fa-f]{8}))/cg
$printf $s =~ /\G(?:(u)([0-9A-Fa-f]{4})|(U)([0-9A-Fa-f]{8}))/cg
Truth table100%3/3
A and B
A= $printfB= $s =~ /\G(?:(u)([0-9A-Fa-f]{4})|(U)([0-9A-Fa-f]{8}))/cg
ABresult
0X0
100
111
84 26 ▶ my ($k, $h) = defined $1 ? ($1, $2) : ($3, $4); my $v = hex $h;
Branch: 1 branch
BranchTrueFalseTotal
defined $1 ? : 18 8 26
85 26 ▶ return ($o, 0, "invalid universal character name \\$k\L$h") if $v >= 0xd800 && $v <= 0xdfff; # (coreutils: \%c%0*x)
Branch: 1 branch
BranchTrueFalseTotal
if $v >= 55296 and $v <= 57343 6 20 26
Condition100%3/3
$v >= 55296 and $v <= 57343
!ll&&!rl&&r
1466
MC/DC100%2/2
$v >= 55296 and $v <= 57343
$v >= 55296 $v <= 57343
Truth table100%3/3
A and B
A= $v >= 55296B= $v <= 57343
ABresult
0X0
100
111
86 20 $o .= unichar($v, $env) }
87 6 ▶ elsif ($printf && $s =~ /\G[xuU]/gc) { return ($o, 0, 'missing hexadecimal number in escape') }
Condition100%3/3
$printf and $s =~ /\G[xuU]/cg
!ll&&!rl&&r
15626
MC/DC100%2/2
$printf and $s =~ /\G[xuU]/cg
$printf $s =~ /\G[xuU]/cg
Truth table100%3/3
A and B
A= $printfB= $s =~ /\G[xuU]/cg
ABresult
0X0
100
111
88 0 ▶ elsif ($mode eq 'fmt' && $s =~ /\G"/gc) { $o .= '"' }
Condition66%2/3
$mode eq "fmt" and $s =~ /\G"/cg
!ll&&!rl&&r
15620
MC/DC0%0/2
$mode eq "fmt" and $s =~ /\G"/cg
$mode eq "fmt" $s =~ /\G"/cg
Truth table66%2/3
A and B
A= $mode eq "fmt"B= $s =~ /\G"/cg
ABresult
0X0
100
111
89 158 else { $o .= '\\' } # anything else (and a final backslash): the backslash as it is
90 }
91 1872 ($o, 0) }
92  
93 22 ▶sub bash_unichar { # bash 5.2's \u and \U in echo -e (u32cconv): ASCII as it is; in a UTF-8 locale (LC_CTYPE) the
Subroutine bash_unichar: called CC=5 SCAR=16.1
Pod undocumented
94 # character in UTF-8's old form up to 6 bytes (surrogates too), else the escape \uXXXX or \UXXXXXXXX; above 0x7FFFFFFF
95 # nothing (checked against bash 5.2.21 in C and C.UTF-8)
96 22 my ($v, $env) = @_;
97 22 ▶ return '' if $v > 0x7fffffff; return chr $v if $v < 0x80;
Branch: 2 branches
BranchTrueFalseTotal
if $v > 2147483647 2 20 22
if $v < 128 4 16 20
98 16 ▶ return sprintf($v <= 0xffff ? '\\u%04X' : '\\U%08X', $v) unless is_utf8($env, 'LC_CTYPE');
Branch: 2 branches
BranchTrueFalseTotal
unless is_utf8($env, "LC_CTYPE") 8 8 16
$v <= 65535 ? : 3 5 8
99 8 my $c = chr $v; utf8::encode($c); $c } # (Perl's own encoder writes that old form; utf8::encode is built in: no module)
100  
101 20 ▶sub unichar { # gnulib's print_unicode_char, as coreutils 9.4's printf uses it (X37): ASCII as it is; another character
Subroutine unichar: called CC=6 SCAR=17.9
Pod undocumented
102 # encoded where the locale can (here: a UTF-8 locale), else (the C locale) the escape \uXXXX or \UXXXXXXXX, as above
103 # U+10FFFF everywhere. (A legacy locale such as ISO-8859-1, which coreutils would convert to by iconv, gets the escape.)
104 20 my ($v, $env) = @_;
105 20 ▶ return chr $v if $v < 0x80;
Branch: 1 branch
BranchTrueFalseTotal
if $v < 128 6 14 20
106 14 ▶ if ($v <= 0x10ffff && is_utf8($env // {}, 'LC_CTYPE')) { my $c = chr $v; utf8::encode($c); return $c }
Branch: 1 branch
BranchTrueFalseTotal
if ($v <= 1114111 and is_utf8($env // {}, "LC_CTYPE")) 6 8 14
Condition80%4/5
$v <= 1114111 and is_utf8($env // {}, "LC_CTYPE")
!ll&&!rl&&r
266
$env // {}
l!l
120
MC/DC100%2/2
$v <= 1114111 and is_utf8($env // {}, "LC_CTYPE")
$v <= 1114111 is_utf8($env // {}, "LC_CTYPE")
MC/DC0%0/1
$env // {}
$env
Truth table100%3/3
A and B
A= $v <= 1114111B= is_utf8($env // {}, "LC_CTYPE")
ABresult
0X0
100
111
Truth table50%1/2
A
A= $env
Aresult
11
00
107 8 ▶ sprintf $v < 0x10000 ? '\u%04X' : '\U%08X', $v }
Branch: 1 branch
BranchTrueFalseTotal
$v < 65536 ? : 4 4 8
108  
109 # ------------------------------------------------------------------ printf
110 # coreutils' printf.c: the flags each conversion takes (' and I not with a A c e E o s x X, # not with c d i s u, 0 not
111 # with c s, a precision not with c); %b and %q take nothing between % and the letter.
112 443 my %NOT = ("'" => 'aAceEosxX', I => 'aAceEosxX', '#' => 'cdisu', 0 => 'cs');
113 1142 ▶sub printf {
Subroutine printf: called CC=43 SCAR=37.6
Pod undocumented
114 1142 ▶ my ($argv, $env) = @_; $env //= {};
Condition50%1/2
$env //= {}
l!l
11420
MC/DC0%0/1
$env //= {}
$env
Truth table50%1/2
A
A= $env
Aresult
11
00
115 1142 my ($name, @a) = @$argv;
116 0 ▶ if (my @i = info('printf', @a)) { return @i }
Branch: 1 branch
BranchTrueFalseTotal
if (my(@i) = info("printf", @a)) 0 1142 1142
117 1142 ▶ shift @a if @a && $a[0] eq '--';
Branch: 1 branch
BranchTrueFalseTotal
if @a and $a[0] eq "--" 2 1140 1142
Condition100%3/3
@a and $a[0] eq "--"
!ll&&!rl&&r
211382
MC/DC100%2/2
@a and $a[0] eq "--"
@a $a[0] eq "--"
Truth table100%3/3
A and B
A= @aB= $a[0] eq "--"
ABresult
0X0
100
111
118 1142 ▶ return ('', "$name: missing operand\nTry '$name --help' for more information.\n", 1) unless @a;
Branch: 1 branch
BranchTrueFalseTotal
unless @a 2 1140 1142
119 1140 my $fmt = shift @a;
120 1140 my ($out, $err, $bad, $flushed, @seq) = ('', '', 0, 0);
121 1140 ▶ my $msg = sub { push @seq, [1, substr $out, $flushed], [2, "$name: $_[0]\n"]; $flushed = length $out; $err .= "$name: $_[0]\n" };
Subroutine __ANON__: called CC=1 SCAR=0.0
122 1140 ▶ my $warn = sub { $msg->(q_($env, $_[0]) . ": $_[1]"); $bad = 1 };
Subroutine __ANON__: called CC=1 SCAR=0.0
123 1140 ▶ my $done = sub { ($out, $err, $_[0] // $bad, [@seq, [1, substr $out, $flushed]]) };
Subroutine __ANON__: called CC=2 SCAR=7.1
Condition66%2/3
$_[0] // $bad
l!l&&r!l&&!r
3527880
MC/DC0%0/2
$_[0] // $bad
$_[0] $bad
Truth table66%2/3
A // B
A= $_[0]B= $bad
ABresult
1X1
011
000
124 1936 ▶ my $num = sub { # an argument as a number, with coreutils' messages; KIND i (intmax_t), u (uintmax_t), f (double)
Subroutine __ANON__: called CC=22 SCAR=30.9
125 1936 my ($s, $kind) = @_;
126 1936 ▶ return 0 if !defined $s || $s eq '';
Branch: 1 branch
BranchTrueFalseTotal
if not defined $s or $s eq "" 622 1314 1936
Condition100%3/3
not defined $s or $s eq ""
l!l&&r!l&&!r
532901314
MC/DC100%2/2
not defined $s or $s eq ""
not defined $s $s eq ""
Truth table100%3/3
not(A) or B
A= not defined $sB= $s eq ""
ABresult
1X1
011
000
127 1314 ▶ if ($s =~ /^\s*['"](.)(.*)/s) { # 'c: the character's code (a warning for more, the status kept)
Branch: 1 branch
BranchTrueFalseTotal
if ($s =~ /^\s*['"](.)(.*)/s) 36 1278 1314
128 36 ▶ $msg->("warning: $2: character(s) following character constant have been ignored") if length $2; return ord $1 }
Branch: 1 branch
BranchTrueFalseTotal
if length $2 2 34 36
129 1278 ▶ if ($kind eq 'f') {
Branch: 1 branch
BranchTrueFalseTotal
if ($kind eq "f") 566 712 1278
130 566 ▶ my ($v, $left) = POSIX::strtod($s); $left //= length $s;
Condition33%1/3
$left //= length $s
l!l&&r!l&&!r
56600
MC/DC0%0/2
$left //= length $s
$left length $s
Truth table33%1/3
A //= B
A= $leftB= length $s
ABresult
1X1
011
000
131 566 ▶ $warn->($s, $left == length $s ? 'expected a numeric value' : 'value not completely converted') if $left;
Branch: 2 branches
BranchTrueFalseTotal
if $left 346 220 566
$left == length $s ? : 312 34 346
132 566 ▶ return $left == length $s ? 0 : $v }
Branch: 1 branch
BranchTrueFalseTotal
$left == length $s ? : 312 254 566
133 my ($sign, $body, $rest) = $s =~ /^\s*([-+]?)(0[xX][0-9A-Fa-f]+|0[0-7]*|[1-9][0-9]*)(.*)\z/s
134 712 ▶ or do { $warn->($s, 'expected a numeric value'); return 0 };
Branch: 1 branch
BranchTrueFalseTotal
() = $s =~ /^\s*([-+]?)(0[xX][0-9A-Fa-f]+|0[0-7]*|[1-9][0-9]*)(.*)\z/s or do { &$warn($s, "expected a numeric value"); return 0 } 374 338 712
135 374 ▶ my $from = $body =~ /^0[xX]/ ? 'from_hex' : $body =~ /^0./ ? 'from_oct' : 'new';
Branch: 2 branches
BranchTrueFalseTotal
$body =~ /^0[xX]/ ? : 18 356 374
$body =~ /^0./ ? : 28 328 356
136 374 my $v = Math::BigInt->$from($body);
137 374 ▶ $v->bneg if $sign eq '-';
Branch: 1 branch
BranchTrueFalseTotal
if $sign eq "-" 62 312 374
138 374 ▶ my ($lo, $hi) = $kind eq 'u' ? (-$UMAX, $UMAX) : ($IMIN, $IMAX); # (strtoumax: -N is 2**64 - N)
Branch: 1 branch
BranchTrueFalseTotal
$kind eq 'u' ? : 244 130 374
139 374 ▶ if ($v < $lo || $v > $hi) { $warn->($s, 'Numerical result out of range'); $v = $kind eq 'u' || $v > 0 ? $hi : $lo }
Branch: 3 branches
BranchTrueFalseTotal
if ($v < $lo or $v > $hi) { } 32 342 374
elsif (length $rest) { } 105 237 342
$kind eq 'u' || $v > 0 ? : 18 14 32
Condition83%5/6
$v < $lo or $v > $hi
l!l&&r!l&&!r
1418342
$kind eq "u" or $v > 0
l!l&&r!l&&!r
01814
MC/DC100%2/2
$v < $lo or $v > $hi
$v < $lo $v > $hi
MC/DC50%1/2
$kind eq "u" or $v > 0
$kind eq "u" $v > 0
Truth table100%3/3
A or B
A= $v < $loB= $v > $hi
ABresult
1X1
011
000
Truth table66%2/3
A or B
A= $kind eq "u"B= $v > 0
ABresult
1X1
011
000
140 105 elsif (length $rest) { $warn->($s, 'value not completely converted') }
141 374 ▶ $v += $UMAX + 1 if $v < 0 && $kind eq 'u';
Branch: 1 branch
BranchTrueFalseTotal
if $v < 0 and $kind eq "u" 34 340 374
Condition100%3/3
$v < 0 and $kind eq "u"
!ll&&!rl&&r
3122834
MC/DC100%2/2
$v < 0 and $kind eq "u"
$v < 0 $kind eq "u"
Truth table100%3/3
A and B
A= $v < 0B= $kind eq "u"
ABresult
0X0
100
111
142 1140 "$v" };
143 1140 my $used;
144 1140 while (1) {
145 1553 my $took = 0;
146 1553 ▶ while ($fmt =~ /\G(?:([^%\\]+)|\\(0?[0-7]{1,3}|x[0-9A-Fa-f]{0,2}|u[0-9A-Fa-f]{0,4}|U[0-9A-Fa-f]{0,8}|.?)|%(%)|%([bq])
Branch: 1 branch
BranchTrueFalseTotal
if ($fmt =~ /\G(?:([^%\\]+)|\\(0?[0-7]{1,3}|x[0-9A-Fa-f]{0,2}|u[0-9A-Fa-f]{0,4}|U[0-9A-Fa-f]{0,8}|.?)|%(%)|%([bq]) |%([-+ #0'I]*)(\*|[0-9]*)(?:\.(\*|[0-9]*))?[lLhjtz]*(.?))/cgsx) 4908 1197 6105
147 |%([-+ #0'I]*)(\*|[0-9]*)(?:\.(\*|[0-9]*))?[lLhjtz]*(.?))/gcsx) {
148 4908 my ($text, $e, $pct, $bq, $fl, $w, $p, $cv, $from) = ($1, $2, $3, $4, $5, $6, $7, $8, $-[0]);
149 4908 ▶ if (defined $text) { $out .= $text; next }
Branch: 1 branch
BranchTrueFalseTotal
if (defined $text) 1444 3464 4908
150 3464 ▶ if (defined $pct) { $out .= '%'; next }
Branch: 1 branch
BranchTrueFalseTotal
if (defined $pct) 3 3461 3464
151 3461 ▶ if (defined $e) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $e) 905 2556 3461
152 905 my ($t, $stop, $error) = esc("\\$e", 'fmt', $env); $out .= $t;
153 905 ▶ if ($error) { $msg->($error); return $done->(1) }
Branch: 1 branch
BranchTrueFalseTotal
if ($error) 8 897 905
154 897 ▶ return $done->() if $stop; next }
Branch: 1 branch
BranchTrueFalseTotal
if $stop 2 895 897
155 2556 ▶ $cv = $bq, $fl = $w = '' if defined $bq;
Branch: 1 branch
BranchTrueFalseTotal
if defined $bq 51 2505 2556
156 2556 ▶ if (!defined $bq && ($cv !~ /^[aAcdeEfFgGiosuxX]\z/ || grep(index($NOT{$_} // "", $cv) >= 0, split //, $fl)
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $bq and !($cv =~ /^[aAcdeEfFgGiosuxX]\z/) || grep(index($NOT{$_} // "", $cv) != -1, split(//, $fl, 0)) || defined $p && $cv eq "c") 340 2216 2556
Condition100%14/14
not defined $bq and !($cv =~ /^[aAcdeEfFgGiosuxX]\z/) || grep(index($NOT{$_} // "", $cv) != -1, split(//, $fl, 0)) || defined $p && $cv eq "c"
!ll&&!rl&&r
512165340
not $cv =~ /^[aAcdeEfFgGiosuxX]\z/ or grep index($NOT{$_} // "", $cv) != -1, split(//, $fl, 0) or defined $p and $cv eq "c"
l!l&&r!l&&!r
322182165
not $cv =~ /^[aAcdeEfFgGiosuxX]\z/ or grep index($NOT{$_} // "", $cv) != -1, split(//, $fl, 0)
l!l&&r!l&&!r
1921302183
$NOT{$_} // ""
l!l
8201669
defined $p and $cv eq "c"
!ll&&!rl&&r
139477118
MC/DC100%5/5
not defined $bq and !($cv =~ /^[aAcdeEfFgGiosuxX]\z/) || grep(index($NOT{$_} // "", $cv) != -1, split(//, $fl, 0)) || defined $p && $cv eq "c"
not defined $bq not $cv =~ /^[aAcdeEfFgGiosuxX]\z/ grep index($NOT{$_} // "", $cv) != -1, split(//, $fl, 0) defined $p $cv eq "c"
MC/DC100%1/1
$NOT{$_} // ""
$NOT{$_}
Truth table100%6/6
not(A) and not(B) or C or D and E
A= not defined $bqB= not $cv =~ /^[aAcdeEfFgGiosuxX]\z/C= grep index($NOT{$_} // "", $cv) != -1, split(//, $fl, 0)D= defined $pE= $cv eq "c"
ABCDEresult
0XXXX0
1000X0
100100
11XXX1
101XX1
100111
Truth table100%2/2
A
A= $NOT{$_}
Aresult
11
00
157 || defined $p && $cv eq 'c')) {
158 340 $msg->(substr($fmt, $from, pos($fmt) - $from) . ": invalid conversion specification"); return $done->(1) } # (as written)
159 2216 $used = 1;
160 2216 ▶ if ($w eq '*') { $w = 0 + $num->(shift(@a), 'i'); $took++; $fl .= '-', $w = -$w if $w < 0 }
Branch: 2 branches
BranchTrueFalseTotal
if ($w eq "*") 5 2211 2216
if $w < 0 0 5 5
161 2216 ▶ if (defined $p && $p eq '*') { $p = 0 + $num->(shift(@a), 'i'); $took++; undef $p if $p < 0 }
Branch: 2 branches
BranchTrueFalseTotal
if (defined $p and $p eq "*") 2 2214 2216
if $p < 0 0 2 2
Condition100%3/3
defined $p and $p eq "*"
!ll&&!rl&&r
14457692
MC/DC100%2/2
defined $p and $p eq "*"
defined $p $p eq "*"
Truth table100%3/3
A and B
A= defined $pB= $p eq "*"
ABresult
0X0
100
111
162 2216 ▶ my $arg = shift @a; $took++ if defined $arg;
Branch: 1 branch
BranchTrueFalseTotal
if defined $arg 1622 594 2216
163 2216 $fl =~ tr/'I//d; # (grouping, the locale's digits: none in the C locale)
164 2216 ▶ my $spec = "%$fl$w" . (defined $p ? ".$p" : '');
Branch: 1 branch
BranchTrueFalseTotal
defined $p ? : 771 1445 2216
165 2216 ▶ if ($cv eq 'q') { $out .= shell_quote($arg, $env) if defined $arg } # (no argument: nothing)
Branch: 7 branches
BranchTrueFalseTotal
if ($cv eq 'q') { } 30 2186 2216
elsif ($cv eq 'b') { } 21 2165 2186
elsif ($cv eq 's') { } 169 1996 2165
elsif ($cv eq 'c') { } 67 1929 1996
elsif ($cv =~ /[di]/) { } 361 1568 1929
elsif ($cv =~ /[ouxX]/) { } 736 832 1568
if defined $arg 26 4 30
166 elsif ($cv eq 'b') {
167 21 ▶ my ($t, $stop, $error) = esc($arg // '', 'b', $env);
Condition100%2/2
$arg // ""
l!l
192
MC/DC100%1/1
$arg // ""
$arg
Truth table100%2/2
A
A= $arg
Aresult
11
00
168 21 ▶ if ($error) { $out .= $t; $msg->($error); return $done->(1) } # what came before the bad escape, as coreutils
Branch: 1 branch
BranchTrueFalseTotal
if ($error) 4 17 21
169 17 ▶ $out .= sprintf "${spec}s", $t; return $done->() if $stop }
Branch: 1 branch
BranchTrueFalseTotal
if $stop 2 15 17
170 169 ▶ elsif ($cv eq 's') { $out .= sprintf "${spec}s", $arg // '' }
Condition100%2/2
$arg // ""
l!l
12940
MC/DC100%1/1
$arg // ""
$arg
Truth table100%2/2
A
A= $arg
Aresult
11
00
171 67 ▶ elsif ($cv eq 'c') { my $c = substr $arg // '', 0, 1; $out .= sprintf "${spec}s", length $c ? $c : "\0" } # (none: a NUL)
Branch: 1 branch
BranchTrueFalseTotal
length $c ? : 49 18 67
Condition100%2/2
$arg // ""
l!l
5116
MC/DC100%1/1
$arg // ""
$arg
Truth table100%2/2
A
A= $arg
Aresult
11
00
172 361 elsif ($cv =~ /[di]/) { $out .= sprintf "${spec}d", $num->($arg, 'i') }
173 736 elsif ($cv =~ /[ouxX]/) { $out .= sprintf "$spec$cv", $num->($arg, 'u') }
174 832 else { $out .= float($spec, $fl, $w, $p, $cv, $num->($arg, 'f'), $arg) } }
175 1197 ▶ last unless @a && $took;
Branch: 1 branch
BranchTrueFalseTotal
unless @a and $took 784 413 1197
Condition100%3/3
@a and $took
!ll&&!rl&&r
7822413
MC/DC100%2/2
@a and $took
@a $took
Truth table100%3/3
A and B
A= @aB= $took
ABresult
0X0
100
111
176 413 pos $fmt = 0 }
177 784 ▶ $msg->("warning: ignoring excess arguments, starting with " . q_($env, $a[0])) if @a && !$used;
Branch: 1 branch
BranchTrueFalseTotal
if @a and not $used 2 782 784
Condition66%2/3
@a and not $used
!ll&&!rl&&r
78202
MC/DC50%1/2
@a and not $used
@a not $used
Truth table66%2/3
A and not(B)
A= @aB= not $used
ABresult
0X0
100
111
178 784 $done->() }
179  
180 832 ▶sub float { # a floating conversion: Perl's sprintf, but inf and nan as glibc writes them, and an integer below 2**64
Subroutine float: called CC=17 SCAR=28.5
Pod undocumented
181 832 my ($spec, $fl, $w, $p, $cv, $v, $arg) = @_; # under %f exact, as coreutils' long double has it (a double rounds)
182 832 ▶ my $sign = $fl =~ /\+/ ? '+' : $fl =~ / / ? ' ' : '';
Branch: 2 branches
BranchTrueFalseTotal
$fl =~ /\+/ ? : 188 644 832
$fl =~ / / ? : 118 526 644
183 832 ▶ if ($v != $v || abs $v == 9**9**9) {
Branch: 1 branch
BranchTrueFalseTotal
if ($v != $v or abs $v == "Inf") 44 788 832
Condition100%3/3
$v != $v or abs $v == "Inf"
l!l&&r!l&&!r
1232788
MC/DC100%2/2
$v != $v or abs $v == "Inf"
$v != $v abs $v == "Inf"
Truth table100%3/3
A or B
A= $v != $vB= abs $v == "Inf"
ABresult
1X1
011
000
184 44 ▶ my $t = ($v < 0 ? '-' : $sign) . ($v != $v ? 'nan' : 'inf');
Branch: 2 branches
BranchTrueFalseTotal
$v < 0 ? : 12 32 44
$v != $v ? : 12 32 44
185 44 ▶ return pad($fl =~ tr/0//dr, $w, $cv =~ /[EFGA]/ ? uc $t : $t) }
Branch: 1 branch
BranchTrueFalseTotal
$cv =~ /[EFGA]/ ? : 20 24 44
186 788 ▶ if ($cv =~ /[fF]/ && defined $arg && $arg =~ /^\s*([-+]?)0*([0-9]{16,20})\s*\z/ && Math::BigInt->new($2) <= $UMAX) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cv =~ /[fF]/ and defined $arg and $arg =~ /^\s*([-+]?)0*([0-9]{16,20})\s*\z/ and "Math::BigInt"->new($2) <= $UMAX) 10 778 788
Condition88%8/9
$cv =~ /[fF]/ and defined $arg and $arg =~ /^\s*([-+]?)0*([0-9]{16,20})\s*\z/ and "Math::BigInt"->new($2) <= $UMAX
!ll&&!rl&&r
778010
$cv =~ /[fF]/ and defined $arg and $arg =~ /^\s*([-+]?)0*([0-9]{16,20})\s*\z/
!ll&&!rl&&r
67610210
$cv =~ /[fF]/ and defined $arg
!ll&&!rl&&r
63442112
MC/DC75%3/4
$cv =~ /[fF]/ and defined $arg and $arg =~ /^\s*([-+]?)0*([0-9]{16,20})\s*\z/ and "Math::BigInt"->new($2) <= $UMAX
$cv =~ /[fF]/ defined $arg $arg =~ /^\s*([-+]?)0*([0-9]{16,20})\s*\z/ "Math::BigInt"->new($2) <= $UMAX
Truth table80%4/5
A and B and C and D
A= $cv =~ /[fF]/B= defined $argC= $arg =~ /^\s*([-+]?)0*([0-9]{16,20})\s*\z/D= "Math::BigInt"->new($2) <= $UMAX
ABCDresult
0XXX0
10XX0
110X0
11100
11111
187 10 ▶ my $prec = $p // 6; $prec ||= 0;
Condition75%3/4
$p // 6
l!l
46
$prec ||= 0
l!l
100
MC/DC100%1/1
$p // 6
$p
MC/DC0%0/1
$prec ||= 0
$prec
Truth table100%2/2
A
A= $p
Aresult
11
00
Truth table50%1/2
A
A= $prec
Aresult
11
00
188 10 ▶ return pad($fl, $w, ($1 eq '-' ? '-' : $sign) . $2 . ($prec || $fl =~ /#/ ? '.' . '0' x $prec : '')) }
Branch: 2 branches
BranchTrueFalseTotal
$1 eq '-' ? : 4 6 10
$prec || $fl =~ /#/ ? : 10 0 10
Condition33%1/3
$prec or $fl =~ /#/
l!l&&r!l&&!r
1000
MC/DC0%0/2
$prec or $fl =~ /#/
$prec $fl =~ /#/
Truth table33%1/3
A or B
A= $precB= $fl =~ /#/
ABresult
1X1
011
000
189 778 sprintf "$spec$cv", $v }
190 54 ▶sub pad { my ($fl, $w, $t) = @_; # a number's text in WIDTH, by the flags - and 0 (zeros after the sign)
Subroutine pad: called CC=5 SCAR=16.3
Pod undocumented
191 54 ▶ my $n = ($w || 0) - length $t; return $t if $n <= 0;
Branch: 1 branch
BranchTrueFalseTotal
if $n <= 0 44 10 54
Condition100%2/2
$w || 0
l!l
1638
MC/DC100%1/1
$w || 0
$w
Truth table100%2/2
A
A= $w
Aresult
11
00
192 0 ▶ $fl =~ /-/ ? $t . ' ' x $n : $fl =~ /0/ ? $t =~ s/^([-+ ]?)/$1 . '0' x $n/er : ' ' x $n . $t }
Branch: 2 branches
BranchTrueFalseTotal
$fl =~ /-/ ? : 2 8 10
$fl =~ /0/ ? : 0 8 8
193  
194 # %q: gnulib's quotearg in shell_escape_quoting_style, as coreutils' printf, with gnulib's later fix (decision IP2): a
195 # word needing no quotes as it is; else in '...', a ' as '\'', what must be escaped (controls; what the locale cannot
196 # print, byte by byte in octal) in $'...' runs; a word whose only trouble is a ' (and spaces, #, ~ in front) in "...".
197 443 my %QESC = (%CESC, "\0" => '0');
198 26 ▶sub shell_quote {
Subroutine shell_quote: called CC=13 SCAR=25.7
Pod undocumented
199 26 ▶ my ($w, $env) = @_; my $u = is_utf8($env // {}, 'LC_CTYPE');
Condition50%1/2
$env // {}
l!l
260
MC/DC0%0/1
$env // {}
$env
Truth table50%1/2
A
A= $env
Aresult
11
00
200 26 my @c = chars($w, $u); my $plain = !grep !printable($_, $u), @c;
201 26 ▶ return $w if $w ne '' && $plain && $w !~ /[\\?'\s!"\$&()*;<=>\[^`|]|^[#~]|^[{}]\z/;
Branch: 1 branch
BranchTrueFalseTotal
if $w ne "" and $plain and not $w =~ /[\\?'\s!"\$&()*;<=>\[^`|]|^[#~]|^[{}]\z/ 9 17 26
Condition100%6/6
$w ne "" and $plain and not $w =~ /[\\?'\s!"\$&()*;<=>\[^`|]|^[#~]|^[{}]\z/
!ll&&!rl&&r
989
$w ne "" and $plain
!ll&&!rl&&r
2717
MC/DC100%3/3
$w ne "" and $plain and not $w =~ /[\\?'\s!"\$&()*;<=>\[^`|]|^[#~]|^[{}]\z/
$w ne "" $plain not $w =~ /[\\?'\s!"\$&()*;<=>\[^`|]|^[#~]|^[{}]\z/
Truth table100%4/4
A and B and not(C)
A= $w ne ""B= $plainC= not $w =~ /[\\?'\s!"\$&()*;<=>\[^`|]|^[#~]|^[{}]\z/
ABCresult
0XX0
10X0
1100
1111
202 17 ▶ return qq{"$w"} if $plain && $w =~ /'/ && $w !~ /[\\?!"\$&()*;<=>\[^`|{}]|.[#~]/s;
Branch: 1 branch
BranchTrueFalseTotal
if $plain and $w =~ /'/ and not $w =~ /[\\?!"\$&()*;<=>\[^`|{}]|.[#~]/s 2 15 17
Condition83%5/6
$plain and $w =~ /'/ and not $w =~ /[\\?!"\$&()*;<=>\[^`|{}]|.[#~]/s
!ll&&!rl&&r
1502
$plain and $w =~ /'/
!ll&&!rl&&r
782
MC/DC66%2/3
$plain and $w =~ /'/ and not $w =~ /[\\?!"\$&()*;<=>\[^`|{}]|.[#~]/s
$plain $w =~ /'/ not $w =~ /[\\?!"\$&()*;<=>\[^`|{}]|.[#~]/s
Truth table75%3/4
A and B and not(C)
A= $plainB= $w =~ /'/C= not $w =~ /[\\?!"\$&()*;<=>\[^`|{}]|.[#~]/s
ABCresult
0XX0
10X0
1100
1111
203 15 my ($q, $dollar) = ("'", 0);
204 15 for (@c) {
205 44 ▶ if (!printable($_, $u)) { $q .= q{'$'} unless $dollar; $dollar = 1; $q .= c_esc($_, \%QESC) }
Branch: 3 branches
BranchTrueFalseTotal
if (not printable($_, $u)) { } 10 34 44
elsif ($_ eq q[']) { } 4 30 34
unless $dollar 9 1 10
206 4 elsif ($_ eq "'") { $q .= q{'\''}; $dollar = 0 }
207 30 ▶ else { $q .= "''" if $dollar; $dollar = 0; $q .= $_ } }
Branch: 1 branch
BranchTrueFalseTotal
if $dollar 0 30 30
208 15 "$q'" }
209  
210 # ------------------------------------------------------------------ test and [
211 # coreutils' grammar: with 1 to 4 arguments the POSIX rules, else (and inside them where they say so) the expression
212 # -o, -a, !, ( ), -l STRING as an integer. The words are consumed from @W; for [, the ] stays in $BEYOND, past the
213 # end, where coreutils' messages still see it ("')' expected, found ']'").
214 443 my %UNARY = map +($_ => 1), qw(-b -c -d -e -f -g -G -h -k -L -N -O -p -r -s -S -t -u -w -x -z -n);
215 443 my %BINARY = map +($_ => 1), qw(= == != -eq -ne -lt -le -gt -ge -nt -ot -ef);
216 443 our (@W, $LAST, $BEYOND, $CMDENV, $OPT);
217 881 ▶sub test {
Subroutine test: called CC=14 SCAR=26.6
Pod undocumented
218 881 my ($argv, $env, $opt) = @_;
219 881 my ($name, @a) = @$argv; my $br = $name =~ m{(?:^|/)\[\z};
220 881 ▶ if ($br) {
Branch: 1 branch
BranchTrueFalseTotal
if ($br) 296 585 881
221 0 ▶ if (my @i = info('[', @a)) { return @i }
Branch: 1 branch
BranchTrueFalseTotal
if (my(@i) = info("[", @a)) 0 296 296
222 296 ▶ return ('', "$name: missing " . q_($env // {}, ']') . "\n", 2) unless @a && pop(@a) eq ']' }
Branch: 1 branch
BranchTrueFalseTotal
unless @a and pop @a eq "]" 2 294 296
Condition60%3/5
@a and pop @a eq "]"
!ll&&!rl&&r
02294
$env // {}
l!l
20
MC/DC50%1/2
@a and pop @a eq "]"
@a pop @a eq "]"
MC/DC0%0/1
$env // {}
$env
Truth table66%2/3
A and B
A= @aB= pop @a eq "]"
ABresult
0X0
100
111
Truth table50%1/2
A
A= $env
Aresult
11
00
223 879 ▶ local (@W, $LAST, $BEYOND, $CMDENV, $OPT) = (@a); ($LAST, $BEYOND, $CMDENV, $OPT) = ($a[-1], $br ? ']' : undef, $env // {}, $opt // {});
Branch: 1 branch
BranchTrueFalseTotal
$br ? : 294 585 879
Condition75%3/4
$env // {}
l!l
8790
$opt // {}
l!l
34845
MC/DC0%0/1
$env // {}
$env
MC/DC100%1/1
$opt // {}
$opt
Truth table50%1/2
A
A= $env
Aresult
11
00
Truth table100%2/2
A
A= $opt
Aresult
11
00
224 879 ▶ my $r = eval { my $v = @W ? posix(scalar @W) : 0; die "extra argument " . q_($CMDENV, $W[0]) . "\n" if @W; $v ? 1 : 0 };
Branch: 3 branches
BranchTrueFalseTotal
@Proc::ShellSpawn::Programs::W ? : 742 137 879
if @Proc::ShellSpawn::Programs::W 164 409 573
$v ? : 192 217 409
225 879 ▶ defined $r ? ('', '', $r ? 0 : 1) : ('', "$name: " . $@, 2) }
Branch: 2 branches
BranchTrueFalseTotal
defined $r ? : 409 470 879
$r ? : 192 217 409
226  
227 74 ▶sub beyond { die "missing argument after " . q_($CMDENV, $LAST) . "\n" }
Subroutine beyond: called CC=1 SCAR=0.0
Pod undocumented
228 80 ▶sub next_word { shift @W; beyond() unless @W; 1 } # coreutils' advance(true)
Subroutine next_word: called CC=2 SCAR=6.9
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
unless @Proc::ShellSpawn::Programs::W 2 78 80
229 332 ▶sub dash1 { defined $_[0] && $_[0] =~ /^-.\z/s }
Subroutine dash1: called CC=2 SCAR=7.6
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
defined $_[0] and $_[0] =~ /^-.\z/s 332 0 332
230 812 ▶sub posix {
Subroutine posix: called CC=19 SCAR=29.7
Pod undocumented
231 812 my $n = shift;
232 812 ▶ if ($n == 1) { return length shift @W }
Branch: 1 branch
BranchTrueFalseTotal
if ($n == 1) 122 690 812
233 690 ▶ if ($n == 2) {
Branch: 1 branch
BranchTrueFalseTotal
if ($n == 2) 152 538 690
234 152 ▶ return !posix(1) if $W[0] eq '!' && shift @W;
Branch: 1 branch
BranchTrueFalseTotal
if $Proc::ShellSpawn::Programs::W[0] eq "!" and shift @Proc::ShellSpawn::Programs::W 8 144 152
Condition66%2/3
$Proc::ShellSpawn::Programs::W[0] eq "!" and shift @Proc::ShellSpawn::Programs::W
!ll&&!rl&&r
14408
MC/DC50%1/2
$Proc::ShellSpawn::Programs::W[0] eq "!" and shift @Proc::ShellSpawn::Programs::W
$Proc::ShellSpawn::Programs::W[0] eq "!" shift @Proc::ShellSpawn::Programs::W
Truth table66%2/3
A and B
A= $Proc::ShellSpawn::Programs::W[0] eq "!"B= shift @Proc::ShellSpawn::Programs::W
ABresult
0X0
100
111
235 144 ▶ return unary_op() if $UNARY{$W[0]};
Branch: 1 branch
BranchTrueFalseTotal
if $UNARY{$Proc::ShellSpawn::Programs::W[0]} 54 90 144
236 90 ▶ dash1($W[0]) ? die q_($CMDENV, $W[0]) . ": unary operator expected\n" : beyond() }
Branch: 1 branch
BranchTrueFalseTotal
dash1($Proc::ShellSpawn::Programs::W[0]) ? : 22 68 90
237 538 ▶ if ($n == 3) {
Branch: 1 branch
BranchTrueFalseTotal
if ($n == 3) 196 342 538
238 196 ▶ return binary_op(0) if $BINARY{$W[1]};
Branch: 1 branch
BranchTrueFalseTotal
if $BINARY{$Proc::ShellSpawn::Programs::W[1]} 90 106 196
239 106 ▶ return next_word() && !posix(2) if $W[0] eq '!';
Branch: 1 branch
BranchTrueFalseTotal
if $Proc::ShellSpawn::Programs::W[0] eq "!" 10 96 106
Condition66%2/3
next_word() && !posix(2)
!ll&&!rl&&r
028
MC/DC0%0/2
next_word() && !posix(2)
next_word() !posix(2)
Truth table33%1/3
A && not(B)
A= next_word()B= !posix(2)
ABresult
0X0
100
111
240 96 ▶ return (shift @W, posix(1), shift @W)[1] if $W[0] eq '(' && $W[2] eq ')';
Branch: 1 branch
BranchTrueFalseTotal
if $Proc::ShellSpawn::Programs::W[0] eq "(" and $Proc::ShellSpawn::Programs::W[2] eq ")" 2 94 96
Condition100%3/3
$Proc::ShellSpawn::Programs::W[0] eq "(" and $Proc::ShellSpawn::Programs::W[2] eq ")"
!ll&&!rl&&r
78162
MC/DC100%2/2
$Proc::ShellSpawn::Programs::W[0] eq "(" and $Proc::ShellSpawn::Programs::W[2] eq ")"
$Proc::ShellSpawn::Programs::W[0] eq "(" $Proc::ShellSpawn::Programs::W[2] eq ")"
Truth table100%3/3
A and B
A= $Proc::ShellSpawn::Programs::W[0] eq "("B= $Proc::ShellSpawn::Programs::W[2] eq ")"
ABresult
0X0
100
111
241 94 ▶ return expr() if $W[1] =~ /^-[ao]\z/;
Branch: 1 branch
BranchTrueFalseTotal
if $Proc::ShellSpawn::Programs::W[1] =~ /^-[ao]\z/ 14 80 94
242 80 die q_($CMDENV, $W[1]) . ": binary operator expected\n" }
243 342 ▶ if ($n == 4) {
Branch: 1 branch
BranchTrueFalseTotal
if ($n == 4) 118 224 342
244 118 ▶ return next_word() && !posix(3) if $W[0] eq '!';
Branch: 1 branch
BranchTrueFalseTotal
if $Proc::ShellSpawn::Programs::W[0] eq "!" 4 114 118
Condition33%1/3
next_word() && !posix(3)
!ll&&!rl&&r
004
MC/DC0%0/2
next_word() && !posix(3)
next_word() !posix(3)
Truth table33%1/3
A && not(B)
A= next_word()B= !posix(3)
ABresult
0X0
100
111
245 114 ▶ return (shift @W, posix(2), shift @W)[1] if $W[0] eq '(' && $W[3] eq ')' }
Branch: 1 branch
BranchTrueFalseTotal
if $Proc::ShellSpawn::Programs::W[0] eq "(" and $Proc::ShellSpawn::Programs::W[3] eq ")" 0 114 114
Condition66%2/3
$Proc::ShellSpawn::Programs::W[0] eq "(" and $Proc::ShellSpawn::Programs::W[3] eq ")"
!ll&&!rl&&r
98160
MC/DC0%0/2
$Proc::ShellSpawn::Programs::W[0] eq "(" and $Proc::ShellSpawn::Programs::W[3] eq ")"
$Proc::ShellSpawn::Programs::W[0] eq "(" $Proc::ShellSpawn::Programs::W[3] eq ")"
Truth table66%2/3
A and B
A= $Proc::ShellSpawn::Programs::W[0] eq "("B= $Proc::ShellSpawn::Programs::W[3] eq ")"
ABresult
0X0
100
111
246 338 expr() }
247 352 ▶sub expr { beyond() unless @W; my $v = and_(); while (@W && $W[0] eq '-o') { shift @W; my $r = and_(); $v ||= $r } $v }
Subroutine expr: called CC=5 SCAR=16.2
Pod undocumented
Branch: 2 branches
BranchTrueFalseTotal
unless @Proc::ShellSpawn::Programs::W 0 352 352
if (@Proc::ShellSpawn::Programs::W and $Proc::ShellSpawn::Programs::W[0] eq "-o") 20 204 224
Condition83%5/6
@Proc::ShellSpawn::Programs::W and $Proc::ShellSpawn::Programs::W[0] eq "-o"
!ll&&!rl&&r
3217220
$v ||= $r
l!l&&r!l&&!r
1602
MC/DC100%2/2
@Proc::ShellSpawn::Programs::W and $Proc::ShellSpawn::Programs::W[0] eq "-o"
@Proc::ShellSpawn::Programs::W $Proc::ShellSpawn::Programs::W[0] eq "-o"
MC/DC50%1/2
$v ||= $r
$v $r
Truth table100%3/3
A and B
A= @Proc::ShellSpawn::Programs::WB= $Proc::ShellSpawn::Programs::W[0] eq "-o"
ABresult
0X0
100
111
Truth table66%2/3
A ||= B
A= $vB= $r
ABresult
1X1
011
000
248 372 ▶sub and_ { my $v = term(); while (@W && $W[0] eq '-a') { shift @W; my $r = term(); $v &&= $r } $v } # (every term evaluated)
Subroutine and_: called CC=4 SCAR=13.9
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
if (@Proc::ShellSpawn::Programs::W and $Proc::ShellSpawn::Programs::W[0] eq "-a") 18 224 242
Condition83%5/6
@Proc::ShellSpawn::Programs::W and $Proc::ShellSpawn::Programs::W[0] eq "-a"
!ll&&!rl&&r
3219218
$v &&= $r
!ll&&!rl&&r
064
MC/DC100%2/2
@Proc::ShellSpawn::Programs::W and $Proc::ShellSpawn::Programs::W[0] eq "-a"
@Proc::ShellSpawn::Programs::W $Proc::ShellSpawn::Programs::W[0] eq "-a"
MC/DC50%1/2
$v &&= $r
$v $r
Truth table100%3/3
A and B
A= @Proc::ShellSpawn::Programs::WB= $Proc::ShellSpawn::Programs::W[0] eq "-a"
ABresult
0X0
100
111
Truth table66%2/3
A &&= B
A= $vB= $r
ABresult
0X0
100
111
249 390 ▶sub term {
Subroutine term: called CC=19 SCAR=29.4
Pod undocumented
250 390 my $neg = 0;
251 390 ▶ next_word(), $neg = !$neg while @W && $W[0] eq '!';
Branch: 1 branch
BranchTrueFalseTotal
@Proc::ShellSpawn::Programs::W and $Proc::ShellSpawn::Programs::W[0] eq "!" and do { next_word(), $neg = !$neg } 18 390 408
Condition100%3/3
@Proc::ShellSpawn::Programs::W and $Proc::ShellSpawn::Programs::W[0] eq "!"
!ll&&!rl&&r
238818
MC/DC100%2/2
@Proc::ShellSpawn::Programs::W and $Proc::ShellSpawn::Programs::W[0] eq "!"
@Proc::ShellSpawn::Programs::W $Proc::ShellSpawn::Programs::W[0] eq "!"
Truth table100%3/3
A and B
A= @Proc::ShellSpawn::Programs::WB= $Proc::ShellSpawn::Programs::W[0] eq "!"
ABresult
0X0
100
111
252 390 ▶ beyond() unless @W;
Branch: 1 branch
BranchTrueFalseTotal
unless @Proc::ShellSpawn::Programs::W 2 388 390
253 388 my $v;
254 388 ▶ if ($W[0] eq '(') {
Branch: 4 branches
BranchTrueFalseTotal
if ($Proc::ShellSpawn::Programs::W[0] eq '(') { } 48 340 388
elsif (@Proc::ShellSpawn::Programs::W >= 4 and $Proc::ShellSpawn::Programs::W[0] eq '-l' and $BINARY{$Proc::ShellSpawn::Programs::W[2]}) { } 16 324 340
elsif (@Proc::ShellSpawn::Programs::W >= 3 and $BINARY{$Proc::ShellSpawn::Programs::W[1]}) { } 82 242 324
elsif (dash1($Proc::ShellSpawn::Programs::W[0])) { } 90 152 242
255 48 next_word();
256 46 ▶ my ($close) = grep $W[$_] eq ')', 1 .. ($#W < 4 ? $#W : 4); # the POSIX rules up to a ')' at most 4 words on
Branch: 1 branch
BranchTrueFalseTotal
$#Proc::ShellSpawn::Programs::W < 4 ? : 30 16 46
257 46 ▶ $v = posix($close // scalar @W);
Condition100%2/2
$close // scalar @Proc::ShellSpawn::Programs::W
l!l
838
MC/DC100%1/1
$close // scalar @Proc::ShellSpawn::Programs::W
$close
Truth table100%2/2
A
A= $close
Aresult
11
00
258 20 ▶ my $at = @W ? $W[0] : $BEYOND;
Branch: 1 branch
BranchTrueFalseTotal
@Proc::ShellSpawn::Programs::W ? : 12 8 20
259 20 ▶ die q_($CMDENV, ')') . " expected" . (defined $at ? ", found " . q_($CMDENV, $at) : '') . "\n" unless defined $at && $at eq ')';
Branch: 2 branches
BranchTrueFalseTotal
unless defined $at and $at eq ")" 14 6 20
defined $at ? : 10 4 14
Condition100%3/3
defined $at and $at eq ")"
!ll&&!rl&&r
4106
MC/DC100%2/2
defined $at and $at eq ")"
defined $at $at eq ")"
Truth table100%3/3
A and B
A= defined $atB= $at eq ")"
ABresult
0X0
100
111
260 6 shift @W }
261 16 ▶ elsif (@W >= 4 && $W[0] eq '-l' && $BINARY{$W[2]}) { shift @W; $v = binary_op(1) }
Condition83%5/6
@Proc::ShellSpawn::Programs::W >= 4 and $Proc::ShellSpawn::Programs::W[0] eq "-l" and $BINARY{$Proc::ShellSpawn::Programs::W[2]}
!ll&&!rl&&r
324016
@Proc::ShellSpawn::Programs::W >= 4 and $Proc::ShellSpawn::Programs::W[0] eq "-l"
!ll&&!rl&&r
3828616
MC/DC66%2/3
@Proc::ShellSpawn::Programs::W >= 4 and $Proc::ShellSpawn::Programs::W[0] eq "-l" and $BINARY{$Proc::ShellSpawn::Programs::W[2]}
@Proc::ShellSpawn::Programs::W >= 4 $Proc::ShellSpawn::Programs::W[0] eq "-l" $BINARY{$Proc::ShellSpawn::Programs::W[2]}
Truth table75%3/4
A and B and C
A= @Proc::ShellSpawn::Programs::W >= 4B= $Proc::ShellSpawn::Programs::W[0] eq "-l"C= $BINARY{$Proc::ShellSpawn::Programs::W[2]}
ABCresult
0XX0
10X0
1100
1111
262 82 ▶ elsif (@W >= 3 && $BINARY{$W[1]}) { $v = binary_op(0) }
Condition100%3/3
@Proc::ShellSpawn::Programs::W >= 3 and $BINARY{$Proc::ShellSpawn::Programs::W[1]}
!ll&&!rl&&r
1622682
MC/DC100%2/2
@Proc::ShellSpawn::Programs::W >= 3 and $BINARY{$Proc::ShellSpawn::Programs::W[1]}
@Proc::ShellSpawn::Programs::W >= 3 $BINARY{$Proc::ShellSpawn::Programs::W[1]}
Truth table100%3/3
A and B
A= @Proc::ShellSpawn::Programs::W >= 3B= $BINARY{$Proc::ShellSpawn::Programs::W[1]}
ABresult
0X0
100
111
263 90 ▶ elsif (dash1($W[0])) { die q_($CMDENV, $W[0]) . ": unary operator expected\n" unless $UNARY{$W[0]}; $v = unary_op() }
Branch: 1 branch
BranchTrueFalseTotal
unless $UNARY{$Proc::ShellSpawn::Programs::W[0]} 54 36 90
264 152 else { $v = length shift @W }
265 242 ▶ $neg ? !$v : $v }
Branch: 1 branch
BranchTrueFalseTotal
$neg ? : 6 236 242
266 90 ▶sub unary_op { my $op = shift @W; beyond() unless @W; unary($op, shift @W) }
Subroutine unary_op: called CC=2 SCAR=6.9
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
unless @Proc::ShellSpawn::Programs::W 2 88 90
267 188 ▶sub binary_op { # L: -l STRING before (already taken); -l STRING after counts for the integer operators only
Subroutine binary_op: called CC=6 SCAR=17.9
Pod undocumented
268 188 my $l = shift;
269 188 my ($x, $op) = splice @W, 0, 2; my $y = shift @W;
270 188 ▶ my $r = $y eq '-l' && @W ? shift @W : undef; # (coreutils: -l after the operator, with a word after it)
Branch: 1 branch
BranchTrueFalseTotal
$y eq '-l' && @Proc::ShellSpawn::Programs::W ? : 6 182 188
Condition100%3/3
$y eq "-l" and @Proc::ShellSpawn::Programs::W
!ll&&!rl&&r
18026
MC/DC100%2/2
$y eq "-l" and @Proc::ShellSpawn::Programs::W
$y eq "-l" @Proc::ShellSpawn::Programs::W
Truth table100%3/3
A and B
A= $y eq "-l"B= @Proc::ShellSpawn::Programs::W
ABresult
0X0
100
111
271 188 ▶ if ($op =~ /^-(?:eq|ne|lt|le|gt|ge)\z/) { $x = length $x if $l; $y = length $r if defined $r }
Branch: 3 branches
BranchTrueFalseTotal
if ($op =~ /^-(?:eq|ne|lt|le|gt|ge)\z/) 101 87 188
if $l 14 87 101
if defined $r 4 97 101
272 188 binary($x, $op, $y) }
273  
274 152 ▶sub int_of { my $s = shift; # an integer of test: blanks around, a sign, digits (any length)
Subroutine int_of: called CC=2 SCAR=6.9
Pod undocumented
275 152 ▶ $s =~ /^[ \t]*([-+]?[0-9]+)[ \t]*\z/ ? Math::BigInt->new($1) : die "invalid integer " . q_($CMDENV, $s) . "\n" }
Branch: 1 branch
BranchTrueFalseTotal
$s =~ /^[ \t]*([-+]?[0-9]+)[ \t]*\z/ ? : 90 62 152
276 76 ▶sub path { my $f = shift; defined $OPT->{cwd} && length $f && !File::Spec->file_name_is_absolute($f) ? "$OPT->{cwd}/$f" : $f }
Subroutine path: called CC=4 SCAR=14.2
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
defined $Proc::ShellSpawn::Programs::OPT->{'cwd'} && length $f && !'File::Spec'->file_name_is_absolute($f) ? : 4 72 76
Condition66%4/6
defined $Proc::ShellSpawn::Programs::OPT->{"cwd"} and length $f and not "File::Spec"->file_name_is_absolute($f)
!ll&&!rl&&r
7204
defined $Proc::ShellSpawn::Programs::OPT->{"cwd"} and length $f
!ll&&!rl&&r
7204
MC/DC33%1/3
defined $Proc::ShellSpawn::Programs::OPT->{"cwd"} and length $f and not "File::Spec"->file_name_is_absolute($f)
defined $Proc::ShellSpawn::Programs::OPT->{"cwd"} length $f not "File::Spec"->file_name_is_absolute($f)
Truth table50%2/4
A and B and not(C)
A= defined $Proc::ShellSpawn::Programs::OPT->{"cwd"}B= length $fC= not "File::Spec"->file_name_is_absolute($f)
ABCresult
0XX0
10X0
1100
1111
277 8 ▶sub mtime { my @s = eval { require Time::HiRes; Time::HiRes::stat($_[0]) }; @s = stat $_[0] unless @s; @s ? $s[9] : undef }
Subroutine mtime: called CC=3 SCAR=11.3
Pod undocumented
Branch: 2 branches
BranchTrueFalseTotal
unless @s 0 8 8
@s ? : 8 0 8
278 0 ▶my %CMP = (eq => sub { $_[0] == 0 }, ne => sub { $_[0] != 0 }, lt => sub { $_[0] < 0 }, le => sub { $_[0] <= 0 },
Subroutine __ANON__: called CC=1 SCAR=1.2
Subroutine __ANON__: not called CC=1 SCAR=1.2
Subroutine __ANON__: called CC=1 SCAR=1.2
Subroutine __ANON__: not called CC=1 SCAR=1.2
279 7 ▶ gt => sub { $_[0] > 0 }, ge => sub { $_[0] >= 0 });
Subroutine __ANON__: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=1 SCAR=0.0
280 188 ▶sub binary {
Subroutine binary: called CC=9 SCAR=22.7
Pod undocumented
281 188 my ($x, $op, $y) = @_;
282 188 ▶ return $x eq $y if $op eq '=' || $op eq '==';
Branch: 1 branch
BranchTrueFalseTotal
if $op eq "=" or $op eq "==" 62 126 188
Condition66%2/3
$op eq "=" or $op eq "=="
l!l&&r!l&&!r
620126
MC/DC50%1/2
$op eq "=" or $op eq "=="
$op eq "=" $op eq "=="
Truth table66%2/3
A or B
A= $op eq "="B= $op eq "=="
ABresult
1X1
011
000
283 126 ▶ return $x ne $y if $op eq '!=';
Branch: 1 branch
BranchTrueFalseTotal
if $op eq "!=" 16 110 126
284 110 ▶ return $CMP{$1}->(int_of($x) <=> int_of($y)) if $op =~ /^-(eq|ne|lt|le|gt|ge)\z/;
Branch: 1 branch
BranchTrueFalseTotal
if $op =~ /^-(eq|ne|lt|le|gt|ge)\z/ 101 9 110
285 9 ($x, $y) = (path($x), path($y));
286 9 ▶ return files_eq($x, $y) if $op eq '-ef';
Branch: 1 branch
BranchTrueFalseTotal
if $op eq "-ef" 5 4 9
287 4 ▶ my ($new, $old) = map mtime($_), $op eq '-nt' ? ($x, $y) : ($y, $x);
Branch: 1 branch
BranchTrueFalseTotal
$op eq '-nt' ? : 2 2 4
288 4 ▶ defined $new && (!defined $old || $new > $old) }
Branch: 1 branch
BranchTrueFalseTotal
defined $new and !defined($old) || $new > $old 4 0 4
Condition33%2/6
defined $new && (!defined($old) || $new > $old)
!ll&&!rl&&r
004
not defined $old or $new > $old
l!l&&r!l&&!r
040
MC/DC0%0/3
defined $new && (!defined($old) || $new > $old)
defined $new not defined $old $new > $old
Truth table25%1/4
A && not(B) or C
A= defined $newB= not defined $oldC= $new > $old
ABCresult
0XX0
1000
11X1
1011
289 88 ▶sub unary {
Subroutine unary: called CC=9 SCAR=22.1
Pod undocumented
290 88 my ($op, $f) = @_;
291 88 ▶ return !length $f if $op eq '-z';
Branch: 1 branch
BranchTrueFalseTotal
if $op eq "-z" 12 76 88
292 76 ▶ return length $f if $op eq '-n';
Branch: 1 branch
BranchTrueFalseTotal
if $op eq "-n" 16 60 76
293 60 ▶ if ($op eq '-t') { my $d = int_of($f); return $d >= 0 && ($OPT->{isatty} ? $OPT->{isatty}->("$d") : POSIX::isatty("$d")) }
Branch: 2 branches
BranchTrueFalseTotal
if ($op eq "-t") 2 58 60
$Proc::ShellSpawn::Programs::OPT->{'isatty'} ? : 0 2 2
Condition33%1/3
$d >= 0 && ($Proc::ShellSpawn::Programs::OPT->{'isatty'} ? $Proc::ShellSpawn::Programs::OPT->{'isatty'}->("$d") : POSIX::isatty("$d"))
!ll&&!rl&&r
020
MC/DC0%0/2
$d >= 0 && ($Proc::ShellSpawn::Programs::OPT->{'isatty'} ? $Proc::ShellSpawn::Programs::OPT->{'isatty'}->("$d") : POSIX::isatty("$d"))
$d >= 0 ($Proc::ShellSpawn::Programs::OPT->{'isatty'} ? $Proc::ShellSpawn::Programs::OPT->{'isatty'}->("$d") : POSIX::isatty("$d"))
Truth table33%1/3
A && B
A= $d >= 0B= ($Proc::ShellSpawn::Programs::OPT->{'isatty'} ? $Proc::ShellSpawn::Programs::OPT->{'isatty'}->("$d") : POSIX::isatty("$d"))
ABresult
0X0
100
111
294 58 $f = path($f);
295 58 ▶ return -l $f if $op eq '-h' || $op eq '-L';
Branch: 1 branch
BranchTrueFalseTotal
if $op eq "-h" or $op eq "-L" 4 54 58
Condition100%3/3
$op eq "-h" or $op eq "-L"
l!l&&r!l&&!r
2254
MC/DC100%2/2
$op eq "-h" or $op eq "-L"
$op eq "-h" $op eq "-L"
Truth table100%3/3
A or B
A= $op eq "-h"B= $op eq "-L"
ABresult
1X1
011
000
296 54 ▶ my @s = stat $f or return 0;
Branch: 1 branch
BranchTrueFalseTotal
my(@s) = stat $f or return 0 17 37 54
297 return { -e => 1, -f => -f _, -d => -d _, -b => -b _, -c => -c _, -p => -p _, -S => -S _, -u => -u _, -g => -g _,
298 -k => -k _, -s => $s[7] > 0, -O => $s[4] == $>, -G => $s[5] == (split ' ', $))[0], -N => $s[9] > $s[8],
299 17 -r => -r $f, -w => -w $f, -x => -x $f }->{$op} }
300  
301 # ------------------------------------------------------------------ pwd
302 # As coreutils 9.4: -L, -P, --logical, --physical (abbreviated too), the last counts; options also after operands,
303 # unless POSIXLY_CORRECT (which also makes -L the default); operands only draw a warning. -L prints PWD from ENV if
304 # it is absolute, has no . or .. component and is the directory (same device and inode); else, and for -P, the
305 # directory with symbolic links resolved. OPT: { cwd => DIR }, the directory (default: Perl's).
306 443 my @PWDLONG = qw(logical physical help version); # (coreutils' order, for its messages)
307 443 my %PWDLONG = (logical => 'L', physical => 'P', help => 'help', version => 'version');
308 28 ▶sub pwd {
Subroutine pwd: called CC=23 SCAR=34.5
Pod undocumented
309 28 ▶ my ($argv, $env, $opt) = @_; $env //= {}; $opt //= {};
Condition75%3/4
$env //= {}
l!l
280
$opt //= {}
l!l
262
MC/DC0%0/1
$env //= {}
$env
MC/DC100%1/1
$opt //= {}
$opt
Truth table50%1/2
A
A= $env
Aresult
11
00
Truth table100%2/2
A
A= $opt
Aresult
11
00
310 28 my ($name, @a) = @$argv; my $posix = defined $env->{POSIXLY_CORRECT};
311 28 my ($logical, @ops, $err) = ($posix); my $try = "Try '$name --help' for more information.\n";
312 28 ▶ while (@a) {
Branch: 1 branch
BranchTrueFalseTotal
if (@a) 36 26 62
313 36 my $w = shift @a;
314 0 ▶ if ($w eq '--') { push @ops, @a; last }
Branch: 1 branch
BranchTrueFalseTotal
if ($w eq "--") 0 36 36
315 36 ▶ if ($w =~ /^--([^=]*)(=?)/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($w =~ /^--([^=]*)(=?)/) 1 35 36
316 1 my $arg = $2; my @m = grep /^\Q$1\E/, @PWDLONG;
317 1 ▶ return ('', "$name: option '$w' is ambiguous; possibilities:" . join('', map " '--$_'", @m) . "\n$try", 1) if @m > 1;
Branch: 1 branch
BranchTrueFalseTotal
if @m > 1 0 1 1
318 1 ▶ @m == 1 or return ('', "$name: unrecognized option '$w'\n$try", 1);
Branch: 1 branch
BranchTrueFalseTotal
@m == 1 or return "", "${name}: unrecognized option '${w}'\n$try", 1 1 0 1
319 1 ▶ return ('', "$name: option '--$m[0]' doesn't allow an argument\n$try", 1) if $arg;
Branch: 1 branch
BranchTrueFalseTotal
if $arg 1 0 1
320 0 my $o = $PWDLONG{$m[0]};
321 0 ▶ return info('pwd', "--$o") if length $o > 1;
Branch: 1 branch
BranchTrueFalseTotal
if length $o > 1 0 0 0
322 0 $logical = $o eq 'L'; next }
323 35 ▶ if ($w =~ /^-(.+)/s) {
Branch: 1 branch
BranchTrueFalseTotal
if ($w =~ /^-(.+)/s) 34 1 35
324 34 for my $l (split //, $1) {
325 36 ▶ $l =~ /^[LP]\z/ or return ('', "$name: invalid option -- '$l'\n$try", 1);
Branch: 1 branch
BranchTrueFalseTotal
$l =~ /^[LP]\z/ or return "", "${name}: invalid option -- '${l}'\n$try", 1 35 1 36
326 35 $logical = $l eq 'L' } next }
327 0 ▶ push @ops, $w; if ($posix) { push @ops, @a; last } }
Branch: 1 branch
BranchTrueFalseTotal
if ($posix) 0 1 1
328 26 ▶ $err = "$name: ignoring non-option arguments\n" if @ops;
Branch: 1 branch
BranchTrueFalseTotal
if @ops 1 25 26
329 26 ▶ my $dir = $opt->{cwd} // '.';
Condition50%1/2
$opt->{"cwd"} // "."
l!l
260
MC/DC0%0/1
$opt->{"cwd"} // "."
$opt->{"cwd"}
Truth table50%1/2
A
A= $opt->{"cwd"}
Aresult
11
00
330 26 my $wd = $env->{PWD};
331 26 ▶ my $ok = $logical && defined $wd && File::Spec->file_name_is_absolute($wd)
Branch: 1 branch
BranchTrueFalseTotal
$^O eq 'MSWin32' ? : 0 22 22
Condition75%9/12
$logical && defined $wd && 'File::Spec'->file_name_is_absolute($wd) && !(($^O eq 'MSWin32' ? $wd =~ s(^[/\\]{2}[^/\\]+)[]r : $wd) =~ m([/\\]\.\.?(?:[/\\]|\z))) && files_eq($wd, $dir)
!ll&&!rl&&r
5021
$logical and defined $wd and "File::Spec"->file_name_is_absolute($wd) and not +($^O eq "MSWin32" ? $wd =~ s(^[/\\]{2}[^/\\]+)[]r : $wd) =~ m([/\\]\.\.?(?:[/\\]|\z))
!ll&&!rl&&r
4121
$logical and defined $wd and "File::Spec"->file_name_is_absolute($wd)
!ll&&!rl&&r
4022
$logical and defined $wd
!ll&&!rl&&r
4022
MC/DC40%2/5
$logical && defined $wd && 'File::Spec'->file_name_is_absolute($wd) && !(($^O eq 'MSWin32' ? $wd =~ s(^[/\\]{2}[^/\\]+)[]r : $wd) =~ m([/\\]\.\.?(?:[/\\]|\z))) && files_eq($wd, $dir)
$logical defined $wd "File::Spec"->file_name_is_absolute($wd) not +($^O eq "MSWin32" ? $wd =~ s(^[/\\]{2}[^/\\]+)[]r : $wd) =~ m([/\\]\.\.?(?:[/\\]|\z)) files_eq($wd, $dir)
Truth table50%3/6
A and B and C and not(D) && E
A= $logicalB= defined $wdC= "File::Spec"->file_name_is_absolute($wd)D= not +($^O eq "MSWin32" ? $wd =~ s(^[/\\]{2}[^/\\]+)[]r : $wd) =~ m([/\\]\.\.?(?:[/\\]|\z))E= files_eq($wd, $dir)
ABCDEresult
0XXXX0
10XXX0
110XX0
1110X0
111100
111111
332 && ($^O eq 'MSWin32' ? $wd =~ s{^[/\\]{2}[^/\\]+}{}r : $wd) !~ m{[/\\]\.\.?(?:[/\\]|\z)} # (a UNC server, as '.',
333 # is no . or ..)
334 && files_eq($wd, $dir);
335 26 require Cwd;
336 26 ▶ (($ok ? $wd : Cwd::abs_path($dir)) . "\n", $err // '', 0) }
Branch: 1 branch
BranchTrueFalseTotal
$ok ? : 21 5 26
Condition100%2/2
$err // ""
l!l
125
MC/DC100%1/1
$err // ""
$err
Truth table100%2/2
A
A= $err
Aresult
11
00
337  
338 1808 ▶sub info { # NAME's result when --help or --version is its only argument: (TEXT, '', 0); else nothing
Subroutine info: called CC=4 SCAR=17.9
Pod undocumented
339 1808 ▶ my ($n, @a) = @_; @a == 1 && $a[0] =~ /^--(help|version)\z/ or return;
Branch: 1 branch
BranchTrueFalseTotal
@a == 1 and $a[0] =~ /^--(help|version)\z/ or return 0 1808 1808
Condition66%2/3
@a == 1 and $a[0] =~ /^--(help|version)\z/
!ll&&!rl&&r
13434650
MC/DC0%0/2
@a == 1 and $a[0] =~ /^--(help|version)\z/
@a == 1 $a[0] =~ /^--(help|version)\z/
Truth table66%2/3
A and B
A= @a == 1B= $a[0] =~ /^--(help|version)\z/
ABresult
0X0
100
111
340 0 ▶ ($1 eq 'help' ? help($n) : version($n), '', 0) }
Branch: 1 branch
BranchTrueFalseTotal
$1 eq 'help' ? : 0 0 0
341 0 ▶sub help { my $n = shift; "Usage: $n ...\n(in the Perl process: Proc::ShellSpawn::Programs, after GNU coreutils 9.4's $n)\n" }
Subroutine help: not called CC=1 SCAR=6.9
Pod undocumented
342 0 ▶sub version { my $n = shift; "$n (Proc::ShellSpawn::Programs $VERSION, after GNU coreutils 9.4)\n" }
Subroutine version: not called CC=1 SCAR=6.9
Pod undocumented
343 12 ▶sub true { ('', '', 0) }
Subroutine true: called CC=1 SCAR=0.0
Pod undocumented
344 19 ▶sub false { ('', '', 1) }
Subroutine false: called CC=1 SCAR=0.0
Pod undocumented
345  
346 443 1;
347  
348 __END__
« lib/Proc/ShellSubset.pm ↑ Summary blib/lib/Proc/Spawner/Loop/Win32.pm »