Branch Coverage

lib/BATsh/CMD.pm
Criterion Covered Total %
branch 312 554 56.3


line true false branch
34 0 15 if ($] < "5.006" and not defined &warnings::import)
36 0 15 if $INC[-1] eq "."
71 23 301 if ($l =~ /\A:([A-Za-z_][A-Za-z0-9_]*)\s*\z/)
83 51 284 if ($_GOTO_LABEL ne "")
86 29 22 if (exists $labels{$lbl}) { }
22 0 elsif ($lbl eq 'EOF') { }
97 1 283 if (defined $rc and $rc eq "__EXIT__")
126 1 0 if ($i <= $#in) { }
156 335 56 unless defined $pre_expanded
162 22 369 if ($line =~ s/\A\@//)
164 0 391 if $line =~ /\A\s*\z/
165 0 391 if $line =~ /\A::/
166 0 391 if $line =~ /\AREM(?:\s|\z)/i
167 10 381 if $line =~ /\A:[A-Za-z_]/
168 0 381 if $line =~ /\A\s*\)\s*(?:ELSE\s*.*)??\s*\z/i
169 0 381 if $line =~ /\A#/
171 325 56 if (not $pre_expanded) { }
8 48 elsif (BATsh::Env::delayed_expansion()) { }
181 4 377 if ($line =~ /[&|]/)
183 3 1 if (@parts > 1)
199 11 314 if ($line =~ /\AFOR\s/i) { }
200 11 0 if ($line =~ m[\A(FOR\s+(?:/[A-Za-z]\s+(?:"[^"]*"\s+)?)?%%[A-Za-z]\s+(?:/[A-Za-z]\s+)?IN\s*\([^)]*\)\s+DO\s+)(.*)\z]i) { }
238 1 125 if ($ch eq "^" and not $in_q)
241 1 0 if ($j < $n)
244 0 125 if ($ch eq "\"")
245 2 123 if (not $in_q and $ch eq "&")
246 1 1 if ($j + 1 < $n and $chars[$j + 1] eq '&') { }
256 4 119 if (not $in_q and $ch eq "|")
257 0 4 if ($j + 1 < $n and $chars[$j + 1] eq '|') { }
4 0 elsif ($j + 1 < $n and $chars[$j + 1] ne '>') { }
273 6 0 if $cur =~ /\S/
286 1 7 if ($part->{'op'} eq "|")
298 4 2 if ($op eq '') { }
300 2 2 if ($pending_op eq '') { }
1 1 elsif ($pending_op eq '&&') { }
0 1 elsif ($pending_op eq '||') { }
1 0 elsif ($pending_op eq '&') { }
301 2 0 if $cmd =~ /\S/
304 1 0 if $ERRORLEVEL == 0 and $cmd =~ /\S/
307 0 0 if $ERRORLEVEL != 0 and $cmd =~ /\S/
310 1 0 if $cmd =~ /\S/
323 0 6 unless $cmd =~ /\S/
349 1 2 if ($op eq '|') { }
2 0 elsif ($op eq '') { }
372 0 2 unless $seg =~ /\S/
374 1 1 $idx == $n_segs - 1 ? :
375 1 1 $is_last ? :
379 1 1 if (defined $input_f and -f $input_f)
381 0 1 unless (open _PIPE_RFH, $input_f)
383 0 1 unless (open _PIPE_SAVIN, "<&STDIN")
385 0 1 unless (open STDIN, "<&_PIPE_RFH")
392 1 1 if (defined $output_f)
394 0 1 unless (open _PIPE_WFH, ">$output_f")
395 0 0 if ($saved_in)
400 0 1 unless (open _PIPE_SAVOUT, ">&STDOUT")
402 0 0 if ($saved_in)
406 0 1 unless (open STDOUT, ">&_PIPE_WFH")
409 0 0 if ($saved_in)
420 1 1 if ($saved_out)
426 1 1 if ($saved_in)
436 0 1 if defined $input_f and -f $input_f
459 3 6250 if ($ch eq "^" and not $in_q)
463 3 0 if $i < $n
467 118 6132 if ($ch eq "\"")
468 3 5935 if (not $in_q and $ch eq '>' || $ch eq '<')
470 0 3 $ch eq '<' ? :
475 0 3 if ($clean =~ s/(?:\A|(?<=[ \t]))([12])[ \t]*\z//)
480 1 2 if (not $is_in and $i < $n and $chars[$i] eq ">")
485 0 3 if ($i < $n and $chars[$i] eq '"') { }
493 0 3 $is_in ? :
515 381 3 unless @{$redirs;}
523 0 3 if ($fd == 0) { }
3 0 elsif ($fd == 1) { }
532 0 3 if (defined $in_file and $ok)
533 0 0 unless (open _REDIR_SRC, $in_file)
534 0 0 if ($ok)
535 0 0 unless (open _REDIR_SAVIN, "<&STDIN")
537 0 0 if ($ok)
538 0 0 unless (open STDIN, "<&_REDIR_SRC")
545 3 0 if (defined $out_file and $ok)
546 1 2 $out_app ? :
547 0 3 unless (open _REDIR_DST, "$mode$out_file")
548 3 0 if ($ok)
549 0 3 unless (open _REDIR_SAVOUT, ">&STDOUT")
551 3 0 if ($ok)
552 0 3 unless (open STDOUT, ">&_REDIR_DST")
559 0 3 if (defined $err_file and $ok)
560 0 0 $err_app ? :
561 0 0 unless (open _REDIR_DST, "$mode$err_file")
562 0 0 if ($ok)
563 0 0 unless (open _REDIR_SAVERR, ">&STDERR")
565 0 0 if ($ok)
566 0 0 unless (open STDERR, ">&_REDIR_DST")
573 3 0 if $ok
576 0 3 if ($saved_err)
577 3 0 if ($saved_out)
578 0 3 if ($saved_in)
590 0 384 unless defined $cmd and $cmd ne ""
594 118 266 if ($CMD eq "ECHO")
595 0 266 if ($CMD eq "\@ECHO")
596 96 170 if ($CMD eq "SET")
597 46 124 if ($CMD eq "IF")
598 11 113 if ($CMD eq "FOR")
599 51 62 if ($CMD eq "GOTO")
604 29 33 if ($CMD eq "CALL")
605 12 21 if ($CMD eq "SHIFT")
606 8 13 if ($CMD eq "SETLOCAL")
611 8 5 if ($CMD eq "ENDLOCAL")
612 0 5 if ($CMD eq "CD" or $CMD eq "CHDIR")
613 0 5 if ($CMD eq "DIR")
614 0 5 if ($CMD eq "COPY")
615 0 5 if ($CMD eq "DEL" or $CMD eq "ERASE")
616 0 5 if ($CMD eq "MOVE")
617 0 5 if ($CMD eq "MKDIR" or $CMD eq "MD")
618 0 5 if ($CMD eq "RMDIR" or $CMD eq "RD")
619 0 5 if ($CMD eq "REN" or $CMD eq "RENAME")
620 3 2 if ($CMD eq "TYPE")
621 0 2 if ($CMD eq "PAUSE")
628 1 1 if ($CMD eq "EXIT")
630 1 0 $rest =~ s[/B\s*][]i ? :
632 1 0 $rest =~ /\A\d+\z/ ? :
635 0 1 if ($CMD eq "CLS")
636 0 1 if ($CMD eq "TITLE")
637 0 1 if ($CMD eq "VER")
638 0 1 if ($CMD eq "PUSHD")
643 0 1 if ($CMD eq "POPD")
644 0 0 if (defined $opts_ref->{'_pushd_stack'} and @{$opts_ref->{'_pushd_stack'};})
660 22 96 if ($rest =~ /\AOFF\s*\z/i)
661 0 96 if ($rest =~ /\AON\s*\z/i)
662 0 96 if ($rest =~ /\A\.\s*\z/)
663 0 0 $ECHO_ON ? :
0 96 if ($rest =~ /\A\s*\z/)
680 3 93 if ($rest =~ s[\A/P\s*][]i)
681 3 0 if ($rest =~ /\A([A-Za-z_][A-Za-z0-9_]*)\s*=(.*)/)
685 0 3 unless defined $input
694 40 53 if ($rest =~ s[\A/A\s*][]i)
695 40 0 if ($rest =~ /\A\s*([A-Za-z_][A-Za-z0-9_]*)\s*=(.*)/) { }
706 0 53 if ($rest =~ /\A\s*\z/)
714 53 0 if ($rest =~ /\A([^=]+?)\s*=(.*)/)
721 0 0 if ($rest =~ /\A(\S+)\s*\z/)
724 0 0 if (index(uc $k, $prefix) == 0)
742 4 0 defined $v && $v =~ /^-?\d+$/ ? :
749 40 0 if ($expr =~ m[\A[\d\s\+\-\*/\%\(\)\^\&\|\~\<\>]+\z])
752 40 0 defined $result ? :
780 2 44 if ($rest =~ s/\ANOT\s+//i)
785 1 45 if ($rest =~ s[\A/I\s+][]i) { }
3 42 elsif ($rest =~ s/\AERRORLEVEL\s+(\d+)\s*//i) { }
2 40 elsif ($rest =~ s/\AEXIST\s+//i) { }
1 39 elsif ($rest =~ s/\ADEFINED\s+(\S+)\s*//i) { }
39 0 elsif ($rest =~ s/\A("(?:[^"]*)"|[^\s=][^\s=]*)\s*==\s*("(?:[^"]*)"|[^\s=]*)\s*//) { }
787 1 0 if ($rest =~ s/\A("(?:[^"]*)"|[^\s=][^\s=]*)\s*==\s*("(?:[^"]*)"|[^\s=]*)\s*//)
791 1 0 lc $a eq lc $b ? :
796 2 1 $ERRORLEVEL >= int $1 ? :
801 1 1 if ($rest =~ s/\A"([^"]+)"\s*//) { }
1 0 elsif ($rest =~ s/\A(\S+)\s*//) { }
807 2 0 defined $path && -e $path ? :
811 1 0 'BATsh::Env'->exists_var($1) ? :
818 12 27 $a eq $b ? :
821 2 44 if $negate
828 46 0 if defined $then_body
829 2 44 if defined $else_body
831 20 26 if ($condition) { }
2 24 elsif (defined $else_body) { }
846 0 50 unless defined $body
853 3 0 exists $BATsh::Env::STORE{$k} ? :
867 4 42 if ($rest =~ s/\A\(//) { }
871 0 42 if ($rest =~ s/\s+ELSE\s+(.+)\z//i)
880 0 8 if defined $first_content and $first_content =~ /\S/
887 2 19 if ($depth == 1 and $ls =~ /\A\)\s*ELSE\s*\(\s*\z/i)
888 2 0 if (defined $else_ref)
891 0 19 if ($depth == 1 and $ls =~ /\A\)\s*ELSE\s+(.+)\z/i)
892 0 0 if (defined $else_ref)
897 0 207 if ($ch eq '"') { }
207 0 elsif (not $in_q) { }
898 0 207 if $ch eq "("
6 201 if $ch eq ")"
901 6 13 if ($depth <= 0)
903 0 6 if $l =~ /\S/
913 0 28 unless defined $body and $body =~ /\S/
914 0 28 unless defined $pre_expanded
920 0 37 if ($ls =~ /\A:([A-Za-z_][A-Za-z0-9_]*)\s*\z/)
929 0 37 if defined $rc and $rc eq "__EXIT__"
930 9 28 if ($_GOTO_LABEL ne "")
933 0 9 if (exists $sub_labels{$lbl}) { }
952 6 5 if ($line =~ m[\AFOR\s+/F\s+("(?:[^"]*)"|'(?:[^']*)'|[^\s]+)\s+(?:%%|\x00FOR_)([A-Za-z])(?:\x00)?\s+IN\s*\(([^)]*)\)\s+DO\s+(.*)]i)
957 2 3 if ($line =~ m[\AFOR\s+/L\s+(?:%%|\x00FOR_)([A-Za-z])(?:\x00)?\s+IN\s*\(([^)]*)\)\s+DO\s+(.*)]i)
960 2 0 defined $start ? :
961 2 0 defined $step ? :
962 2 0 defined $end ? :
963 0 2 if $step == 0
977 3 0 if ($line =~ /\AFOR\s+(?:%%|\x00FOR_)([A-Za-z])(?:\x00)?\s+IN\s*\(([^)]*)\)\s+DO\s+(.*)/i)
983 0 9 if $item eq ""
984 0 9 if ($item =~ /[*?]/) { }
986 0 0 @g ? :
1011 2 3 if ($probe =~ /\A\s*\(\s*\z/)
1022 2 3 if (defined $paren_body_template)
1040 6 12 if (defined $paren_expanded) { }
1060 0 18 if $_GOTO_LABEL ne ""
1087 0 6 if $opts_str =~ /usebackq/i
1088 4 2 if ($opts_str =~ /tokens=(\S+)/i)
1092 2 4 if ($opts_str =~ /delims=([^\s"]*)/i) { }
0 4 elsif ($opts_str =~ /delims=\s*\z/i) { }
1094 0 2 if $delims eq ""
1099 1 5 if ($opts_str =~ /skip=(\d+)/i)
1100 1 5 if ($opts_str =~ /eol=(.)/i)
1104 1 5 $tokens_spec =~ /\*/ ? :
1110 0 6 if ($source_str =~ /\A'([^']*)'\z/ or $usebackq and $source_str =~ /\A`([^`]*)`\z/) { }
0 6 elsif ($usebackq and $source_str =~ /\A"([^"]*)"\z/) { }
3 3 elsif ($source_str =~ /\A"([^"]*)"\z/ and not $usebackq) { }
3 0 elsif ($source_str =~ /\A(\S+)\z/) { }
1115 0 0 unless open CMDOUT, "$cmd |"
1123 0 0 unless (open FFH, $file)
1135 0 3 unless (open FFH2, $file)
1145 1 5 if $skip > 0
1152 0 6 if ($probe =~ /\A\s*\(\s*\z/)
1168 1 7 if $eol ne "" and $src_line =~ /\A\Q$eol\E/
1169 0 7 if $src_line =~ /\A\s*\z/
1173 0 7 if ($delims eq '') { }
1180 0 7 if ($src_line =~ /\A[$escaped_delims]/)
1181 0 0 if @tokens and $tokens[0] eq ""
1188 10 0 defined $tokens[$tidx] ? :
1190 1 6 if ($want_star and @tokens > $token_indices[-1])
1192 1 0 length $delims > 0 ? :
1198 0 7 if (defined $paren_body) { }
1202 0 0 $want_star ? :
1203 0 0 defined 'BATsh::Env'->get("%%$vn") ? :
1213 1 6 $want_star ? :
1214 11 0 defined 'BATsh::Env'->get("%%$vn") ? :
1220 0 7 if $_GOTO_LABEL ne ""
1234 0 8 unless $part =~ /\S/
1235 0 8 if ($part =~ /\A(\d+)-(\d+)\z/) { }
8 0 elsif ($part =~ /\A(\d+)\z/) { }
1242 0 6 unless @indices
1253 29 0 if ($rest =~ /\A:([A-Za-z_][A-Za-z0-9_]*)(.*)/i)
1259 29 0 if (defined $opts_ref->{'_batsh'})
1265 0 0 if ($rest =~ /(\S+\.batsh)(.*)/i)
1267 0 0 if (defined $opts_ref->{'_batsh'})
1286 0 29 unless defined $s
1288 3 26 if $s eq ""
1294 2 162 if ($c eq "\"")
1295 18 144 if ($c =~ /\s/ and not $in_q)
1296 18 0 if ($have)
1301 26 0 if $have
1317 0 12 unless defined $rest
1319 1 11 if ($rest =~ m[/(\d)])
1320 0 12 if $start < 1
1321 0 12 if $start > 9
1325 95 0 defined $next ? :
1333 12 17 unless defined $v and $v ne ""
1341 108 0 defined $v ? :
1356 0 0 if ($rest eq "" or $rest =~ m[\A/D\s*\z]i)
1361 0 0 unless (chdir $rest)
1377 0 0 $rest eq '' ? :
1380 0 0 if $target eq ""
1382 0 0 unless (-e $target)
1384 0 0 if (-d $target) { }
1385 0 0 unless (opendir DH, $target)
1390 0 0 if $e eq "." or $e eq ".."
1392 0 0 if (-d $full) { }
1408 0 0 unless (defined $src and defined $dst)
1411 0 0 unless (File::Copy::copy($src, $dst))
1422 0 0 unless @files
1424 0 0 unless unlink $f
1433 0 0 unless (defined $src and defined $dst)
1436 0 0 unless (File::Copy::move($src, $dst))
1445 0 0 if (-d $rest)
1452 0 0 $rest =~ s[\s*/S\s*][]i ? :
1454 0 0 if ($recurse) { }
1456 0 0 unless (rmdir $rest)
1467 0 0 unless (defined $src and defined $dst)
1468 0 0 unless (rename $src, $dst)
1478 0 3 unless (open TFH, $rest)
1491 0 1 unless defined $rest
1493 1 0 $rest ne '' ? :
1497 1 0 $rc == 0 ? :
1506 384 0 if ($line =~ /\A(\S+)\s*(.*)\z/s)
1523 0 15 if ($@)