Branch Coverage

lib/BATsh/CMD.pm
Criterion Covered Total %
branch 280 528 53.0


line true false branch
30 0 7 if ($] < "5.006" and not defined &warnings::import)
32 0 7 if $INC[-1] eq "."
67 1 132 if ($l =~ /\A:([A-Za-z_][A-Za-z0-9_]*)\s*\z/)
79 1 109 if ($_GOTO_LABEL ne "")
82 1 0 if (exists $labels{$lbl}) { }
0 0 elsif ($lbl eq 'EOF') { }
93 0 109 if (defined $rc and $rc eq "__EXIT__")
116 1 0 if ($i <= $#in) { }
146 110 47 unless defined $pre_expanded
152 1 156 if ($line =~ s/\A\@//)
154 0 157 if $line =~ /\A\s*\z/
155 0 157 if $line =~ /\A::/
156 0 157 if $line =~ /\AREM(?:\s|\z)/i
157 0 157 if $line =~ /\A:[A-Za-z_]/
158 0 157 if $line =~ /\A\s*\)\s*(?:ELSE\s*.*)??\s*\z/i
159 0 157 if $line =~ /\A#/
161 110 47 if (not $pre_expanded) { }
8 39 elsif (BATsh::Env::delayed_expansion()) { }
171 4 153 if ($line =~ /[&|]/)
173 3 1 if (@parts > 1)
189 11 99 if ($line =~ /\AFOR\s/i) { }
190 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) { }
228 1 125 if ($ch eq "^" and not $in_q)
231 1 0 if ($j < $n)
234 0 125 if ($ch eq "\"")
235 2 123 if (not $in_q and $ch eq "&")
236 1 1 if ($j + 1 < $n and $chars[$j + 1] eq '&') { }
246 4 119 if (not $in_q and $ch eq "|")
247 0 4 if ($j + 1 < $n and $chars[$j + 1] eq '|') { }
4 0 elsif ($j + 1 < $n and $chars[$j + 1] ne '>') { }
263 6 0 if $cur =~ /\S/
276 1 7 if ($part->{'op'} eq "|")
288 4 2 if ($op eq '') { }
290 2 2 if ($pending_op eq '') { }
1 1 elsif ($pending_op eq '&&') { }
0 1 elsif ($pending_op eq '||') { }
1 0 elsif ($pending_op eq '&') { }
291 2 0 if $cmd =~ /\S/
294 1 0 if $ERRORLEVEL == 0 and $cmd =~ /\S/
297 0 0 if $ERRORLEVEL != 0 and $cmd =~ /\S/
300 1 0 if $cmd =~ /\S/
313 0 6 unless $cmd =~ /\S/
339 1 2 if ($op eq '|') { }
2 0 elsif ($op eq '') { }
362 0 2 unless $seg =~ /\S/
364 1 1 $idx == $n_segs - 1 ? :
365 1 1 $is_last ? :
369 1 1 if (defined $input_f and -f $input_f)
371 0 1 unless (open _PIPE_RFH, $input_f)
373 0 1 unless (open _PIPE_SAVIN, "<&STDIN")
375 0 1 unless (open STDIN, "<&_PIPE_RFH")
382 1 1 if (defined $output_f)
384 0 1 unless (open _PIPE_WFH, ">$output_f")
385 0 0 if ($saved_in)
390 0 1 unless (open _PIPE_SAVOUT, ">&STDOUT")
392 0 0 if ($saved_in)
396 0 1 unless (open STDOUT, ">&_PIPE_WFH")
399 0 0 if ($saved_in)
410 1 1 if ($saved_out)
416 1 1 if ($saved_in)
426 0 1 if defined $input_f and -f $input_f
449 3 2988 if ($ch eq "^" and not $in_q)
453 3 0 if $i < $n
457 44 2944 if ($ch eq "\"")
458 3 2783 if (not $in_q and $ch eq '>' || $ch eq '<')
460 0 3 $ch eq '<' ? :
465 0 3 if ($clean =~ s/(?:\A|(?<=[ \t]))([12])[ \t]*\z//)
470 1 2 if (not $is_in and $i < $n and $chars[$i] eq ">")
475 0 3 if ($i < $n and $chars[$i] eq '"') { }
483 0 3 $is_in ? :
505 157 3 unless @{$redirs;}
513 0 3 if ($fd == 0) { }
3 0 elsif ($fd == 1) { }
522 0 3 if (defined $in_file and $ok)
523 0 0 unless (open _REDIR_SRC, $in_file)
524 0 0 if ($ok)
525 0 0 unless (open _REDIR_SAVIN, "<&STDIN")
527 0 0 if ($ok)
528 0 0 unless (open STDIN, "<&_REDIR_SRC")
535 3 0 if (defined $out_file and $ok)
536 1 2 $out_app ? :
537 0 3 unless (open _REDIR_DST, "$mode$out_file")
538 3 0 if ($ok)
539 0 3 unless (open _REDIR_SAVOUT, ">&STDOUT")
541 3 0 if ($ok)
542 0 3 unless (open STDOUT, ">&_REDIR_DST")
549 0 3 if (defined $err_file and $ok)
550 0 0 $err_app ? :
551 0 0 unless (open _REDIR_DST, "$mode$err_file")
552 0 0 if ($ok)
553 0 0 unless (open _REDIR_SAVERR, ">&STDERR")
555 0 0 if ($ok)
556 0 0 unless (open STDERR, ">&_REDIR_DST")
563 3 0 if $ok
566 0 3 if ($saved_err)
567 3 0 if ($saved_out)
568 0 3 if ($saved_in)
580 0 160 unless defined $cmd and $cmd ne ""
584 47 113 if ($CMD eq "ECHO")
585 0 113 if ($CMD eq "\@ECHO")
586 66 47 if ($CMD eq "SET")
587 15 32 if ($CMD eq "IF")
588 11 21 if ($CMD eq "FOR")
589 1 20 if ($CMD eq "GOTO")
594 0 20 if ($CMD eq "CALL")
595 8 12 if ($CMD eq "SETLOCAL")
600 8 4 if ($CMD eq "ENDLOCAL")
601 0 4 if ($CMD eq "CD" or $CMD eq "CHDIR")
602 0 4 if ($CMD eq "DIR")
603 0 4 if ($CMD eq "COPY")
604 0 4 if ($CMD eq "DEL" or $CMD eq "ERASE")
605 0 4 if ($CMD eq "MOVE")
606 0 4 if ($CMD eq "MKDIR" or $CMD eq "MD")
607 0 4 if ($CMD eq "RMDIR" or $CMD eq "RD")
608 0 4 if ($CMD eq "REN" or $CMD eq "RENAME")
609 3 1 if ($CMD eq "TYPE")
610 0 1 if ($CMD eq "PAUSE")
617 0 1 if ($CMD eq "EXIT")
619 0 0 $rest =~ s[/B\s*][]i ? :
621 0 0 $rest =~ /\A\d+\z/ ? :
624 0 1 if ($CMD eq "CLS")
625 0 1 if ($CMD eq "TITLE")
626 0 1 if ($CMD eq "VER")
627 0 1 if ($CMD eq "PUSHD")
632 0 1 if ($CMD eq "POPD")
633 0 0 if (defined $opts_ref->{'_pushd_stack'} and @{$opts_ref->{'_pushd_stack'};})
649 1 46 if ($rest =~ /\AOFF\s*\z/i)
650 0 46 if ($rest =~ /\AON\s*\z/i)
651 0 46 if ($rest =~ /\A\.\s*\z/)
652 0 0 $ECHO_ON ? :
0 46 if ($rest =~ /\A\s*\z/)
669 3 63 if ($rest =~ s[\A/P\s*][]i)
670 3 0 if ($rest =~ /\A([A-Za-z_][A-Za-z0-9_]*)\s*=(.*)/)
674 0 3 unless defined $input
683 15 48 if ($rest =~ s[\A/A\s*][]i)
684 15 0 if ($rest =~ /\A\s*([A-Za-z_][A-Za-z0-9_]*)\s*=(.*)/) { }
695 0 48 if ($rest =~ /\A\s*\z/)
703 48 0 if ($rest =~ /\A([^=]+?)\s*=(.*)/)
710 0 0 if ($rest =~ /\A(\S+)\s*\z/)
713 0 0 if (index(uc $k, $prefix) == 0)
731 4 0 defined $v && $v =~ /^-?\d+$/ ? :
738 15 0 if ($expr =~ m[\A[\d\s\+\-\*/\%\(\)\^\&\|\~\<\>]+\z])
741 15 0 defined $result ? :
769 2 13 if ($rest =~ s/\ANOT\s+//i)
774 1 14 if ($rest =~ s[\A/I\s+][]i) { }
3 11 elsif ($rest =~ s/\AERRORLEVEL\s+(\d+)\s*//i) { }
2 9 elsif ($rest =~ s/\AEXIST\s+//i) { }
1 8 elsif ($rest =~ s/\ADEFINED\s+(\S+)\s*//i) { }
8 0 elsif ($rest =~ s/\A("(?:[^"]*)"|[^\s=][^\s=]*)\s*==\s*("(?:[^"]*)"|[^\s=]*)\s*//) { }
776 1 0 if ($rest =~ s/\A("(?:[^"]*)"|[^\s=][^\s=]*)\s*==\s*("(?:[^"]*)"|[^\s=]*)\s*//)
780 1 0 lc $a eq lc $b ? :
785 2 1 $ERRORLEVEL >= int $1 ? :
790 1 1 if ($rest =~ s/\A"([^"]+)"\s*//) { }
1 0 elsif ($rest =~ s/\A(\S+)\s*//) { }
796 2 0 defined $path && -e $path ? :
800 1 0 'BATsh::Env'->exists_var($1) ? :
807 3 5 $a eq $b ? :
810 2 13 if $negate
817 15 0 if defined $then_body
818 2 13 if defined $else_body
820 11 4 if ($condition) { }
2 2 elsif (defined $else_body) { }
835 0 19 unless defined $body
842 3 0 exists $BATsh::Env::STORE{$k} ? :
856 4 11 if ($rest =~ s/\A\(//) { }
860 0 11 if ($rest =~ s/\s+ELSE\s+(.+)\z//i)
869 0 8 if defined $first_content and $first_content =~ /\S/
876 2 19 if ($depth == 1 and $ls =~ /\A\)\s*ELSE\s*\(\s*\z/i)
877 2 0 if (defined $else_ref)
880 0 19 if ($depth == 1 and $ls =~ /\A\)\s*ELSE\s+(.+)\z/i)
881 0 0 if (defined $else_ref)
886 0 207 if ($ch eq '"') { }
207 0 elsif (not $in_q) { }
887 0 207 if $ch eq "("
6 201 if $ch eq ")"
890 6 13 if ($depth <= 0)
892 0 6 if $l =~ /\S/
902 0 19 unless defined $body and $body =~ /\S/
903 0 19 unless defined $pre_expanded
909 0 28 if ($ls =~ /\A:([A-Za-z_][A-Za-z0-9_]*)\s*\z/)
918 0 28 if defined $rc and $rc eq "__EXIT__"
919 0 28 if ($_GOTO_LABEL ne "")
922 0 0 if (exists $sub_labels{$lbl}) { }
941 6 5 if ($line =~ m[\AFOR\s+/F\s+("(?:[^"]*)"|'(?:[^']*)'|[^\s]+)\s+(?:%%|\x00FOR_)([A-Za-z])(?:\x00)?\s+IN\s*\(([^)]*)\)\s+DO\s+(.*)]i)
946 2 3 if ($line =~ m[\AFOR\s+/L\s+(?:%%|\x00FOR_)([A-Za-z])(?:\x00)?\s+IN\s*\(([^)]*)\)\s+DO\s+(.*)]i)
949 2 0 defined $start ? :
950 2 0 defined $step ? :
951 2 0 defined $end ? :
952 0 2 if $step == 0
966 3 0 if ($line =~ /\AFOR\s+(?:%%|\x00FOR_)([A-Za-z])(?:\x00)?\s+IN\s*\(([^)]*)\)\s+DO\s+(.*)/i)
972 0 9 if $item eq ""
973 0 9 if ($item =~ /[*?]/) { }
975 0 0 @g ? :
1000 2 3 if ($probe =~ /\A\s*\(\s*\z/)
1011 2 3 if (defined $paren_body_template)
1029 6 12 if (defined $paren_expanded) { }
1049 0 18 if $_GOTO_LABEL ne ""
1076 0 6 if $opts_str =~ /usebackq/i
1077 4 2 if ($opts_str =~ /tokens=(\S+)/i)
1081 2 4 if ($opts_str =~ /delims=([^\s"]*)/i) { }
0 4 elsif ($opts_str =~ /delims=\s*\z/i) { }
1083 0 2 if $delims eq ""
1088 1 5 if ($opts_str =~ /skip=(\d+)/i)
1089 1 5 if ($opts_str =~ /eol=(.)/i)
1093 1 5 $tokens_spec =~ /\*/ ? :
1099 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/) { }
1104 0 0 unless open CMDOUT, "$cmd |"
1112 0 0 unless (open FFH, $file)
1124 0 3 unless (open FFH2, $file)
1134 1 5 if $skip > 0
1141 0 6 if ($probe =~ /\A\s*\(\s*\z/)
1157 1 7 if $eol ne "" and $src_line =~ /\A\Q$eol\E/
1158 0 7 if $src_line =~ /\A\s*\z/
1162 0 7 if ($delims eq '') { }
1169 0 7 if ($src_line =~ /\A[$escaped_delims]/)
1170 0 0 if @tokens and $tokens[0] eq ""
1177 10 0 defined $tokens[$tidx] ? :
1179 1 6 if ($want_star and @tokens > $token_indices[-1])
1181 1 0 length $delims > 0 ? :
1187 0 7 if (defined $paren_body) { }
1191 0 0 $want_star ? :
1192 0 0 defined 'BATsh::Env'->get("%%$vn") ? :
1202 1 6 $want_star ? :
1203 11 0 defined 'BATsh::Env'->get("%%$vn") ? :
1209 0 7 if $_GOTO_LABEL ne ""
1223 0 8 unless $part =~ /\S/
1224 0 8 if ($part =~ /\A(\d+)-(\d+)\z/) { }
8 0 elsif ($part =~ /\A(\d+)\z/) { }
1231 0 6 unless @indices
1242 0 0 if ($rest =~ /\A:([A-Za-z_][A-Za-z0-9_]*)(.*)/i)
1247 0 0 defined $args[$n - 1] ? :
1249 0 0 if (defined $opts_ref->{'_batsh'})
1255 0 0 if ($rest =~ /(\S+\.batsh)(.*)/i)
1257 0 0 if (defined $opts_ref->{'_batsh'})
1276 0 0 if ($rest eq "" or $rest =~ m[\A/D\s*\z]i)
1281 0 0 unless (chdir $rest)
1297 0 0 $rest eq '' ? :
1300 0 0 if $target eq ""
1302 0 0 unless (-e $target)
1304 0 0 if (-d $target) { }
1305 0 0 unless (opendir DH, $target)
1310 0 0 if $e eq "." or $e eq ".."
1312 0 0 if (-d $full) { }
1328 0 0 unless (defined $src and defined $dst)
1331 0 0 unless (File::Copy::copy($src, $dst))
1342 0 0 unless @files
1344 0 0 unless unlink $f
1353 0 0 unless (defined $src and defined $dst)
1356 0 0 unless (File::Copy::move($src, $dst))
1365 0 0 if (-d $rest)
1372 0 0 $rest =~ s[\s*/S\s*][]i ? :
1374 0 0 if ($recurse) { }
1376 0 0 unless (rmdir $rest)
1387 0 0 unless (defined $src and defined $dst)
1388 0 0 unless (rename $src, $dst)
1398 0 3 unless (open TFH, $rest)
1411 0 1 unless defined $rest
1413 1 0 $rest ne '' ? :
1417 1 0 $rc == 0 ? :
1426 160 0 if ($line =~ /\A(\S+)\s*(.*)\z/s)
1443 0 7 if ($@)