Branch Coverage

blib/lib/Doit.pm
Criterion Covered Total %
branch 525 844 62.2


line true false branch
43 2 53 if defined $can_coloring
48 53 0 !(($ENV{'TERM'} || '') =~ /^(|dumb)$/) && eval { do { require Term::ANSIColor; 1 } } ? :
53 53 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 140 0 if ($] >= 5.014) { }
149 4 136 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 72 ref $src eq 'ARRAY' ? :
206 0 78 unless @stat
209 35 43 exists $preserve{'ownership'} ? :
210 36 42 exists $preserve{'mode'} ? :
211 1 77 exists $preserve{'time'} ? :
213 0 78 if %preserve
215 75 3 if ($preserve_mode)
216 0 75 unless chmod $stat[2], $dest
219 75 3 if ($preserve_ownership)
221 0 75 unless (chown $stat[4], $stat[5], $dest)
228 41 37 if ($preserve_time)
229 0 41 unless utime $stat[8], $stat[9], $dest
238 0 0 if $> == 0
245 16 6 unless (defined &Doit::Util::_file_name_is_absolute)
246 0 16 if (eval { do { require File::Spec; defined &File::Spec::file_name_is_absolute } }) { }
252 0 22 if ($^O eq 'MSWin32') { }
262 0 22 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 172 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 16 156 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 7 47 if ($dry_run) { }
453 2 0 unless ($msg)
454 2 0 $args ? :
460 2 1 if (&$check($self, \@args, $addinfo))
474 25 17 if (@args and ref $args[0] eq "HASH")
476 0 42 if %options
481 41 4 if (@s) { }
482 38 3 if (($s[2] & 4095) != $mode)
489 39 3 if (@files_to_change) { }
493 3 33 if ($changed_files != @files_to_change)
494 1 2 if (@files_to_change == 1) { }
1 1 elsif ($changed_files == 0) { }
503 24 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 2 9 if ($if and not &$if())
602 1 8 if ($doit and $unless and &$unless())
605 2 6 if ($doit and $creates and -e $creates)
609 6 5 if ($doit) { }
611 1 5 if (ref $cmd->[0] eq 'ARRAY') { }
627 2 10 if (not defined $oldfile) { }
2 8 elsif (not defined $newfile) { }
4 4 elsif (-l $newfile) { }
2 2 elsif (-d $newfile) { }
632 0 4 unless my $points_to = readlink $newfile
634 2 2 if ($points_to eq $oldfile)
646 4 2 if ($doit) { }
660 1 4 if (ref $directories[-1] eq "HASH")
662 2 3 if (@directories_to_create) { }
666 0 2 unless File::Path::make_path(@directories_to_create, $options)
680 18 3 if (not -d $directory) { }
682 2 16 if (defined $mode) { }
684 1 1 unless mkdir $directory, $mode
690 1 15 unless mkdir $directory
703 1 3 if (ref $directories[-1] eq "HASH")
705 3 1 if (@directories_to_remove) { }
709 0 3 unless File::Path::remove_tree(@directories_to_remove, $options)
725 1 20 unless rename $from, $to
734 3 14 if (@args and ref $args[0] eq "HASH")
736 1 16 if %options
737 1 15 if (@args != 2)
743 4 11 if (-d $to) { }
749 11 4 if (not -e $real_to or do { require File::Compare; File::Compare::compare($from, $real_to) != 0 }) { }
753 2 9 unless File::Copy::copy($from, $to)
757 7 4 if (not -e $real_to) { }
760 1 3 if ($quiet) { }
780 1 1 unless File::Copy::move($from, $to)
790 1 62 if ($? == -1) { }
10 52 elsif ($? & 127) { }
798 0 10 $? & 128 ? :
816 0 58 if %opts
820 29 29 if (defined $prefix_msg)
828 42 111 if ($flag) { }
856 8 3 if (@args and ref $args[0] eq "HASH")
859 6 5 unless defined $instr
860 0 11 if %options
864 1 2 $quiet || $info ? :
3 7 unless $? == 0
870 4 7 $info ? :
1 10 $quiet ? :
879 1 2 if (@args and ref $args[0] eq "HASH")
894 27 11 defined $instr ? :
895 27 10 if (defined $instr)
909 74 34 if ($buf eq '') { }
912 37 37 if $sel->count == 0
926 37 2 if (@args and ref $args[0] eq "HASH")
932 0 39 if %options
937 30 7 if ($errref)
941 2 35 if ($statusref) { }
944 4 31 if ($? != 0)
945 1 3 $quiet || $info ? :
953 4 35 $info ? :
24 15 $quiet ? :
962 1 2 if (@args and ref $args[0] eq "HASH")
971 0 172 unless open my $fh, "-|", @args
981 166 7 if (@args and ref $args[0] eq "HASH")
985 0 173 if %options
989 2 170 if ($statusref) { }
992 29 141 if ($? != 0)
993 27 2 $quiet || $info ? :
1000 163 10 $info ? :
160 13 $quiet ? :
1009 159 3 if (@args and ref $args[0] eq "HASH")
1016 5 1 if (-d $directory) { }
1018 1 4 unless rmdir $directory
1034 3 5 if (not $success)
1041 6 8 if (ref $arg eq 'ARRAY') { }
1056 2 1 if (not defined $ENV{$key} or $ENV{$key} ne $val) { }
1059 1 1 defined $ENV{$key} ? :
1071 2 2 if (-l $newfile) { }
2 0 elsif (not -e $newfile) { }
1072 0 2 unless my $points_to = readlink $newfile
1074 0 2 if ($points_to ne $oldfile)
1082 2 2 if ($doit) { }
1084 0 2 unless symlink $oldfile, $newfile
1096 47 108 if (@args and ref $args[0] eq "HASH")
1100 0 155 if %options
1106 19 135 if ($? != 0)
1112 3 152 $info ? :
2 153 $quiet ? :
1123 0 2 if (@args and ref $args[0] eq "HASH")
1132 30 1 if (not -e $file) { }
1134 0 30 unless open my $fh, ">>", $file
1139 0 1 unless utime time, time, $file
1153 16 2 unless (-e $file)
1155 0 16 unless open my $fh, ">>", $file
1160 15 1 if (@commands) { }
1173 31 3 if (-e $file or -l $file)
1177 24 2 if (@files_to_remove) { }
1179 0 24 unless unlink @files_to_remove
1190 1 1 if (defined $ENV{$key}) { }
1206 1 9 unless (defined $atime)
1209 1 9 unless (defined $mtime)
1216 10 4 if (@s) { }
1217 10 0 if ($s[8] != $atime or $s[9] != $mtime)
1225 10 0 if (@files_to_change) { }
1229 3 7 if ($changed_files != @files_to_change)
1230 1 2 if (@files_to_change == 1) { }
1 1 elsif ($changed_files == 0) { }
1250 2 13 if (@args != 1)
1259 17 27 if (@args and ref $args[0] eq "HASH")
1261 1 43 exists $options{'atomic'} ? :
1262 1 43 if %options
1263 1 42 if (@args != 2)
1270 18 24 if (not -e $filename) { }
18 6 elsif (-s $filename != length $content) { }
1276 0 6 unless open my $fh, "<", $filename
1281 2 4 if ($file_content ne $content)
1287 38 4 if ($doit) { }
1293 37 1 $atomic ? :
1294 1 37 unless open my $ofh, ">", $outfile
1296 20 17 if (-e $filename)
1301 0 37 unless close $ofh
1303 36 1 if ($atomic)
1304 0 36 unless rename $outfile, $filename
1311 4 34 $quiet >= 2 ? :
1312 10 24 if ($quiet) { }
1313 3 7 if ($need_diff) { }
1319 14 10 if ($need_diff) { }
1336 3 44 if (@args and ref $args[0] eq "HASH")
1339 0 47 if ($check and ref $check ne "CODE")
1340 1 46 if %options
1342 1 45 if (@args < 1)
1347 2 43 unless (-e $file)
1350 2 41 unless (-f $file)
1357 26 20 if ($_->{'add_if_missing'})
1360 10 16 if (defined $_->{'add_after'} or defined $_->{'add_after_first'} or defined $_->{'add_before'} or defined $_->{'add_before_last'}) { }
1371 0 10 if ($defines != 1)
1377 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'}) { }
1400 4 2 $reverse ? :
1401 4 2 $reverse ? :
1402 4 2 $reverse ? :
1403 11 2 $reverse ? :
1404 5 7 if ($arrayref->[$i] =~ /$add/)
1405 3 2 if ($do_after) { }
1414 1 5 if (not $found)
1427 29 17 if ($_->{'unless_match'}) { }
16 1 elsif ($_->{'match'}) { }
1428 26 3 if (ref $_->{'unless_match'} ne "Regexp")
1432 1 28 unless ($_->{'action'})
1435 1 27 if (ref $_->{'action'} ne "CODE")
1440 3 13 if (ref $_->{'match'} ne "Regexp")
1444 3 13 $_->{'action'} ? :
7 9 defined $_->{'replace'} ? :
5 11 defined $_->{'delete'} ? :
1445 1 15 if ($consequences != 1)
1448 3 12 if ($_->{'action'}) { }
7 5 elsif (defined $_->{'replace'}) { }
5 0 elsif (defined $_->{'delete'}) { }
1449 1 2 if (ref $_->{'action'} ne "CODE")
1469 0 36 unless File::Copy::copy($file, $tmpfile)
1474 0 36 unless tie my @lines, "Tie::File", $tmpfile
1481 0 44 if ($debug)
1482 18 26 if ($lines[$line_i] =~ /$match/)
1483 9 9 if (exists $match_action->{'replace'}) { }
6 3 elsif (exists $match_action->{'delete'}) { }
1485 9 0 if ($lines[$line_i] ne $replace)
1491 5 1 if ($match_action->{'delete'})
1509 8 62 if ($line =~ /$match/)
1522 25 10 if ($no_of_changes)
1525 2 22 if ($check)
1529 0 1 unless &$check($tmpfile)
1532 0 23 unless rename $tmpfile, $file
1542 25 10 if ($no_of_changes) { }
1553 14 28 if (ref $file2)
1558 9 33 unless (@diff_cmd)
1560 0 9 if ($^O eq "MSWin32")
1564 9 0 if (Doit::Util::is_in_path($diff_candidate->[0]))
1569 0 0 !$diff_error_shown++ ? :
0 9 unless @diff_cmd
1574 0 42 if ($^O eq "MSWin32" and $diff_cmd[0] eq "fc")
1576 0 0 if ($file2 eq "-")
1582 42 0 if (not $cannot_use_dash and eval { do { require IPC::Run; 1 } }) { }
1583 0 42 unless (eval { do { IPC::Run::run([@diff_cmd, $file1, $file2], defined $stdin ? ("<", \$stdin) : (), ">", \$diff, "2>", \$diff_stderr); 1 } })
1584 14 28 defined $stdin ? :
1586 0 0 !$diff_error_shown++ ? :
1590 0 0 if ($^O eq 'MSWin32' or $cannot_use_dash) { }
1592 0 0 if ($file2 eq "-")
1605 0 0 if ($@)
1606 0 0 !$diff_error_shown++ ? :
1616 0 2 if $? != 0
1621 1 1 unless (symlink $oldfile, $newfile)
1622 1 0 if ($!{'EEXIST'}) { }
1626 0 1 unless symlink $oldfile, $tmpfile
1628 0 1 unless rename $tmpfile, $newfile
1637 0 53 if ($ENV{'DOIT__USE_LN_NSF_PERL'}) { }
1660 46 0 if (@commands)
1668 449 275 if (exists $command->{'msg'})
1671 690 34 if (exists $command->{'code'})
1673 400 214 if (exists $command->{'rv'}) { }
1686 18 4 if (exists $command->{'msg'})
1687 9 9 $command->{'run_always'} ? :
1689 21 1 if (exists $command->{'code'})
1691 9 12 if ($command->{'run_always'})
1694 12 9 if (exists $command->{'rv'}) { }
1712 0 54 if %options
1731 23 711 if ($self->{'dryrun'}) { }
1746 3 20 if ($component_or_module =~ /::/) { }
1753 2 8 if $_->{'module'} eq $module
1756 1 20 unless (eval " require $module; 1 ")
1759 0 20 unless my $o = $module->new
1776 4 16 if ($o->can("add_components"))
1807 2 8 if ($context eq 'a') { }
1812 2 8 if ($@) { }
1822 6 0 unless $sub =~ /::/
1829 7 0 unless $sub =~ /::/
1876 0 23 if (not defined $ret) { }
1 22 elsif (not $ret) { }
1882 0 22 unless read $fh, $buf, $length
1889 0 22 unless (defined $fh)
1900 0 0 unless defined $pid
1901 0 0 if (eval { do { require POSIX; defined &POSIX::WNOHANG } }) { }
1902 0 0 if ($self->{'debug'})
1912 0 0 if (time - $start_time >= 2)
1918 0 0 if (not $got_pid)
1922 0 0 if (not $done_POSIX_warning++)
1938 0 0 if %opts
1942 0 0 if $ret
1944 0 0 if ($fast_tries and eval { do { require Time::HiRes; 1 } }) { }
1949 0 0 $try <= $fast_tries && defined &Time::HiRes::sleep ? :
1950 0 0 if $retry_msg_code
1968 0 2 if %options
1981 0 0 defined $self->{'label'} ? :
1988 0 11 unless $self->{'outfh'}
1989 2 9 wantarray ? :
1992 2 9 if (defined $rettype and $rettype eq 'e') { }
9 0 elsif (defined $rettype and $rettype eq 'r') { }
1995 1 8 if ($ret[0] eq "bye-bye" and $do_exit)
1998 2 7 if ($context eq 'a') { }
2004 0 0 defined $rettype ? :
2011 0 0 if ($ret ne 'pong') { }
2029 0 0 if %options
2048 0 0 if ($self->{'debug'}) { }
2058 0 0 if (not $self->{'excl'} and -e $sockpath)
2062 0 0 unless my $sock = "IO::Socket::UNIX"->new("Type", SOCK_STREAM(), "Local", $sockpath, "Listen", 1)
2072 0 0 if $ready[0] != $sock
2079 0 0 if (not defined $context) { }
0 0 elsif ($data[0] eq 'exit') { }
0 0 elsif ($data[0] eq '__doit_rpc_ping') { }
2109 0 1 if %options
2111 0 1 unless $infh
2112 0 1 unless $outfh
2126 0 7 if (not defined $context) { }
1 6 elsif ($data[0] eq 'exit') { }
0 6 elsif ($data[0] eq '__doit_rpc_ping') { }
2135 0 6 unless open my $oldout, ">&STDOUT"
2139 0 6 unless open STDOUT, ">", "/dev/stderr"
2142 0 6 unless open STDOUT, ">&", $oldout
2164 0 0 if $^O eq "linux"
2181 0 0 unless (defined $realscript)
2182 0 0 if (defined $ENV{'DOIT_SCRIPT'}) { }
2192 0 0 if ($realscript ne '-e') { }
2219 0 0 unless delete $opts{'sudo_opts'}
2222 0 0 unless delete $opts{'components'}
2224 0 0 if %opts
2249 0 0 if ($? != 0)
2260 0 0 $class->_can_LANS ? :
2263 0 0 $debug ? :
0 0 $debug ? :
0 0 $LANS_PREFIX ? :
0 0 $dry_run ? :
2276 0 0 if (not defined $worker_pid) { }
0 0 elsif ($worker_pid == 0) { }
2279 0 0 if $debug
2288 0 0 $LANS_PREFIX ? :
2292 0 0 if $debug
2307 0 0 if %opts
2309 0 0 unless (-t STDIN)
2310 0 0 if ($debug)
2316 0 0 if (Doit::Util::is_in_path('stty')) { }
2318 0 0 if ($debug)
2322 0 0 if ($? == 0)
2330 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 } }) { }
2335 0 0 unless -t $fd
2337 0 0 if ($debug)
2368 0 0 if ($self->{'rpc'})
2369 0 0 if ($self->{'rpc'}{'outfh'})
2395 0 6 unless delete $opts{'components'}
2403 6 0 unless defined $dest_os
2405 1 5 unless $put_to_remote =~ /^(rsync_put|scp_put)$/
2409 1 4 if (defined $umask and not $umask =~ /^\d+$/)
2413 0 4 if %opts
2416 0 4 $forward_agent ? :
0 4 $tty ? :
2420 0 4 $forward_agent ? :
4 0 $master_opts ? :
2426 0 4 if (UNIVERSAL::isa($ssh_or_host, 'Net::OpenSSH')) { }
2434 4 0 if $ssh->error
2439 0 0 if (($bootstrap || '') eq "perl")
2446 0 0 if ($dest_os eq 'MSWin32') { }
2451 0 0 if ($debug)
2456 0 0 if ($FindBin::RealScript ne "-e")
2465 0 0 $dest_os ne 'MSWin32' ? :
2479 0 0 unless ($seen_dir{$target_dir})
2481 0 0 if ($dest_os eq 'MSWin32') { }
2498 0 0 $dest_os eq 'MSWin32' ? :
2505 0 0 if (defined $as)
2506 0 0 if ($as eq 'root') { }
2514 0 0 if ($dest_os eq 'MSWin32') { }
2515 0 0 $debug ? :
0 0 $dry_run ? :
2529 0 0 defined $umask ? :
0 0 $debug ? :
0 0 $dry_run ? :
2544 0 0 if $debug
2549 0 0 if ($dest_os eq 'MSWin32') { }
2565 0 0 if $debug
2578 0 4 if ($self->{'ssh'})
2579 0 0 if $self->{'ssh'}->can("disconnect")
2582 0 4 if ($self->{'rpc'})
2595 0 0 unless defined $peer
2597 0 0 if %options
2607 0 0 if ($debug) { }
2626 0 0 if $sock
2636 0 0 unless ($sock)
2645 0 0 unless read $infh, $length_buf, 4
2651 0 0 if $got == $length
2652 0 0 if $got > $length
2665 0 0 if eof $infh