lib/LEOCHARRE/Test.pm

filter: Statementstmt 50.0% 30 / 60 Branchbran 3.8% 1 / 26 Conditioncond 12.5% 2 / 16 MC/DCmcdc 0.0% 0 / 8 Subroutinesub 64.2% 9 / 14 Podpod 100% 7 / 7 totaltotal 37.4% 49 / 131 CC 19 SCAR 31.1
CC
19
Cov
32%
mysqld_running
56.0
_ok_mysqld_via_dbi
30.0
ok_mysqld
20.0
CRAP 22.5
↑ Summary
1 package LEOCHARRE::Test;
2 2 ▶eval { use lib './lib'; };
Subroutine BEGIN: called CC=1 SCAR=0.0
3 2 ▶use strict 'vars';
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use Test::Builder::Module;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 2 ▶use vars qw(@EXPORT @ISA $VERSION $PART_NUMBER $ABS_MYSQLD);
Subroutine BEGIN: called CC=1 SCAR=0.0
6 2 @EXPORT = qw(ok_part ok test_is_interactive ok_mysqld spacer mysqld_running mysqld_exists stderr_spacer);
7 2 $VERSION = sprintf "%d.%02d", q$Revision: 1.11 $ =~ /(\d+)/g;
8 2 @ISA = qw(Test::Builder::Module);
9 2 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 2 ▶$ABS_MYSQLD ||= '/etc/init.d/mysqld';
Condition50%1/2
$LEOCHARRE::Test::ABS_MYSQLD ||= "/etc/init.d/mysqld"
l!l
02
MC/DC0%0/1
$LEOCHARRE::Test::ABS_MYSQLD ||= "/etc/init.d/mysqld"
$LEOCHARRE::Test::ABS_MYSQLD
Truth table50%1/2
A
A= $LEOCHARRE::Test::ABS_MYSQLD
Aresult
11
00
12  
13 2 my $CLASS = __PACKAGE__;
14  
15 4 ▶sub ok ($;$) {
Subroutine ok: called CC=1 SCAR=0.0
Pod documented
16 4 $CLASS->builder->ok(@_);
17 }
18 2 ▶sub ok_part {
Subroutine ok_part: called CC=2 SCAR=7.0
Pod documented
19 2 my $msg = shift;
20 2 ▶ $msg ||='';
Condition50%1/2
$msg ||= ""
l!l
20
MC/DC0%0/1
$msg ||= ""
$msg
Truth table50%1/2
A
A= $msg
Aresult
11
00
21 2 my @arg= ('PART', $PART_NUMBER++, uc($msg));
22
23 2 carp("\n\n\n======================================\n@arg, ");
24 2 return 1;
25 }
26  
27 1 ▶sub stderr_spacer { print STDERR "\n\n" }
Subroutine stderr_spacer: called CC=1 SCAR=0.0
Pod documented
28  
29  
30 1 ▶sub test_is_interactive { -t STDIN && -t STDOUT }
Subroutine test_is_interactive: called CC=2 SCAR=7.6
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
-t STDIN and -t STDOUT 0 1 1
31  
32 0 ▶sub ok_mysqld {
Subroutine ok_mysqld: not called CC=4 SCAR=30.0
Pod documented
33  
34 0 ▶ my $host = $_[0] ||= 'localhost';
Condition0%0/2
$_[0] ||= "localhost"
l!l
00
MC/DC0%0/1
$_[0] ||= "localhost"
$_[0]
Truth table0%0/2
A
A= $_[0]
Aresult
11
00
35
36  
37 0 ▶ if ( $host eq 'localhost' and mysqld_exists() ){
Branch: 1 branch
BranchTrueFalseTotal
if ($host eq "localhost" and mysqld_exists()) 0 0 0
Condition0%0/3
$host eq "localhost" and mysqld_exists()
!ll&&!rl&&r
000
MC/DC0%0/2
$host eq "localhost" and mysqld_exists()
$host eq "localhost" mysqld_exists()
Truth table0%0/3
A and B
A= $host eq "localhost"B= mysqld_exists()
ABresult
0X0
100
111
38 0 return _ok_mysqld_via_daemon();
39 }
40  
41 0 return _ok_mysqld_via_dbi($host);
42 }
43  
44  
45 0 ▶sub _ok_mysqld_via_daemon {
Subroutine _ok_mysqld_via_daemon: not called CC=1 SCAR=6.9
46 0 ok( mysqld_running(), "mysqld running on host, $ABS_MYSQLD is running")
47 }
48  
49 0 ▶sub _ok_mysqld_via_dbi {
Subroutine _ok_mysqld_via_dbi: not called CC=5 SCAR=34.0
50  
51 0 ▶ my $host = $_[0] ||= 'localhost';
Condition0%0/2
$_[0] ||= "localhost"
l!l
00
MC/DC0%0/1
$_[0] ||= "localhost"
$_[0]
Truth table0%0/2
A
A= $_[0]
Aresult
11
00
52 0 require DBI;
53 0 require DBD::mysql;
54  
55 # make a bogus connect on purpose
56 0 my $user = 'a'.time().( int rand(20) );
57 0 my $pass = 'b'.time().( int rand(20) );
58 0 my $name = 'c'.time().( int rand(20) );
59  
60 0 my $h = "DBI:mysql:database=$name;host=$host";
61
62 0 my $dbh = DBI->connect($h, $user, $pass,{ RaiseError => 0, PrintError => 0});
63 0 my $err = $DBI::errstr;
64  
65 0 my $result;
66  
67 0 ▶ if($err=~/Unknown MySQL server host|Can\'t connect to local MySQL server/i){
Branch: 2 branches
BranchTrueFalseTotal
if ($err =~ /Unknown MySQL server host|Can\'t connect to local MySQL server/i) { } 0 0 0
elsif ($err =~ /Access denied for user/i) { } 0 0 0
68 0 $result = 0;;
69 }
70 elsif ( $err=~/Access denied for user/i ){
71 0 $result = 1;
72 }
73 else {
74 0 warn("dont know how to interpret this error: '$err'");
75 0 $result = 0;
76 }
77  
78 0 ▶ ok($result, "[$result] mysql host '$host' is up ? " . ($result ? 'yes' : "no.
Branch: 1 branch
BranchTrueFalseTotal
$result ? : 0 0 0
79 Check your /etc/init.d/mysqld status or equivalent."));
80 }
81  
82  
83 0 ▶sub mysqld_exists {
Subroutine mysqld_exists: not called CC=4 SCAR=30.0
Pod documented
84 0 ▶ my $path = ( $_[0] ? $_[0] : $ABS_MYSQLD ) or confess('missing ABS_MYSQLD or arg');
Branch: 2 branches
BranchTrueFalseTotal
my $path = $_[0] ? $_[0] : $LEOCHARRE::Test::ABS_MYSQLD or confess("missing ABS_MYSQLD or arg") 0 0 0
$_[0] ? : 0 0 0
85 0 ▶ -e $path ? $path : 0
Branch: 1 branch
BranchTrueFalseTotal
-e $path ? : 0 0 0
86 }
87  
88 0 ▶sub mysqld_running {
Subroutine mysqld_running: not called CC=7 SCAR=40.3
Pod documented
89 0 ▶ my $path = ( $_[0] ? $_[0] : $ABS_MYSQLD ) or confess('missing ABS_MYSQLD or arg');
Branch: 2 branches
BranchTrueFalseTotal
my $path = $_[0] ? $_[0] : $LEOCHARRE::Test::ABS_MYSQLD or confess("missing ABS_MYSQLD or arg") 0 0 0
$_[0] ? : 0 0 0
90
91 0 ▶ mysqld_exists($path) or warn("daemon does not exist on disk: $path\n") and return;
Branch: 1 branch
BranchTrueFalseTotal
mysqld_exists($path) or warn "daemon does not exist on disk: $path\n" and return 0 0 0
Condition0%0/5
mysqld_exists($path) || warn("daemon does not exist on disk: $path\n") && (return)
l!l&&r!l&&!r
000
warn "daemon does not exist on disk: $path\n" and return
!ll
00
MC/DC0%0/2
mysqld_exists($path) || warn("daemon does not exist on disk: $path\n") && (return)
mysqld_exists($path) warn "daemon does not exist on disk: $path\n"
Truth table0%0/3
A || B
A= mysqld_exists($path)B= warn "daemon does not exist on disk: $path\n"
ABresult
1X1
011
000
92 0 my $r = `$path status`;
93 0 ▶ $r=~/stopped/i and return 0;
Branch: 1 branch
BranchTrueFalseTotal
$r =~ /stopped/i and return 0 0 0 0
94 0 ▶ $r=~/running/i and return 1;
Branch: 1 branch
BranchTrueFalseTotal
$r =~ /running/i and return 1 0 0 0
95 0 warn("dunno $path status '$r'");
96 0 return;
97 }
98  
99  
100  
101  
102 2 1;
103  
104  
105 __END__
↑ Summary