lib/Proc/ShellSpawn/Programs.pm

filter: Statementstmt 95.7% 386 / 403 Branchbran 90.7% 343 / 378 Conditioncond 79.7% 220 / 276 MC/DCmcdc 62.6% 99 / 158 Subroutinesub 91.6% 44 / 48 Podpod 0.0% 0 / 33 totaltotal 84.2% 1092 / 1296 CC 293 SCAR 30.8
CC
293
Cov
90%
pwd
46.5
printf
45.2
echo
28.6
CRAP 21.7
« 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 422 ▶use strict; use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
15 422 ▶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 422 our $VERSION = '0.12';
17  
18 422 my $IMAX = Math::BigInt->new('9223372036854775807'); my $IMIN = -$IMAX - 1;
19 422 my $UMAX = Math::BigInt->new('18446744073709551615');
20 422 my %CESC = ("\a" => 'a', "\b" => 'b', "\f" => 'f', "\n" => 'n', "\r" => 'r', "\t" => 't', "\013" => 'v');
21 422 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  
29 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=7 SCAR=19.5
Pod undocumented
30 # doubled, control characters as C escapes, what the locale cannot print in octal, and (C locale) \' for '
31 1305 my $u = is_utf8($env, 'LC_MESSAGES');
32 1305 my $t = join '', map { printable($_, $u) ? ($_ eq '\\' ? '\\\\' : $_ eq "'" && !$u ? "\\'" : $_)
33 4872 ▶ : join '', map $CESC{$_} ? "\\$CESC{$_}" : sprintf('\\%03o', ord), split // } chars($s, $u);
Branch: 4 branches
BranchTrueFalseTotal
printable($_, $u) ? : 4800 72 4872
$_ eq '\\' ? : 252 4548 4800
$_ eq q['] && !$u ? : 24 4524 4548
$CESC{$_} ? : 32 40 72
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
34 1305 ▶ $u ? "\xe2\x80\x98$t\xe2\x80\x99" : "'$t'" }
Branch: 1 branch
BranchTrueFalseTotal
$u ? : 650 655 1305
35  
36 # ------------------------------------------------------------------ echo
37 # OPT's echo (Proc::ShellSpawn: PROC_SHELLSPAWN_ECHO; decision EC1, the user, 2026-11-09) picks whose echo this is:
38 # coreutils (the default): coreutils 9.4's; POSIXLY_CORRECT in ENV changes it (escapes always, options only a first -n)
39 # dash: dash 0.5.12's builtin: escapes always (not \x), options only a first -n; POSIXLY_CORRECT changes nothing
40 # bash: bash 5.2's builtin (xpg_echo off, as bash --posix starts): options -n -e -E, escapes with -e (also \E, \u, \U)
41 422 our @ECHO = qw(coreutils dash bash);
42 1628 ▶sub echo {
Subroutine echo: called CC=28 SCAR=33.5
Pod undocumented
43 1628 ▶ my ($argv, $env, $opt) = @_; $env //= {}; my $style = ($opt && $opt->{echo}) || 'coreutils';
Condition71%5/7
$env //= {}
l!l
16280
$opt && $opt->{'echo'} || 'coreutils'
l!l
1288340
$opt and $opt->{"echo"}
!ll&&!rl&&r
34001288
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
44 1628 my @a = @$argv[1 .. $#$argv];
45 1628 ▶ my ($nl, $esc, $mode) = (1, 0, $style eq 'coreutils' ? 'echo' : $style);
Branch: 1 branch
BranchTrueFalseTotal
$style eq 'coreutils' ? : 407 1221 1628
46 1628 ▶ if ($style eq 'dash') { $esc = 1; if (@a && $a[0] eq '-n') { shift @a; $nl = 0 } }
Branch: 4 branches
BranchTrueFalseTotal
if ($style eq 'dash') { } 853 775 1628
elsif ($style eq 'bash') { } 368 407 775
elsif ($style eq 'coreutils') { } 407 0 407
if (@a and $a[0] eq "-n") 43 810 853
Condition100%3/3
@a and $a[0] eq "-n"
!ll&&!rl&&r
5275843
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
47 368 ▶ elsif ($style eq 'bash') { while (@a && $a[0] =~ /^-([eEn]+)\z/) { shift @a; for (split //, $1) { $_ eq 'n' ? ($nl = 0) : ($esc = $_ eq 'e') } } }
Branch: 2 branches
BranchTrueFalseTotal
if (@a and $a[0] =~ /^-([eEn]+)\z/) 174 368 542
$_ eq 'n' ? : 98 126 224
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
48 elsif ($style eq 'coreutils') {
49 407 my $posix = defined $env->{POSIXLY_CORRECT};
50 407 $esc = $posix; # POSIXLY_CORRECT: escapes always, options only for a first -n
51 407 ▶ if (!$posix || (@a && $a[0] eq '-n')) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $posix or @a and $a[0] eq "-n") 352 55 407
Condition100%6/6
not $posix or @a and $a[0] eq "-n"
l!l&&r!l&&!r
348455
@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
52 352 ▶ return ($1 eq 'help' ? help('echo') : version('echo'), '', 0) if @a == 1 && $a[0] =~ /^--(help|version)\z/;
Branch: 2 branches
BranchTrueFalseTotal
if @a == 1 and $a[0] =~ /^--(help|version)\z/ 0 352 352
$1 eq 'help' ? : 0 0 0
Condition66%2/3
@a == 1 and $a[0] =~ /^--(help|version)\z/
!ll&&!rl&&r
2311210
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
53 352 ▶ while (@a && $a[0] =~ /^-([eEn]+)\z/) { shift @a; for (split //, $1) { $_ eq 'n' ? ($nl = 0) : ($esc = $_ eq 'e' || $posix) } } } }
Branch: 2 branches
BranchTrueFalseTotal
if (@a and $a[0] =~ /^-([eEn]+)\z/) 139 352 491
$_ eq 'n' ? : 86 101 187
Condition100%6/6
@a and $a[0] =~ /^-([eEn]+)\z/
!ll&&!rl&&r
52300139
$_ eq 'e' || $posix
l!l&&r!l&&!r
61238
MC/DC100%2/2
@a and $a[0] =~ /^-([eEn]+)\z/
@a $a[0] =~ /^-([eEn]+)\z/
MC/DC100%2/2
$_ eq 'e' || $posix
$_ eq 'e' $posix
Truth table100%3/3
A and B
A= @aB= $a[0] =~ /^-([eEn]+)\z/
ABresult
0X0
100
111
Truth table100%3/3
A || B
A= $_ eq 'e'B= $posix
ABresult
1X1
011
000
54 0 else { die "PROC_SHELLSPAWN_ECHO: '$style' is none of @ECHO\n" }
55 1628 my $out = join ' ', @a;
56 1628 ▶ 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) 1031 597 1628
if $stop 72 959 1031
57 1556 ▶ ($out . ($nl ? "\n" : ''), '', 0) }
Branch: 1 branch
BranchTrueFalseTotal
$nl ? : 1354 202 1556
58  
59 # The backslash escapes of echo -e and printf's %b (MODE 'echo' or 'b'), or of printf's format ('fmt'); of dash's and
60 # bash's builtin echo (MODE 'dash', 'bash'). Returns (TEXT, STOP, ERROR): STOP after \c, ERROR for printf's "missing
61 # hexadecimal number" and "invalid universal character name". ENV: the command's environment, for \u and \U (the locale).
62 422 my %SIMPLE = (a => "\a", b => "\b", e => "\e", f => "\f", n => "\n", r => "\r", t => "\t", v => "\013", '\\' => '\\');
63 1956 ▶sub esc {
Subroutine esc: called CC=26 SCAR=32.6
Pod undocumented
64 1956 ▶ 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
219041031
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
65 1956 ▶ 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' ? : 904 1052 1956
$mode eq 'bash' ? : 68 984 1052
66 : qr/0([0-7]{0,3})|([1-7][0-7]{0,2})/; # echo, dash and %b: \0NNN or \NNN
67 1956 ▶ while ($s =~ /\G(?:([^\\]+)|\\)/gc) {
Branch: 1 branch
BranchTrueFalseTotal
if ($s =~ /\G(?:([^\\]+)|\\)/cg) 2672 1868 4540
68 2672 ▶ if (defined $1) { $o .= $1; next }
Branch: 1 branch
BranchTrueFalseTotal
if (defined $1) 1267 1405 2672
69 1405 ▶ if ($s =~ /\G$oct/gc) { $o .= chr(oct('0' . ($1 // $2)) & 255) }
Branch: 9 branches
BranchTrueFalseTotal
if ($s =~ /\G$oct/cg) { } 86 1319 1405
elsif ($s =~ /\G([abefnrtv\\])/cg) { } 1009 310 1319
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
70 1009 elsif ($s =~ /\G([abefnrtv\\])/gc) { $o .= $SIMPLE{$1} }
71 76 elsif ($s =~ /\Gc/gc) { return ($o, 1) }
72 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
73 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
74 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
75 ▶ 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
76 26 ▶ my ($k, $h) = defined $1 ? ($1, $2) : ($3, $4); my $v = hex $h;
Branch: 1 branch
BranchTrueFalseTotal
defined $1 ? : 18 8 26
77 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
78 20 $o .= unichar($v, $env) }
79 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
80 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
81 158 else { $o .= '\\' } # anything else (and a final backslash): the backslash as it is
82 }
83 1868 ($o, 0) }
84  
85 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=10 SCAR=23.0
Pod undocumented
86 # character in UTF-8's old form up to 6 bytes (surrogates too), else the escape \uXXXX or \UXXXXXXXX; above 0x7FFFFFFF
87 # nothing (checked against bash 5.2.21 in C and C.UTF-8)
88 22 my ($v, $env) = @_;
89 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
90 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
91 8 ▶ my ($n, $lead) = $v < 0x800 ? (2, 0xc0) : $v < 0x10000 ? (3, 0xe0) : $v < 0x200000 ? (4, 0xf0) : $v < 0x4000000 ? (5, 0xf8) : (6, 0xfc);
Branch: 4 branches
BranchTrueFalseTotal
$v < 2048 ? : 1 7 8
$v < 65536 ? : 2 5 7
$v < 2097152 ? : 3 2 5
$v < 67108864 ? : 0 2 2
92 8 my @b; for (2 .. $n) { unshift @b, 0x80 | ($v & 0x3f); $v >>= 6 }
93 8 pack 'C*', $lead | $v, @b }
94  
95 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
96 # encoded where the locale can (here: a UTF-8 locale), else (the C locale) the escape \uXXXX or \UXXXXXXXX, as above
97 # U+10FFFF everywhere. (A legacy locale such as ISO-8859-1, which coreutils would convert to by iconv, gets the escape.)
98 20 my ($v, $env) = @_;
99 20 ▶ return chr $v if $v < 0x80;
Branch: 1 branch
BranchTrueFalseTotal
if $v < 128 6 14 20
100 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
101 8 ▶ sprintf $v < 0x10000 ? '\u%04X' : '\U%08X', $v }
Branch: 1 branch
BranchTrueFalseTotal
$v < 65536 ? : 4 4 8
102  
103 # ------------------------------------------------------------------ printf
104 # 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
105 # with c s, a precision not with c); %b and %q take nothing between % and the letter.
106 422 my %NOT = ("'" => 'aAceEosxX', I => 'aAceEosxX', '#' => 'cdisu', 0 => 'cs');
107 1141 ▶sub printf {
Subroutine printf: called CC=45 SCAR=38.1
Pod undocumented
108 1141 ▶ my ($argv, $env) = @_; $env //= {};
Condition50%1/2
$env //= {}
l!l
11410
MC/DC0%0/1
$env //= {}
$env
Truth table50%1/2
A
A= $env
Aresult
11
00
109 1141 my ($name, @a) = @$argv;
110 1141 ▶ return ($1 eq 'help' ? help('printf') : version('printf'), '', 0) if @a == 1 && $a[0] =~ /^--(help|version)\z/;
Branch: 2 branches
BranchTrueFalseTotal
if @a == 1 and $a[0] =~ /^--(help|version)\z/ 0 1141 1141
$1 eq 'help' ? : 0 0 0
Condition66%2/3
@a == 1 and $a[0] =~ /^--(help|version)\z/
!ll&&!rl&&r
8602810
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
111 1141 ▶ shift @a if @a && $a[0] eq '--';
Branch: 1 branch
BranchTrueFalseTotal
if @a and $a[0] eq "--" 2 1139 1141
Condition100%3/3
@a and $a[0] eq "--"
!ll&&!rl&&r
211372
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
112 1141 ▶ return ('', "$name: missing operand\nTry '$name --help' for more information.\n", 1) unless @a;
Branch: 1 branch
BranchTrueFalseTotal
unless @a 2 1139 1141
113 1139 my $fmt = shift @a;
114 1139 my ($out, $err, $bad, $flushed, @seq) = ('', '', 0, 0);
115 1139 ▶ 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
116 1139 ▶ my $warn = sub { $msg->(q_($env, $_[0]) . ": $_[1]"); $bad = 1 };
Subroutine __ANON__: called CC=1 SCAR=0.0
117 1139 ▶ 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
3527870
MC/DC0%0/2
$_[0] // $bad
$_[0] $bad
Truth table66%2/3
A // B
A= $_[0]B= $bad
ABresult
1X1
011
000
118 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
119 1936 my ($s, $kind) = @_;
120 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
121 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
122 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
123 1278 ▶ if ($kind eq 'f') {
Branch: 1 branch
BranchTrueFalseTotal
if ($kind eq "f") 566 712 1278
124 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
125 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
126 566 ▶ return $left == length $s ? 0 : $v }
Branch: 1 branch
BranchTrueFalseTotal
$left == length $s ? : 312 254 566
127 my ($sign, $body, $rest) = $s =~ /^\s*([-+]?)(0[xX][0-9A-Fa-f]+|0[0-7]*|[1-9][0-9]*)(.*)\z/s
128 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
129 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
130 374 my $v = Math::BigInt->$from($body);
131 374 ▶ $v->bneg if $sign eq '-';
Branch: 1 branch
BranchTrueFalseTotal
if $sign eq "-" 62 312 374
132 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
133 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
134 105 elsif (length $rest) { $warn->($s, 'value not completely converted') }
135 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
136 1139 "$v" };
137 1139 my $used;
138 1139 while (1) {
139 1552 my $took = 0;
140 1552 ▶ 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) 4906 1196 6102
141 |%([-+ #0'I]*)(\*|[0-9]*)(?:\.(\*|[0-9]*))?[lLhjtz]*(.?))/gcsx) {
142 4906 my ($text, $e, $pct, $bq, $fl, $w, $p, $cv, $from) = ($1, $2, $3, $4, $5, $6, $7, $8, $-[0]);
143 4906 ▶ if (defined $text) { $out .= $text; next }
Branch: 1 branch
BranchTrueFalseTotal
if (defined $text) 1443 3463 4906
144 3463 ▶ if (defined $pct) { $out .= '%'; next }
Branch: 1 branch
BranchTrueFalseTotal
if (defined $pct) 3 3460 3463
145 3460 ▶ if (defined $e) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $e) 904 2556 3460
146 904 my ($t, $stop, $error) = esc("\\$e", 'fmt', $env); $out .= $t;
147 904 ▶ if ($error) { $msg->($error); return $done->(1) }
Branch: 1 branch
BranchTrueFalseTotal
if ($error) 8 896 904
148 896 ▶ return $done->() if $stop; next }
Branch: 1 branch
BranchTrueFalseTotal
if $stop 2 894 896
149 2556 ▶ $cv = $bq, $fl = $w = '' if defined $bq;
Branch: 1 branch
BranchTrueFalseTotal
if defined $bq 51 2505 2556
150 2556 ▶ if (!defined $bq && ($cv !~ /^[aAcdeEfFgGiosuxX]\z/ || grep(index($NOT{$_} // "", $cv) >= 0, split //, $fl) || defined $p && $cv eq 'c')) {
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
151 340 $msg->(substr($fmt, $from, pos($fmt) - $from) . ": invalid conversion specification"); return $done->(1) } # (as written)
152 2216 $used = 1;
153 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
154 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
155 2216 ▶ my $arg = shift @a; $took++ if defined $arg;
Branch: 1 branch
BranchTrueFalseTotal
if defined $arg 1622 594 2216
156 2216 $fl =~ tr/'I//d; # (grouping, the locale's digits: none in the C locale)
157 2216 ▶ my $spec = "%$fl$w" . (defined $p ? ".$p" : '');
Branch: 1 branch
BranchTrueFalseTotal
defined $p ? : 771 1445 2216
158 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
159 elsif ($cv eq 'b') {
160 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
161 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
162 17 ▶ $out .= sprintf "${spec}s", $t; return $done->() if $stop }
Branch: 1 branch
BranchTrueFalseTotal
if $stop 2 15 17
163 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
164 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
165 361 elsif ($cv =~ /[di]/) { $out .= sprintf "${spec}d", $num->($arg, 'i') }
166 736 elsif ($cv =~ /[ouxX]/) { $out .= sprintf "$spec$cv", $num->($arg, 'u') }
167 832 else { $out .= float($spec, $fl, $w, $p, $cv, $num->($arg, 'f'), $arg) } }
168 1196 ▶ last unless @a && $took;
Branch: 1 branch
BranchTrueFalseTotal
unless @a and $took 783 413 1196
Condition100%3/3
@a and $took
!ll&&!rl&&r
7812413
MC/DC100%2/2
@a and $took
@a $took
Truth table100%3/3
A and B
A= @aB= $took
ABresult
0X0
100
111
169 413 pos $fmt = 0 }
170 783 ▶ $msg->("warning: ignoring excess arguments, starting with " . q_($env, $a[0])) if @a && !$used;
Branch: 1 branch
BranchTrueFalseTotal
if @a and not $used 2 781 783
Condition66%2/3
@a and not $used
!ll&&!rl&&r
78102
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
171 783 $done->() }
172  
173 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
174 832 my ($spec, $fl, $w, $p, $cv, $v, $arg) = @_; # under %f exact, as coreutils' long double has it (a double rounds)
175 832 ▶ my $sign = $fl =~ /\+/ ? '+' : $fl =~ / / ? ' ' : '';
Branch: 2 branches
BranchTrueFalseTotal
$fl =~ /\+/ ? : 188 644 832
$fl =~ / / ? : 118 526 644
176 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
177 44 ▶ my $t = ($v < 0 ? '-' : $sign) . ($v != $v ? 'nan' : 'inf');
Branch: 2 branches
BranchTrueFalseTotal
$v < 0 ? : 12 32 44
$v != $v ? : 12 32 44
178 44 ▶ return pad($fl =~ tr/0//dr, $w, $cv =~ /[EFGA]/ ? uc $t : $t) }
Branch: 1 branch
BranchTrueFalseTotal
$cv =~ /[EFGA]/ ? : 20 24 44
179 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
180 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
181 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
182 778 sprintf "$spec$cv", $v }
183 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
184 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
185 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
186  
187 # %q: gnulib's quotearg in shell_escape_quoting_style, as coreutils' printf, with gnulib's later fix (decision IP2): a
188 # word needing no quotes as it is; else in '...', a ' as '\'', what must be escaped (controls; what the locale cannot
189 # print, byte by byte in octal) in $'...' runs; a word whose only trouble is a ' (and spaces, #, ~ in front) in "...".
190 422 my %QESC = (%CESC, "\0" => '0');
191 26 ▶sub shell_quote {
Subroutine shell_quote: called CC=14 SCAR=26.4
Pod undocumented
192 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
193 26 my @c = chars($w, $u); my $plain = !grep !printable($_, $u), @c;
194 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
195 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
196 15 my ($q, $dollar) = ("'", 0);
197 15 for (@c) {
198 44 ▶ if (!printable($_, $u)) { $q .= q{'$'} unless $dollar; $dollar = 1; $q .= join '', map $QESC{$_} ? "\\$QESC{$_}" : sprintf('\\%03o', ord), split // }
Branch: 4 branches
BranchTrueFalseTotal
if (not printable($_, $u)) { } 10 34 44
elsif ($_ eq q[']) { } 4 30 34
unless $dollar 9 1 10
$QESC{$_} ? : 4 6 10
199 4 elsif ($_ eq "'") { $q .= q{'\''}; $dollar = 0 }
200 30 ▶ else { $q .= "''" if $dollar; $dollar = 0; $q .= $_ } }
Branch: 1 branch
BranchTrueFalseTotal
if $dollar 0 30 30
201 15 "$q'" }
202  
203 # ------------------------------------------------------------------ test and [
204 # coreutils' grammar: with 1 to 4 arguments the POSIX rules, else (and inside them where they say so) the expression
205 # -o, -a, !, ( ), -l STRING as an integer. The words are consumed from @W; for [, the ] stays in $BEYOND, past the
206 # end, where coreutils' messages still see it ("')' expected, found ']'").
207 422 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);
208 422 my %BINARY = map +($_ => 1), qw(= == != -eq -ne -lt -le -gt -ge -nt -ot -ef);
209 422 our (@W, $LAST, $BEYOND, $ENV, $OPT);
210 880 ▶sub test {
Subroutine test: called CC=16 SCAR=28.3
Pod undocumented
211 880 my ($argv, $env, $opt) = @_;
212 880 my ($name, @a) = @$argv; my $br = $name =~ m{(?:^|/)\[\z};
213 880 ▶ if ($br) {
Branch: 1 branch
BranchTrueFalseTotal
if ($br) 296 584 880
214 296 ▶ return ($1 eq 'help' ? help('[') : version('['), '', 0) if @a == 1 && $a[0] =~ /^--(help|version)\z/;
Branch: 2 branches
BranchTrueFalseTotal
if @a == 1 and $a[0] =~ /^--(help|version)\z/ 0 296 296
$1 eq 'help' ? : 0 0 0
Condition66%2/3
@a == 1 and $a[0] =~ /^--(help|version)\z/
!ll&&!rl&&r
252440
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
215 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
216 878 ▶ local (@W, $LAST, $BEYOND, $ENV, $OPT) = (@a); ($LAST, $BEYOND, $ENV, $OPT) = ($a[-1], $br ? ']' : undef, $env // {}, $opt // {});
Branch: 1 branch
BranchTrueFalseTotal
$br ? : 294 584 878
Condition75%3/4
$env // {}
l!l
8780
$opt // {}
l!l
34844
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
217 878 ▶ my $r = eval { my $v = @W ? posix(scalar @W) : 0; die "extra argument " . q_($ENV, $W[0]) . "\n" if @W; $v ? 1 : 0 };
Branch: 3 branches
BranchTrueFalseTotal
@Proc::ShellSpawn::Programs::W ? : 741 137 878
if @Proc::ShellSpawn::Programs::W 164 408 572
$v ? : 191 217 408
218 878 ▶ defined $r ? ('', '', $r ? 0 : 1) : ('', "$name: " . $@, 2) }
Branch: 2 branches
BranchTrueFalseTotal
defined $r ? : 408 470 878
$r ? : 191 217 408
219  
220 74 ▶sub beyond { die "missing argument after " . q_($ENV, $LAST) . "\n" }
Subroutine beyond: called CC=1 SCAR=0.0
Pod undocumented
221 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
222 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
223 811 ▶sub posix {
Subroutine posix: called CC=19 SCAR=29.7
Pod undocumented
224 811 my $n = shift;
225 811 ▶ if ($n == 1) { return length shift @W }
Branch: 1 branch
BranchTrueFalseTotal
if ($n == 1) 122 689 811
226 689 ▶ if ($n == 2) {
Branch: 1 branch
BranchTrueFalseTotal
if ($n == 2) 152 537 689
227 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
228 144 ▶ return unary_op() if $UNARY{$W[0]};
Branch: 1 branch
BranchTrueFalseTotal
if $UNARY{$Proc::ShellSpawn::Programs::W[0]} 54 90 144
229 90 ▶ dash1($W[0]) ? die q_($ENV, $W[0]) . ": unary operator expected\n" : beyond() }
Branch: 1 branch
BranchTrueFalseTotal
dash1($Proc::ShellSpawn::Programs::W[0]) ? : 22 68 90
230 537 ▶ if ($n == 3) {
Branch: 1 branch
BranchTrueFalseTotal
if ($n == 3) 195 342 537
231 195 ▶ return binary_op(0) if $BINARY{$W[1]};
Branch: 1 branch
BranchTrueFalseTotal
if $BINARY{$Proc::ShellSpawn::Programs::W[1]} 89 106 195
232 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
233 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
234 94 ▶ return expr() if $W[1] =~ /^-[ao]\z/;
Branch: 1 branch
BranchTrueFalseTotal
if $Proc::ShellSpawn::Programs::W[1] =~ /^-[ao]\z/ 14 80 94
235 80 die q_($ENV, $W[1]) . ": binary operator expected\n" }
236 342 ▶ if ($n == 4) {
Branch: 1 branch
BranchTrueFalseTotal
if ($n == 4) 118 224 342
237 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
238 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
239 338 expr() }
240 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
241 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
242 390 ▶sub term {
Subroutine term: called CC=19 SCAR=29.4
Pod undocumented
243 390 my $neg = 0;
244 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
245 390 ▶ beyond() unless @W;
Branch: 1 branch
BranchTrueFalseTotal
unless @Proc::ShellSpawn::Programs::W 2 388 390
246 388 my $v;
247 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
248 48 next_word();
249 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
250 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
251 20 ▶ my $at = @W ? $W[0] : $BEYOND;
Branch: 1 branch
BranchTrueFalseTotal
@Proc::ShellSpawn::Programs::W ? : 12 8 20
252 20 ▶ die q_($ENV, ')') . " expected" . (defined $at ? ", found " . q_($ENV, $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
253 6 shift @W }
254 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
255 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
256 90 ▶ elsif (dash1($W[0])) { die q_($ENV, $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
257 152 else { $v = length shift @W }
258 242 ▶ $neg ? !$v : $v }
Branch: 1 branch
BranchTrueFalseTotal
$neg ? : 6 236 242
259 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
260 187 ▶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
261 187 my $l = shift;
262 187 my ($x, $op) = splice @W, 0, 2; my $y = shift @W;
263 187 ▶ 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 181 187
Condition100%3/3
$y eq "-l" and @Proc::ShellSpawn::Programs::W
!ll&&!rl&&r
17926
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
264 187 ▶ 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 86 187
if $l 14 87 101
if defined $r 4 97 101
265 187 binary($x, $op, $y) }
266  
267 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
268 152 ▶ $s =~ /^[ \t]*([-+]?[0-9]+)[ \t]*\z/ ? Math::BigInt->new($1) : die "invalid integer " . q_($ENV, $s) . "\n" }
Branch: 1 branch
BranchTrueFalseTotal
$s =~ /^[ \t]*([-+]?[0-9]+)[ \t]*\z/ ? : 90 62 152
269 74 ▶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 70 74
Condition66%4/6
defined $Proc::ShellSpawn::Programs::OPT->{"cwd"} and length $f and not "File::Spec"->file_name_is_absolute($f)
!ll&&!rl&&r
7004
defined $Proc::ShellSpawn::Programs::OPT->{"cwd"} and length $f
!ll&&!rl&&r
7004
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
270 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
271 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
272 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
273 187 ▶sub binary {
Subroutine binary: called CC=12 SCAR=26.9
Pod undocumented
274 187 my ($x, $op, $y) = @_;
275 187 ▶ return $x eq $y if $op eq '=' || $op eq '==';
Branch: 1 branch
BranchTrueFalseTotal
if $op eq "=" or $op eq "==" 62 125 187
Condition66%2/3
$op eq "=" or $op eq "=="
l!l&&r!l&&!r
620125
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
276 125 ▶ return $x ne $y if $op eq '!=';
Branch: 1 branch
BranchTrueFalseTotal
if $op eq "!=" 16 109 125
277 109 ▶ 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 8 109
278 8 ($x, $y) = (path($x), path($y));
279 8 ▶ if ($op eq '-ef') { my @a = stat $x; my @b = stat $y; return @a && @b && $a[0] == $b[0] && $a[1] == $b[1] }
Branch: 1 branch
BranchTrueFalseTotal
if ($op eq "-ef") 4 4 8
Condition44%4/9
@a && @b && $a[0] == $b[0] && $a[1] == $b[1]
!ll&&!rl&&r
022
@a and @b and $a[0] == $b[0]
!ll&&!rl&&r
004
@a and @b
!ll&&!rl&&r
004
MC/DC25%1/4
@a && @b && $a[0] == $b[0] && $a[1] == $b[1]
@a @b $a[0] == $b[0] $a[1] == $b[1]
Truth table40%2/5
A and B and C && D
A= @aB= @bC= $a[0] == $b[0]D= $a[1] == $b[1]
ABCDresult
0XXX0
10XX0
110X0
11100
11111
280 4 ▶ my ($new, $old) = map mtime($_), $op eq '-nt' ? ($x, $y) : ($y, $x);
Branch: 1 branch
BranchTrueFalseTotal
$op eq '-nt' ? : 2 2 4
281 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
282 88 ▶sub unary {
Subroutine unary: called CC=9 SCAR=22.1
Pod undocumented
283 88 my ($op, $f) = @_;
284 88 ▶ return !length $f if $op eq '-z';
Branch: 1 branch
BranchTrueFalseTotal
if $op eq "-z" 12 76 88
285 76 ▶ return length $f if $op eq '-n';
Branch: 1 branch
BranchTrueFalseTotal
if $op eq "-n" 16 60 76
286 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
287 58 $f = path($f);
288 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
289 54 ▶ my @s = stat $f or return 0;
Branch: 1 branch
BranchTrueFalseTotal
my(@s) = stat $f or return 0 17 37 54
290 return { -e => 1, -f => -f _, -d => -d _, -b => -b _, -c => -c _, -p => -p _, -S => -S _, -u => -u _, -g => -g _,
291 -k => -k _, -s => $s[7] > 0, -O => $s[4] == $>, -G => $s[5] == (split ' ', $))[0], -N => $s[9] > $s[8],
292 17 -r => -r $f, -w => -w $f, -x => -x $f }->{$op} }
293  
294 # ------------------------------------------------------------------ pwd
295 # As coreutils 9.4: -L, -P, --logical, --physical (abbreviated too), the last counts; options also after operands,
296 # unless POSIXLY_CORRECT (which also makes -L the default); operands only draw a warning. -L prints PWD from ENV if
297 # it is absolute, has no . or .. component and is the directory (same device and inode); else, and for -P, the
298 # directory with symbolic links resolved. OPT: { cwd => DIR }, the directory (default: Perl's).
299 422 my @PWDLONG = qw(logical physical help version); # (coreutils' order, for its messages)
300 422 my %PWDLONG = (logical => 'L', physical => 'P', help => 'help', version => 'version');
301 28 ▶sub pwd {
Subroutine pwd: called CC=27 SCAR=38.4
Pod undocumented
302 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
303 28 my ($name, @a) = @$argv; my $posix = defined $env->{POSIXLY_CORRECT};
304 28 my ($logical, @ops, $err) = ($posix); my $try = "Try '$name --help' for more information.\n";
305 28 ▶ while (@a) {
Branch: 1 branch
BranchTrueFalseTotal
if (@a) 36 26 62
306 36 my $w = shift @a;
307 0 ▶ if ($w eq '--') { push @ops, @a; last }
Branch: 1 branch
BranchTrueFalseTotal
if ($w eq "--") 0 36 36
308 36 ▶ if ($w =~ /^--([^=]*)(=?)/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($w =~ /^--([^=]*)(=?)/) 1 35 36
309 1 my $arg = $2; my @m = grep /^\Q$1\E/, @PWDLONG;
310 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
311 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
312 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
313 0 my $o = $PWDLONG{$m[0]};
314 0 ▶ return ($o eq 'help' ? help('pwd') : version('pwd'), '', 0) if length $o > 1;
Branch: 2 branches
BranchTrueFalseTotal
if length $o > 1 0 0 0
$o eq 'help' ? : 0 0 0
315 0 $logical = $o eq 'L'; next }
316 35 ▶ if ($w =~ /^-(.+)/s) {
Branch: 1 branch
BranchTrueFalseTotal
if ($w =~ /^-(.+)/s) 34 1 35
317 34 for my $l (split //, $1) {
318 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
319 35 $logical = $l eq 'L' } next }
320 0 ▶ push @ops, $w; if ($posix) { push @ops, @a; last } }
Branch: 1 branch
BranchTrueFalseTotal
if ($posix) 0 1 1
321 26 ▶ $err = "$name: ignoring non-option arguments\n" if @ops;
Branch: 1 branch
BranchTrueFalseTotal
if @ops 1 25 26
322 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
323 26 my $wd = $env->{PWD};
324 my $ok = $logical && defined $wd && File::Spec->file_name_is_absolute($wd)
325 && ($^O eq 'MSWin32' ? $wd =~ s{^[/\\]{2}[^/\\]+}{}r : $wd) !~ m{[/\\]\.\.?(?:[/\\]|\z)} # (a UNC server, as '.', is no . or ..)
326 26 ▶ && do { my @a = stat $wd; my @b = stat $dir; @a && @b && $a[0] == $b[0] && $a[1] == $b[1] };
Branch: 1 branch
BranchTrueFalseTotal
$^O eq 'MSWin32' ? : 0 22 22
Condition57%12/21
$logical && defined $wd && 'File::Spec'->file_name_is_absolute($wd) && !(($^O eq 'MSWin32' ? $wd =~ s(^[/\\]{2}[^/\\]+)[]r : $wd) =~ m([/\\]\.\.?(?:[/\\]|\z))) && do { my(@a) = stat $wd; my(@b) = stat $dir; @a and @b and $a[0] == $b[0] and $a[1] == $b[1] }
!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
@a && @b && $a[0] == $b[0] && $a[1] == $b[1]
!ll&&!rl&&r
0021
@a and @b and $a[0] == $b[0]
!ll&&!rl&&r
0021
@a and @b
!ll&&!rl&&r
0021
MC/DC40%2/5
$logical && defined $wd && 'File::Spec'->file_name_is_absolute($wd) && !(($^O eq 'MSWin32' ? $wd =~ s(^[/\\]{2}[^/\\]+)[]r : $wd) =~ m([/\\]\.\.?(?:[/\\]|\z))) && do { my(@a) = stat $wd; my(@b) = stat $dir; @a and @b and $a[0] == $b[0] and $a[1] == $b[1] }
$logical defined $wd "File::Spec"->file_name_is_absolute($wd) not +($^O eq "MSWin32" ? $wd =~ s(^[/\\]{2}[^/\\]+)[]r : $wd) =~ m([/\\]\.\.?(?:[/\\]|\z)) do { my(@a) = stat $wd; my(@b) = stat $dir; @a and @b and $a[0] == $b[0] and $a[1] == $b[1] }
MC/DC0%0/4
@a && @b && $a[0] == $b[0] && $a[1] == $b[1]
@a @b $a[0] == $b[0] $a[1] == $b[1]
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= do { my(@a) = stat $wd; my(@b) = stat $dir; @a and @b and $a[0] == $b[0] and $a[1] == $b[1] }
ABCDEresult
0XXXX0
10XXX0
110XX0
1110X0
111100
111111
Truth table20%1/5
A and B and C && D
A= @aB= @bC= $a[0] == $b[0]D= $a[1] == $b[1]
ABCDresult
0XXX0
10XX0
110X0
11100
11111
327 26 require Cwd;
328 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
329  
330 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
331 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
332 11 ▶sub true { ('', '', 0) }
Subroutine true: called CC=1 SCAR=0.0
Pod undocumented
333 19 ▶sub false { ('', '', 1) }
Subroutine false: called CC=1 SCAR=0.0
Pod undocumented
334  
335 422 1;
336  
337 __END__
« lib/Proc/ShellSubset.pm ↑ Summary blib/lib/Proc/Spawner/Loop/Win32.pm »