Branch Coverage

lib/BATsh/SH.pm
Criterion Covered Total %
branch 345 760 45.3


line true false branch
44 0 7 if ($] < "5.006" and not defined &warnings::import)
46 0 7 if $INC[-1] eq "."
84 0 45 defined $_EXIT_CODE ? :
98 0 132 if defined $_EXIT_CODE
99 0 132 if $_BREAK or $_RETURN
106 9 123 if $line =~ /\A\s*\z/
107 0 123 if $line =~ /\A\s*#/
114 123 0 defined $first ? :
116 7 116 if ($first eq "if")
120 2 114 if ($first eq "for")
124 2 112 if ($first eq "while" or $first eq "until")
128 1 111 if ($first eq "case")
134 6 105 if ($stripped =~ /\A(?:function\s+[A-Za-z_]|[A-Za-z_][A-Za-z0-9_]*\s*\(\s*\))/)
140 0 105 if $_CONTINUE
153 0 121 if $line =~ /\A\s*\z/
154 0 121 if $line =~ /\A\s*#/
157 0 121 if $line =~ /\A#!/
162 5 116 if (@compound > 1)
170 3 113 if (@pipe_segs > 1)
183 0 113 if (@{$sh_redirs_ref;})
189 0 113 unless defined $cmd and $cmd ne ""
194 28 85 if ($cmd =~ /\A([A-Za-z_][A-Za-z0-9_]*)=(.*)\z/s)
204 24 61 if ($lc_cmd eq "export")
205 1 60 if ($lc_cmd eq "unset")
206 23 37 if ($lc_cmd eq "echo")
207 0 37 if ($lc_cmd eq "printf")
208 0 37 if ($lc_cmd eq "cd")
209 0 37 if ($lc_cmd eq "pwd")
210 0 37 if ($lc_cmd eq "exit")
211 2 35 if ($lc_cmd eq "true")
212 4 31 if ($lc_cmd eq "false")
213 0 31 if ($lc_cmd eq ":")
214 1 30 if ($lc_cmd eq "read")
215 16 14 if ($lc_cmd eq "test" or $cmd eq "[")
216 0 14 if ($lc_cmd eq "source" or $cmd eq ".")
217 0 0 $rest =~ /\A\s*(\d+)/ ? :
0 14 if ($lc_cmd eq "return")
218 0 14 if ($lc_cmd eq "break")
219 0 14 if ($lc_cmd eq "continue")
220 2 12 if ($lc_cmd eq "shift")
221 2 10 if ($lc_cmd eq "local")
222 0 10 if ($lc_cmd eq "set")
225 6 4 if (exists $BATsh::SH::_SH_FUNCTIONS{$cmd})
238 0 125 unless defined $str
252 1 0 defined $v ? :
257 1 0 defined $v ? :
262 1 0 defined $v ? :
267 1 0 defined $v ? :
272 1 0 defined $v ? :
277 1 0 defined $v ? :
282 1 0 defined $v ? :
287 1 0 defined $v ? :
292 0 0 defined $v ? :
297 1 0 defined $v ? :
302 0 0 defined $v ? :
308 1 0 defined $v ? :
310 0 1 if $off < 0
311 0 1 if $off < 0
317 0 0 defined $v ? :
319 0 0 if $off < 0
320 0 0 if $off < 0
327 0 2 if (defined $v and $v ne '') { }
332 0 0 if (not defined $v or $v eq "")
337 0 0 defined $v && $v ne '' ? :
342 13 0 defined $v ? :
353 0 0 defined $v ? :
360 0 5 unless defined $v and $v ne ""
361 5 0 defined $v ? :
366 0 0 defined $v ? :
374 0 0 unless defined $vv and $vv ne ""
375 0 0 unless defined $vv and $vv ne ""
384 32 0 defined $v ? :
402 12 0 if ($expr =~ m[\A[\d\s\+\-\*/\%\(\)]+\z])
404 12 0 defined $result ? :
412 0 5 unless defined $v and $v ne ""
413 5 0 defined $v && $v =~ /\A-?\d+\z/ ? :
419 8 0 defined $v && $v =~ /\A-?\d+\z/ ? :
431 0 125 unless defined $str
442 0 62 if ($ch eq "\$" and $i + 1 < $n and $chars[$i + 1] eq "(")
452 0 0 if ($in_sq)
453 0 0 if ($c eq "'")
456 0 0 if ($c eq "'" and not $in_dq)
459 0 0 if ($c eq "\"" and not $in_sq)
462 0 0 if ($in_dq)
463 0 0 if ($c eq "\\")
465 0 0 if $i < $n
469 0 0 if ($c eq "\\")
471 0 0 if $i < $n
473 0 0 if ($c eq "(")
474 0 0 if ($c eq ")")
476 0 0 if ($depth == 0)
501 0 1 unless open _SUBST_SAVOUT, ">&STDOUT"
504 0 1 unless (open _SUBST_CAPFH, "> $tmpfile")
506 0 1 unless (open STDOUT, ">&_SUBST_CAPFH")
518 1 0 if (open _SUBST_READFH, "< $tmpfile")
524 0 1 unless defined $output
536 0 24 if ($rest =~ /\A-p\s*\z/)
546 23 1 if ($item =~ /\A([A-Za-z_][A-Za-z0-9_]*)=(.*)\z/s) { }
1 0 elsif ($item =~ /\A([A-Za-z_][A-Za-z0-9_]*)\z/) { }
564 1 0 if $var ne ""
577 0 23 if ($rest =~ s/\A-n\s*//)
580 0 23 if ($rest =~ s/\A-e\s*//)
581 0 23 if ($escape)
590 0 23 if ($no_newline) { }
604 0 0 if ($rest =~ s/\A"((?:[^"\\]|\\.)*)"\s*//) { }
0 0 elsif ($rest =~ s/\A'([^']*)'\s*//) { }
612 0 0 unless defined $rest
629 0 0 if ($rest eq "" or $rest eq "~")
632 0 0 unless (chdir $rest)
648 0 0 $rest =~ /\A(\d+)/ ? :
662 0 1 unless defined $line
665 1 0 if (@vars == 1) { }
0 0 elsif (@vars > 1) { }
671 0 0 defined $words[$i] ? :
683 2 0 unless defined $rest
688 0 0 if $n_shift < 1
0 2 if ($rest =~ /\A(\d+)\s*\z/)
694 0 16 defined $next ? :
701 16 0 defined $next ? :
709 2 4 unless defined $v and $v ne ""
726 1 1 if ($rest =~ /\A([A-Za-z_][A-Za-z0-9_]*)=(.*)\z/s) { }
1 0 elsif ($rest =~ /\A([A-Za-z_][A-Za-z0-9_]*)\s*\z/) { }
735 0 1 unless defined $val
743 2 0 if (@FUNCTION_STACK)
746 2 0 unless (exists $frame->{$var})
748 2 0 defined $old ? :
774 0 0 if (defined $opts_ref->{'_batsh'})
776 0 0 if ($@)
789 11 5 $result ? :
799 0 16 if ($expr =~ /^(.*)\s+-a\s+(.*)$/)
802 0 16 if ($expr =~ /^(.*)\s+-o\s+(.*)$/)
806 0 16 if ($expr =~ /^!\s+(.*)$/)
811 2 14 if ($expr =~ /\A(-[a-z])\s+(.+)\z/)
814 0 0 -e $path ? :
0 2 if ($op eq "-e")
815 0 0 -f $path ? :
0 2 if ($op eq "-f")
816 0 0 -d $path ? :
0 2 if ($op eq "-d")
817 0 0 -r $path ? :
0 2 if ($op eq "-r")
818 0 0 -w $path ? :
0 2 if ($op eq "-w")
819 0 0 -x $path ? :
0 2 if ($op eq "-x")
820 0 0 -s $path ? :
0 2 if ($op eq "-s")
821 1 0 !defined($s) || $s == 0 ? :
1 1 if ($op eq "-z")
822 1 0 length $path > 0 ? :
1 0 if ($op eq "-n")
823 0 0 -l $path ? :
0 0 if ($op eq "-L")
827 0 14 if ($expr =~ /\A(.+?)\s+(=|==|!=|<|>)\s+(.+)\z/)
831 0 0 $a eq $b ? :
0 0 if ($op eq "=" or $op eq "==")
832 0 0 $a ne $b ? :
0 0 if ($op eq "!=")
833 0 0 $a lt $b ? :
0 0 if ($op eq "<")
834 0 0 $a gt $b ? :
0 0 if ($op eq ">")
838 14 0 if ($expr =~ /\A(.+?)\s+(-eq|-ne|-lt|-le|-gt|-ge)\s+(.+)\z/)
842 14 0 if $a =~ /\A-?\d+\z/
843 14 0 if $b =~ /\A-?\d+\z/
844 1 1 $a == $b ? :
2 12 if ($op eq "-eq")
845 0 0 $a != $b ? :
0 12 if ($op eq "-ne")
846 5 1 $a < $b ? :
6 6 if ($op eq "-lt")
847 0 0 $a <= $b ? :
0 6 if ($op eq "-le")
848 2 0 $a > $b ? :
2 4 if ($op eq "-gt")
849 1 3 $a >= $b ? :
4 0 if ($op eq "-ge")
853 0 0 if ($expr =~ /\A-n\s+(.+)\z/)
855 0 0 length $s > 0 ? :
858 0 0 if ($expr =~ /\A-z\s+(.+)\z/)
860 0 0 length $s == 0 ? :
865 0 0 length $expr > 0 && $expr ne '0' ? :
891 0 7 if ($cond_str =~ /\A(.+?)\s*;\s*then\s+(.+?)\s*;\s*fi\s*\z/i)
894 0 0 if ($cond_status == 0)
911 16 0 $ls =~ /\A(\S+)/ ? :
913 4 12 if ($lc_first eq 'fi') { }
1 11 elsif ($lc_first eq 'elif') { }
3 8 elsif ($lc_first eq 'else') { }
0 8 elsif ($lc_first eq 'then') { }
934 6 0 $els =~ /\A(\S+)/ ? :
3 3 if (lc($els =~ /\A(\S+)/ ? $1 : "") eq "fi")
955 6 2 if ($cond_status == 0)
961 1 6 if (not $executed and defined $else_body)
981 2 0 if ($for_line =~ /\Afor\s+([A-Za-z_][A-Za-z0-9_]*)\s+in\s+(.*?)\s*(?:;\s*do)?\s*\z/i)
992 4 0 $ls =~ /\A(\S+)/ ? :
993 0 4 if ($lc_f eq "for" or $lc_f eq "while" or $lc_f eq "until")
994 2 0 if $depth == 0
2 2 if ($lc_f eq "done")
995 2 0 unless $lc_f eq "do" and $depth == 1
1005 0 6 if $_BREAK or defined $_EXIT_CODE
1023 1 1 $while_line =~ /\Auntil\s/i ? :
1038 4 0 $ls =~ /\A(\S+)/ ? :
1039 0 4 if ($lc_f eq "for" or $lc_f eq "while" or $lc_f eq "until")
1040 2 0 if $depth == 0
2 2 if ($lc_f eq "done")
1041 2 0 unless $lc_f eq "do" and $depth == 1
1047 0 10 if defined $_EXIT_CODE
1050 1 9 if $is_until and $cond_true
1051 1 5 unless $is_until or $cond_true
1054 0 8 if $_BREAK
1074 1 0 if ($case_line =~ /\Acase\s+(.*?)\s+in\s*\z/i)
1085 0 4 if $pl =~ /\A\s*\z/
1086 4 0 $pl =~ /\A(\S+)/ ? :
1087 1 3 if $lc_f eq "esac"
1088 0 3 if $pl =~ /\A\s*;;\s*\z/
1091 3 0 if ($pl =~ /\A(.*?)\)\s*(.+?)\s*;;\s*\z/)
1093 2 1 unless ($matched)
1096 1 1 if (_match_pattern($word, $pat))
1107 0 0 if ($pl =~ /\A(.*?)\)\s*\z/)
1113 0 0 if $bl =~ /\A\s*;;\s*\z/
1114 0 0 if ($bl =~ /\A(.+?)\s*;;\s*\z/)
1117 0 0 unless ($matched)
1120 0 0 if (_match_pattern($word, $pat))
1136 0 2 if $pat eq "*"
1141 1 1 $word =~ /\A$re\z/ ? :
1185 0 1371 if ($in_sq)
1186 0 0 if ($ch eq "'")
1189 0 1371 if ($ch eq "'" and not $in_dq)
1192 26 1345 if ($ch eq "\"" and not $in_sq)
1195 148 1197 if ($in_dq)
1196 0 148 if ($ch eq "\\")
1198 0 0 if $i < $n
1204 0 1197 if ($ch eq "\\")
1206 0 0 if $i < $n
1210 0 0 $i + 3 < $n ? :
0 0 if ($ch =~ /[012]/ and $i + 2 < $n and $chars[$i + 1] eq ">" and $i + 3 < $n ? $chars[$i + 2] eq ">" : 0 and $chars[$i + 3] eq "&")
1222 0 37 if ($ch =~ /[012]/ and $i + 2 < $n and $chars[$i + 1] eq ">" and $chars[$i + 2] eq "&")
1234 0 1197 if ($ch =~ /[012]/ and $i + 1 < $n and $chars[$i + 1] eq '>') { }
0 1197 elsif ($ch eq '<') { }
0 1197 elsif ($ch eq '>') { }
1243 0 0 if $file ne ""
1250 0 1197 if (defined $redir_fd)
1253 0 0 if ($i + 1 < $n and $chars[$i + 1] eq ">")
1262 0 0 if $file ne ""
1288 0 0 if ($fd == 0) { }
0 0 elsif ($fd == 1) { }
1290 0 0 if ($file eq '&2') { }
1294 0 0 if ($file eq '&1') { }
1303 0 0 if (defined $in_file and $ok)
1305 0 0 unless (open _SH_REDIR_SRC, $in_file)
1306 0 0 if ($ok)
1307 0 0 unless (open _SH_REDIR_SAVIN, "<&STDIN")
1309 0 0 if ($ok)
1310 0 0 unless (open STDIN, "<&_SH_REDIR_SRC")
1317 0 0 if (defined $out_file and $ok) { }
0 0 elsif ($out_to_stderr and $ok) { }
1318 0 0 $out_app ? :
1320 0 0 unless (open _SH_REDIR_DST, "$mode$out_file")
1321 0 0 if ($ok)
1322 0 0 unless (open _SH_REDIR_SAVOUT, ">&STDOUT")
1324 0 0 if ($ok)
1325 0 0 unless (open STDOUT, ">&_SH_REDIR_DST")
1331 0 0 unless (open _SH_REDIR_SAVOUT, ">&STDOUT")
1332 0 0 if ($ok)
1333 0 0 unless (open STDOUT, ">&STDERR")
1339 0 0 if (defined $err_file and $ok) { }
0 0 elsif ($err_to_stdout and $ok) { }
1340 0 0 $err_app ? :
1342 0 0 unless (open _SH_REDIR_DST, "$mode$err_file")
1343 0 0 if ($ok)
1344 0 0 unless (open _SH_REDIR_SAVERR, ">&STDERR")
1346 0 0 if ($ok)
1347 0 0 unless (open STDERR, ">&_SH_REDIR_DST")
1354 0 0 unless (open _SH_REDIR_SAVERR, ">&STDERR")
1355 0 0 if ($ok)
1356 0 0 unless (open STDERR, ">&STDOUT")
1362 0 0 if ($ok)
1367 0 0 if ($saved_err)
1368 0 0 if ($saved_out)
1369 0 0 if ($saved_in)
1390 0 1812 if ($in_sq)
1391 0 0 if ($ch eq "'")
1394 0 1812 if ($ch eq "'" and not $in_dq)
1397 30 1782 if ($ch eq "\"" and not $in_sq)
1400 220 1562 if ($in_dq)
1401 0 220 if ($ch eq '$' and $i + 1 < $n and $chars[$i + 1] eq '(') { }
0 428 elsif ($ch eq ')' and $depth > 0) { }
1407 11 38 if ($ch eq "\$" and $i + 1 < $n and $chars[$i + 1] eq "(")
1410 11 1540 if ($ch eq ")" and $depth > 0)
1415 106 1434 if ($depth > 0)
1418 0 1434 if ($ch eq "\\")
1420 0 0 if $i < $n
1424 3 0 if ($ch eq "&" and $i + 1 < $n and $chars[$i + 1] eq "&")
1431 2 4 if ($ch eq "|" and $i + 1 < $n and $chars[$i + 1] eq "|")
1438 1 1428 if ($ch eq ";")
1450 6 127 if $p->{'op'} ne ""
1451 5 116 if $has_op
1468 11 6 if ($op eq '') { }
1470 5 6 if ($pending_op eq '') { }
3 3 elsif ($pending_op eq '&&') { }
2 1 elsif ($pending_op eq '||') { }
1 0 elsif ($pending_op eq ';') { }
1471 5 0 if $cmd =~ /\S/
1474 1 2 if ($LAST_STATUS == 0 and $cmd =~ /\S/)
1479 2 0 if ($LAST_STATUS != 0 and $cmd =~ /\S/)
1484 1 0 if $cmd =~ /\S/
1511 0 1724 if ($in_sq)
1512 0 0 if ($ch eq "'")
1517 30 1694 if ($ch eq "\"" and not $in_sq)
1523 220 1474 if ($in_dq)
1524 0 18 if ($ch eq "\$" and $i + 1 < $n and $chars[$i + 1] eq "(")
1527 0 220 if ($ch eq ")" and $depth > 0)
1531 0 220 if ($ch eq "\\")
1533 0 0 if $i < $n
1539 0 1474 if ($ch eq "'")
1542 11 38 if ($ch eq "\$" and $i + 1 < $n and $chars[$i + 1] eq "(")
1545 22 0 if $depth > 0
22 1441 if ($ch eq "(")
1546 22 1419 if ($ch eq ")")
1547 22 0 if ($depth > 0)
1552 4 1415 if ($ch eq "|" and $depth == 0)
1554 0 4 if ($i + 1 < $n and $chars[$i + 1] eq "|")
1563 0 1415 if ($ch eq "\\")
1565 0 0 if $i < $n
1590 0 7 unless $seg =~ /\S/
1592 3 4 $idx == $n_segs - 1 ? :
1593 3 4 $is_last ? :
1597 4 3 if (defined $input_f and -f $input_f)
1599 0 4 unless (open _SH_PIPE_RFH, $input_f)
1601 0 4 unless (open _SH_PIPE_SAVIN, "<&STDIN")
1603 0 4 unless (open STDIN, "<&_SH_PIPE_RFH")
1614 4 3 if (defined $output_f)
1616 0 4 unless (open _SH_PIPE_WFH, ">$output_f")
1617 0 0 if ($saved_in)
1624 0 4 unless (open _SH_PIPE_SAVOUT, ">&STDOUT")
1626 0 0 if ($saved_in)
1632 0 4 unless (open STDOUT, ">&_SH_PIPE_WFH")
1635 0 0 if ($saved_in)
1648 4 3 if ($saved_out)
1654 4 3 if ($saved_in)
1663 0 3 if defined $input_f and -f $input_f
1679 4 8 if ($c eq '*') { }
0 8 elsif ($c eq '?') { }
0 8 elsif ($c eq '[') { }
1680 3 1 $greedy ? :
1705 1 1 if ($greedy) { }
1707 1 0 $val =~ /\A(.*?)$re\z/s ? :
1711 1 0 $val =~ /\A(.*)$re\z/s ? :
1722 2 0 $val =~ /\A$re(.*)\z/s ? :
1728 1 1 if ($global) { }
1749 6 0 if ($line =~ /\A([A-Za-z_][A-Za-z0-9_]*)\s*\(\s*\)\s*(?:\{.*)?\z/) { }
0 0 elsif ($line =~ /\Afunction\s+([A-Za-z_][A-Za-z0-9_]*)\s*(?:\(\s*\))?\s*(?:\{.*)?\z/i) { }
1760 6 0 $line =~ /\{/ ? :
1765 1 5 if ($depth >= 1 and $line =~ /\{(.*)\}\s*\z/s)
1771 1 0 if $part =~ /\S/
1777 0 5 if ($depth == 0)
1781 0 0 if ($l =~ /\{/)
1791 5 8 if ($depth <= 0)
1794 0 5 if $before =~ /\S/
1809 0 6 unless exists $BATsh::SH::_SH_FUNCTIONS{$name}
1816 5 49 defined $args[$n - 1] ? :
1822 5 49 defined $args[$n - 1] ? :
1836 6 0 if (@FUNCTION_STACK)
1840 2 0 if (defined $old) { }
1848 0 54 defined $v ? :
1852 1 53 defined $v ? :
1854 0 6 defined $saved_star ? :
1865 0 6 unless defined $str
1867 2 4 unless $str =~ /\S/
1873 0 14 if ($in_sq)
1874 0 0 if ($ch eq q[']) { }
1877 0 14 if ($ch eq "'" and not $in_dq)
1878 0 14 if ($ch eq "\"" and not $in_sq)
1879 1 0 if ($ch =~ /\s/ and not $in_sq and not $in_dq)
1885 4 0 if $cur ne "" or @args
1893 0 4 unless defined $rest
1895 4 0 $rest ne '' ? :
1898 2 2 $rc == 0 ? :
1907 113 0 if ($line =~ /\A(\S+)\s*(.*)\z/s)
1922 0 7 if ($@)