Branch Coverage

blib/lib/Doit.pm
Criterion Covered Total %
branch 550 880 62.5


line true false branch
43 2 54 if defined $can_coloring
48 54 0 !(($ENV{'TERM'} || '') =~ /^(|dumb)$/) && eval { do { require Term::ANSIColor; 1 } } ? :
53 54 0 if (_can_coloring()) { }
74 1 1 if (defined $label) { }
92 66 0 if ($level eq "auto")
96 0 360 unless (@stackinfo)
100 66 294 unless ($stackinfo[1] =~ m(([/\\]|^)Doit\.pm$))
116 2 39 unless defined $msg
117 39 2 unless ($msg =~ /\n\z/)
145 145 0 if ($] >= 5.014) { }
149 4 141 if ($@)
184 105 231 if (defined $dir)
187 2 103 if (not defined $pwd or $pwd eq '') { }
192 2 101 unless chdir $pwd
195 3 102 unless chdir $dir
205 6 75 ref $src eq 'ARRAY' ? :
206 0 81 unless @stat
209 38 43 exists $preserve{'ownership'} ? :
210 39 42 exists $preserve{'mode'} ? :
211 1 80 exists $preserve{'time'} ? :
213 0 81 if %preserve
215 78 3 if ($preserve_mode)
216 0 78 unless chmod $stat[2], $dest
219 78 3 if ($preserve_ownership)
221 0 78 unless (chown $stat[4], $stat[5], $dest)
228 41 40 if ($preserve_time)
229 0 41 unless utime $stat[8], $stat[9], $dest
238 0 0 if $> == 0
245 17 7 unless (defined &Doit::Util::_file_name_is_absolute)
246 0 17 if (eval { do { require File::Spec; defined &File::Spec::file_name_is_absolute } }) { }
252 0 24 if ($^O eq 'MSWin32') { }
262 0 24 if (_file_name_is_absolute($prog))
263 0 0 if ($^O eq 'MSWin32') { }
264 0 0 if -f $prog and -x $prog
265 0 0 if -f "$prog.bat" and -x "$prog.bat"
266 0 0 if -f "$prog.com" and -x "$prog.com"
267 0 0 if -f "$prog.exe" and -x "$prog.exe"
268 0 0 if -f "$prog.cmd" and -x "$prog.cmd"
270 0 0 if -f $prog and -x $prog
277 0 188 if ($^O eq 'MSWin32') { }
279 0 0 if -f "$_\\$prog" and -x "$_\\$prog"
280 0 0 if -f "$_\\$prog.bat" and -x "$_\\$prog.bat"
281 0 0 if -f "$_\\$prog.com" and -x "$_\\$prog.com"
282 0 0 if -f "$_\\$prog.exe" and -x "$_\\$prog.exe"
283 0 0 if -f "$_\\$prog.cmd" and -x "$_\\$prog.cmd"
285 17 171 if -x "$_/$prog" and not -d "$_/$prog"
297 1 14 if %opts
298 6 8 ref $candidate_files eq 'ARRAY' ? :
299 10 5 if ($refresh or not $cached_os_release_per_file{$candidate_file})
300 8 2 if (open my $fh, "<", $candidate_file)
303 76 2 if (my($k, $v) = $_ =~ /^(.*?)=["']?(.*?)["']?$/)
310 13 2 if $cached_os_release_per_file{$candidate_file}
326 0 0 if (_has_shell_metachars($args))
343 0 0 if ($text ne '' and not $text =~ /[ \t\n\x0a\x0b\x0c\x0d\x85"]/) { }
354 0 0 if ($i > $#text) { }
0 0 elsif ($text[$i] eq '"') { }
378 0 0 if ($char eq '%') { }
0 0 elsif ($char eq q['] or $char eq '"') { }
0 0 elsif ($char eq '<' or $char eq '>' or $char eq '|') { }
381 0 0 if ($inquote) { }
382 0 0 if ($char eq $quote)
391 0 0 unless ($inquote)
444 8 48 if ($dry_run) { }
453 2 0 unless ($msg)
454 2 0 $args ? :
460 2 1 if (&$check($self, \@args, $addinfo))
474 30 17 if (@args and ref $args[0] eq "HASH")
476 0 47 if %options
481 46 4 if (@s) { }
482 43 3 if (($s[2] & 4095) != $mode)
489 44 3 if (@files_to_change) { }
493 3 37 if ($changed_files != @files_to_change)
494 1 2 if (@files_to_change == 1) { }
1 1 elsif ($changed_files == 0) { }
503 29 15 $quiet ? :
514 2 10 if (@args and ref $args[0] eq "HASH")
516 0 12 if %options
519 3 9 if (not defined $uid) { }
2 7 elsif (not $uid =~ /^-?\d+$/) { }
523 1 1 unless (defined $_uid)
534 6 5 if (not defined $gid) { }
1 4 elsif (not $gid =~ /^-?\d+$/) { }
538 1 0 unless (defined $_gid)
545 9 1 if ($uid != -1 or $gid != -1)
548 7 3 if (@s) { }
549 0 7 if ($uid != -1 and $s[4] != $uid) { }
0 12 elsif ($gid != -1 and $s[5] != $gid) { }
560 2 8 if (@files_to_change) { }
564 2 0 if ($changed_files != @files_to_change)
565 1 1 if (@files_to_change == 1) { }
1 0 elsif ($changed_files == 0) { }
574 0 2 $quiet ? :
589 1 13 if %opts
591 1 12 unless ($cmd)
594 1 11 if (ref $cmd ne "ARRAY")
599 1 10 if ($if and not &$if())
602 1 9 if ($doit and $unless and &$unless())
605 2 7 if ($doit and $creates and -e $creates)
609 7 4 if ($doit) { }
611 1 6 if (ref $cmd->[0] eq 'ARRAY') { }
627 2 12 if (not defined $oldfile) { }
2 10 elsif (not defined $newfile) { }
4 6 elsif (-l $newfile) { }
2 4 elsif (-d $newfile) { }
2 2 elsif (-e $newfile) { }
632 0 4 unless my $points_to = readlink $newfile
634 2 2 if ($points_to eq $oldfile)
648 6 2 if ($doit) { }
662 1 4 if (ref $directories[-1] eq "HASH")
664 2 3 if (@directories_to_create) { }
668 0 2 unless File::Path::make_path(@directories_to_create, $options)
682 18 3 if (not -d $directory) { }
684 2 16 if (defined $mode) { }
686 1 1 unless mkdir $directory, $mode
692 1 15 unless mkdir $directory
705 1 3 if (ref $directories[-1] eq "HASH")
707 3 1 if (@directories_to_remove) { }
711 0 3 unless File::Path::remove_tree(@directories_to_remove, $options)
725 28 3 if (@args and ref $args[0] eq "HASH")
727 0 31 if %options
728 0 31 if (@args != 2)
734 1 27 unless rename $from, $to
736 7 24 if ($show_diff) { }
738 2 5 if (not -e $real_to) { }
754 3 14 if (@args and ref $args[0] eq "HASH")
756 1 16 if %options
757 1 15 if (@args != 2)
763 11 4 if (not -e $real_to or do { require File::Compare; File::Compare::compare($from, $real_to) != 0 }) { }
767 2 9 unless File::Copy::copy($from, $to)
771 7 4 if (not -e $real_to) { }
774 1 3 if ($quiet) { }
791 4 2 if (@args and ref $args[0] eq "HASH")
793 0 6 if %options
794 0 6 if (@args != 2)
802 1 4 unless File::Copy::move($from, $to)
806 3 3 if ($show_diff) { }
808 1 2 if (not -e $real_to) { }
823 1 62 if ($? == -1) { }
10 52 elsif ($? & 127) { }
831 0 10 $? & 128 ? :
849 0 58 if %opts
853 29 29 if (defined $prefix_msg)
861 42 113 if ($flag) { }
889 8 3 if (@args and ref $args[0] eq "HASH")
892 6 5 unless defined $instr
893 0 11 if %options
897 1 2 $quiet || $info ? :
3 7 unless $? == 0
903 4 7 $info ? :
1 10 $quiet ? :
912 1 2 if (@args and ref $args[0] eq "HASH")
927 27 11 defined $instr ? :
928 27 10 if (defined $instr)
942 74 34 if ($buf eq '') { }
945 37 37 if $sel->count == 0
959 37 2 if (@args and ref $args[0] eq "HASH")
965 0 39 if %options
970 30 7 if ($errref)
974 2 35 if ($statusref) { }
977 4 31 if ($? != 0)
978 1 3 $quiet || $info ? :
986 4 35 $info ? :
24 15 $quiet ? :
995 1 2 if (@args and ref $args[0] eq "HASH")
1004 0 172 unless open my $fh, "-|", @args
1014 166 7 if (@args and ref $args[0] eq "HASH")
1018 0 173 if %options
1022 2 170 if ($statusref) { }
1025 29 141 if ($? != 0)
1026 27 2 $quiet || $info ? :
1033 163 10 $info ? :
160 13 $quiet ? :
1042 159 3 if (@args and ref $args[0] eq "HASH")
1049 5 1 if (-d $directory) { }
1051 1 4 unless rmdir $directory
1062 2 9 if (@args and ref $args[0] eq "HASH")
1065 0 11 if %options
1072 3 7 if (not $success)
1076 0 11 $quiet ? :
2 9 $info ? :
1079 9 8 if (ref $arg eq 'ARRAY') { }
1095 0 1 if (@args and ref $args[0] eq "HASH")
1102 2 1 if (not defined $ENV{$key} or $ENV{$key} ne $val) { }
1105 1 1 defined $ENV{$key} ? :
1117 2 2 if (-l $newfile) { }
2 0 elsif (not -e $newfile) { }
1118 0 2 unless my $points_to = readlink $newfile
1120 0 2 if ($points_to ne $oldfile)
1128 2 2 if ($doit) { }
1130 0 2 unless symlink $oldfile, $newfile
1142 48 109 if (@args and ref $args[0] eq "HASH")
1146 0 157 if %options
1152 19 137 if ($? != 0)
1158 4 153 $info ? :
2 155 $quiet ? :
1169 0 3 if (@args and ref $args[0] eq "HASH")
1178 30 1 if (not -e $file) { }
1180 0 30 unless open my $fh, ">>", $file
1185 0 1 unless utime time, time, $file
1199 18 2 unless (-e $file)
1201 0 18 unless open my $fh, ">>", $file
1206 17 1 if (@commands) { }
1219 35 3 if (-e $file or -l $file)
1223 28 2 if (@files_to_remove) { }
1225 0 28 unless unlink @files_to_remove
1236 1 1 if (defined $ENV{$key}) { }
1252 1 9 unless (defined $atime)
1255 1 9 unless (defined $mtime)
1262 10 4 if (@s) { }
1263 10 0 if ($s[8] != $atime or $s[9] != $mtime)
1271 10 0 if (@files_to_change) { }
1275 3 7 if ($changed_files != @files_to_change)
1276 1 2 if (@files_to_change == 1) { }
1 1 elsif ($changed_files == 0) { }
1296 2 14 if (@args != 1)
1305 17 34 if (@args and ref $args[0] eq "HASH")
1307 1 50 exists $options{'atomic'} ? :
1308 1 50 if %options
1309 1 49 if (@args != 2)
1316 25 24 if (not -e $filename) { }
18 6 elsif (-s $filename != length $content) { }
1322 0 6 unless open my $fh, "<", $filename
1327 2 4 if ($file_content ne $content)
1333 45 4 if ($doit) { }
1339 44 1 $atomic ? :
1340 1 44 unless open my $ofh, ">", $outfile
1342 20 24 if (-e $filename)
1347 0 44 unless close $ofh
1349 43 1 if ($atomic)
1350 0 43 unless rename $outfile, $filename
1357 4 41 $quiet >= 2 ? :
1358 10 31 if ($quiet) { }
1359 3 7 if ($need_diff) { }
1365 14 17 if ($need_diff) { }
1382 3 44 if (@args and ref $args[0] eq "HASH")
1385 0 47 if ($check and ref $check ne "CODE")
1386 1 46 if %options
1388 1 45 if (@args < 1)
1393 2 43 unless (-e $file)
1396 2 41 unless (-f $file)
1403 26 20 if ($_->{'add_if_missing'})
1406 10 16 if (defined $_->{'add_after'} or defined $_->{'add_after_first'} or defined $_->{'add_before'} or defined $_->{'add_before_last'}) { }
1417 0 10 if ($defines != 1)
1423 4 6 if (defined $_->{'add_after'}) { }
2 4 elsif (defined $_->{'add_after_first'}) { }
2 2 elsif (defined $_->{'add_before'}) { }
2 0 elsif (defined $_->{'add_before_last'}) { }
1446 4 2 $reverse ? :
1447 4 2 $reverse ? :
1448 4 2 $reverse ? :
1449 11 2 $reverse ? :
1450 5 7 if ($arrayref->[$i] =~ /$add/)
1451 3 2 if ($do_after) { }
1460 1 5 if (not $found)
1473 29 17 if ($_->{'unless_match'}) { }
16 1 elsif ($_->{'match'}) { }
1474 26 3 if (ref $_->{'unless_match'} ne "Regexp")
1478 1 28 unless ($_->{'action'})
1481 1 27 if (ref $_->{'action'} ne "CODE")
1486 3 13 if (ref $_->{'match'} ne "Regexp")
1490 3 13 $_->{'action'} ? :
7 9 defined $_->{'replace'} ? :
5 11 defined $_->{'delete'} ? :
1491 1 15 if ($consequences != 1)
1494 3 12 if ($_->{'action'}) { }
7 5 elsif (defined $_->{'replace'}) { }
5 0 elsif (defined $_->{'delete'}) { }
1495 1 2 if (ref $_->{'action'} ne "CODE")
1515 0 36 unless File::Copy::copy($file, $tmpfile)
1520 0 36 unless tie my @lines, "Tie::File", $tmpfile
1527 0 44 if ($debug)
1528 18 26 if ($lines[$line_i] =~ /$match/)
1529 9 9 if (exists $match_action->{'replace'}) { }
6 3 elsif (exists $match_action->{'delete'}) { }
1531 9 0 if ($lines[$line_i] ne $replace)
1537 5 1 if ($match_action->{'delete'})
1555 8 62 if ($line =~ /$match/)
1568 25 10 if ($no_of_changes)
1571 2 22 if ($check)
1575 0 1 unless &$check($tmpfile)
1578 0 23 unless rename $tmpfile, $file
1588 25 10 if ($no_of_changes) { }
1599 14 35 if (ref $file2)
1604 10 39 unless (@diff_cmd)
1606 0 10 if ($^O eq "MSWin32")
1610 10 0 if (Doit::Util::is_in_path($diff_candidate->[0]))
1615 0 0 !$diff_error_shown++ ? :
0 10 unless @diff_cmd
1620 0 49 if ($^O eq "MSWin32" and $diff_cmd[0] eq "fc")
1622 0 0 if ($file2 eq "-")
1628 49 0 if (not $cannot_use_dash and eval { do { require IPC::Run; 1 } }) { }
1629 0 49 unless (eval { do { IPC::Run::run([@diff_cmd, $file1, $file2], defined $stdin ? ("<", \$stdin) : (), ">", \$diff, "2>", \$diff_stderr); 1 } })
1630 14 35 defined $stdin ? :
1632 0 0 !$diff_error_shown++ ? :
1636 0 0 if ($^O eq 'MSWin32' or $cannot_use_dash) { }
1638 0 0 if ($file2 eq "-")
1651 0 0 if ($@)
1652 0 0 !$diff_error_shown++ ? :
1664 4 21 if (-d $dest) { }
1676 0 3 if $? != 0
1681 2 1 unless (symlink $oldfile, $newfile)
1682 2 0 if ($!{'EEXIST'}) { }
1686 0 2 unless symlink $oldfile, $tmpfile
1688 0 2 unless rename $tmpfile, $newfile
1697 0 54 if ($ENV{'DOIT__USE_LN_NSF_PERL'}) { }
1720 49 0 if (@commands)
1728 475 279 if (exists $command->{'msg'})
1731 720 34 if (exists $command->{'code'})
1733 426 218 if (exists $command->{'rv'}) { }
1746 23 5 if (exists $command->{'msg'})
1747 12 11 $command->{'run_always'} ? :
1749 27 1 if (exists $command->{'code'})
1751 12 15 if ($command->{'run_always'})
1754 18 9 if (exists $command->{'rv'}) { }
1772 0 56 if %options
1791 29 741 if ($self->{'dryrun'}) { }
1806 3 21 if ($component_or_module =~ /::/) { }
1813 2 8 if $_->{'module'} eq $module
1816 1 21 unless (eval " require $module; 1 ")
1819 0 21 unless my $o = $module->new
1836 4 17 if ($o->can("add_components"))
1867 2 8 if ($context eq 'a') { }
1872 2 8 if ($@) { }
1882 6 0 unless $sub =~ /::/
1889 7 0 unless $sub =~ /::/
1936 0 23 if (not defined $ret) { }
1 22 elsif (not $ret) { }
1942 0 22 unless read $fh, $buf, $length
1949 0 22 unless (defined $fh)
1960 0 0 unless defined $pid
1961 0 0 if (eval { do { require POSIX; defined &POSIX::WNOHANG } }) { }
1962 0 0 if ($self->{'debug'})
1972 0 0 if (time - $start_time >= 2)
1978 0 0 if (not $got_pid)
1982 0 0 if (not $done_POSIX_warning++)
1998 0 0 if %opts
2002 0 0 if $ret
2004 0 0 if ($fast_tries and eval { do { require Time::HiRes; 1 } }) { }
2009 0 0 $try <= $fast_tries && defined &Time::HiRes::sleep ? :
2010 0 0 if $retry_msg_code
2028 0 2 if %options
2041 0 0 defined $self->{'label'} ? :
2048 0 11 if $do_exit and not $self->{'outfh'}
2049 2 9 wantarray ? :
2052 2 9 if (defined $rettype and $rettype eq 'e') { }
9 0 elsif (defined $rettype and $rettype eq 'r') { }
2055 1 8 if (defined $ret[0] and $ret[0] eq "bye-bye" and $do_exit)
2058 2 7 if ($context eq 'a') { }
2064 0 0 defined $rettype ? :
2071 0 0 if ($ret ne 'pong') { }
2089 0 0 if %options
2108 0 0 if ($self->{'debug'}) { }
2118 0 0 if (not $self->{'excl'} and -e $sockpath)
2122 0 0 unless my $sock = "IO::Socket::UNIX"->new("Type", SOCK_STREAM(), "Local", $sockpath, "Listen", 1)
2132 0 0 if $ready[0] != $sock
2139 0 0 if (not defined $context) { }
0 0 elsif ($data[0] eq 'exit') { }
0 0 elsif ($data[0] eq '__doit_rpc_ping') { }
2169 0 1 if %options
2171 0 1 unless $infh
2172 0 1 unless $outfh
2186 0 7 if (not defined $context) { }
1 6 elsif ($data[0] eq 'exit') { }
0 6 elsif ($data[0] eq '__doit_rpc_ping') { }
2195 0 6 unless open my $oldout, ">&STDOUT"
2203 0 6 unless open STDOUT, ">", "/dev/stderr"
2206 0 6 unless open STDOUT, ">&", $oldout
2228 0 0 if $^O eq "linux"
2245 0 0 unless (defined $realscript)
2246 0 0 if (defined $ENV{'DOIT_SCRIPT'}) { }
2256 0 0 if ($realscript ne '-e') { }
2283 0 0 unless delete $opts{'sudo_opts'}
2286 0 0 unless delete $opts{'components'}
2288 0 0 if %opts
2316 0 0 if ($? != 0)
2327 0 0 $class->_can_LANS ? :
2330 0 0 $debug ? :
0 0 $debug ? :
0 0 $LANS_PREFIX ? :
0 0 $dry_run ? :
2343 0 0 if (not defined $worker_pid) { }
0 0 elsif ($worker_pid == 0) { }
2346 0 0 if $debug
2355 0 0 $LANS_PREFIX ? :
2359 0 0 if $debug
2374 0 0 if %opts
2376 0 0 unless (-t STDIN)
2377 0 0 if ($debug)
2383 0 0 if (Doit::Util::is_in_path('stty')) { }
2385 0 0 if ($debug)
2389 0 0 if ($? == 0)
2397 0 0 if (not eval { do { require POSIX; my $term = 'POSIX::Termios'->new; my $fd = fileno STDIN; return 1 unless -t $fd; if ($debug) { &info('Reset terminal using POSIX.pm...'); } ; $term->getattr($fd); my $lflag = $term->getlflag; my $iflag = $term->getiflag; my $oflag = $term->getoflag; $lflag |= &POSIX::ICANON() | &POSIX::ISIG() | &POSIX::ECHO(); $iflag |= &POSIX::ICRNL(); $oflag |= &POSIX::OPOST(); $term->setlflag($lflag); $term->setiflag($iflag); $term->setoflag($oflag); $term->setattr($fd, &POSIX::TCSANOW()); 1 } }) { }
2402 0 0 unless -t $fd
2404 0 0 if ($debug)
2435 0 0 if ($self->{'rpc'})
2436 0 0 if ($self->{'rpc'}{'outfh'})
2462 0 6 unless delete $opts{'components'}
2470 6 0 unless defined $dest_os
2472 1 5 unless $put_to_remote =~ /^(rsync_put|scp_put)$/
2476 1 4 if (defined $umask and not $umask =~ /^\d+$/)
2480 0 4 if %opts
2483 0 4 $forward_agent ? :
0 4 $tty ? :
2487 0 4 $forward_agent ? :
4 0 $master_opts ? :
2493 0 4 if (UNIVERSAL::isa($ssh_or_host, 'Net::OpenSSH')) { }
2501 4 0 if $ssh->error
2506 0 0 if (($bootstrap || '') eq "perl")
2513 0 0 if ($dest_os eq 'MSWin32') { }
2518 0 0 if ($debug)
2523 0 0 if ($FindBin::RealScript ne "-e")
2532 0 0 $dest_os ne 'MSWin32' ? :
2546 0 0 unless ($seen_dir{$target_dir})
2548 0 0 if ($dest_os eq 'MSWin32') { }
2565 0 0 $dest_os eq 'MSWin32' ? :
2572 0 0 if (defined $as)
2573 0 0 if ($as eq 'root') { }
2581 0 0 if ($dest_os eq 'MSWin32') { }
2582 0 0 $0 eq '-e' ? :
0 0 $debug ? :
0 0 $dry_run ? :
2596 0 0 defined $umask ? :
0 0 $0 eq '-e' ? :
0 0 $debug ? :
0 0 $dry_run ? :
2611 0 0 if $debug
2616 0 0 if ($dest_os eq 'MSWin32') { }
2632 0 0 if $debug
2645 0 4 if ($self->{'ssh'})
2646 0 0 if $self->{'ssh'}->can("disconnect")
2649 0 4 if ($self->{'rpc'})
2662 0 0 unless defined $peer
2664 0 0 if %options
2674 0 0 if ($debug) { }
2693 0 0 if $sock
2703 0 0 unless ($sock)
2713 0 0 unless read $infh, $length_buf, 4
2719 0 0 if $got == $length
2720 0 0 if $got > $length
2733 0 0 if eof $infh