DBomb/Test/Util.pm

filter: Statementstmt 28.0% 14 / 50 Branchbran 0.0% 0 / 30 Conditioncond 0.0% 0 / 9 MC/DCmcdc 0.0% 0 / 6 Subroutinesub 37.5% 3 / 8 Podpod 0.0% 0 / 5 totaltotal 15.7% 17 / 108 CC 21 SCAR 47.3
CC
21
Cov
16%
same_list
182.0
same_results
90.0
count_table
2.0
CRAP 113.8
« DBomb/Meta/ColumnInfo.pm ↑ Summary DBomb/Query/Insert.pm »
1 package DBomb::Test::Util;
2  
3 =head1 NAME
4  
5 DBomb::Test::Util - THIS PACKAGE SHOULD NOT BE INSTALLED.
6  
7 =head1 DESCRIPTION
8  
9 This is a helper package for the "make test" part of the DBomb::* distribution.
10 It should not be installed. If it is installed, then report it as a bug, please.
11  
12 =cut
13  
14 10 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 10 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 10 our $VERSION = '$Revision: 1.3 $';
17  
18 10 ▶use base qw(Exporter);
Subroutine BEGIN: called CC=1 SCAR=0.0
19  
20 10 our %EXPORT_TAGS = ( all => [qw{same_results same_list count_table truncate_table drop_table}] );
21 10 Exporter::export_ok_tags('all');
22  
23 ## Be sure to set the DBH from outside this package.
24 10 our $dbh;
25  
26 ## Compares two sql statemtns, or two query objects or a query object and sql statement
27 0 ▶sub same_results {
Subroutine same_results: not called CC=9 SCAR=45.0
Pod undocumented
28 0 my $dbh = shift;
29 0 ▶ my @sql = map { UNIVERSAL::isa($_,'DBomb::Query')? scalar($_->sql) : $_->[0] } @_;
Branch: 1 branch
BranchTrueFalseTotal
UNIVERSAL::isa($_, 'DBomb::Query') ? : 0 0 0
30 0 my $msg = "SQL: " . $sql[0]
31 . "\nSAME: " . $sql[1];
32  
33 0 eval {
34 0 my @results;
35 0 for (@_){
36 0 ▶ if (UNIVERSAL::isa($_,'DBomb::Query')){
Branch: 1 branch
BranchTrueFalseTotal
if (UNIVERSAL::isa($_, 'DBomb::Query')) { } 0 0 0
37 0 push @results, $_->selectall_arrayref;
38 }
39 else{
40 0 my($sql,@bind_values) = @$_;
41 0 ▶ my $sth = $dbh->prepare($sql) or die $DBI::errstr;
Branch: 1 branch
BranchTrueFalseTotal
my $sth = $dbh->prepare($sql) or die $DBI::errstr 0 0 0
42 0 ▶ $sth->execute(@bind_values) or die $DBI::errstr;
Branch: 1 branch
BranchTrueFalseTotal
$sth->execute(@bind_values) or die $DBI::errstr 0 0 0
43 0 push @results, $sth->fetchall_arrayref;
44 }
45 }
46 0 ▶ die "Results are not the same." unless same_list(@results);
Branch: 1 branch
BranchTrueFalseTotal
unless same_list(@results) 0 0 0
47 };
48 0 ▶ if ($@){
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
49 0 ▶ print STDERR "$msg\n$@" if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 0 0
50 0 return 0;
51 }
52  
53 0 return 1;
54 }
55  
56 ## compares two lists for identical values.
57 0 ▶sub same_list {
Subroutine same_list: not called CC=13 SCAR=52.0
Pod undocumented
58 0 my($a,$b) = @_;
59 0 ▶ return 0 unless defined($a) && defined($b);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $a and defined $b 0 0 0
Condition0%0/3
defined $a and defined $b
!ll&&!rl&&r
000
MC/DC0%0/2
defined $a and defined $b
defined $a defined $b
Truth table0%0/3
A and B
A= defined $aB= defined $b
ABresult
0X0
100
111
60 0 ▶ return 0 unless ref($a) eq 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $a eq "ARRAY" 0 0 0
61 0 ▶ return 0 unless ref($b) eq 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $b eq "ARRAY" 0 0 0
62 0 ▶ return 0 unless @$a == @$b;
Branch: 1 branch
BranchTrueFalseTotal
unless @$a == @$b 0 0 0
63  
64 0 for my $i (0..$#$a){
65 0 my($x,$y) = ($a->[$i], $b->[$i]);
66 0 ▶ next if ((not defined $x) && (not defined $y));
Branch: 1 branch
BranchTrueFalseTotal
unless defined $x or defined $y 0 0 0
Condition0%0/3
defined $x or defined $y
l!l&&r!l&&!r
000
MC/DC0%0/2
defined $x or defined $y
defined $x defined $y
Truth table0%0/3
A or B
A= defined $xB= defined $y
ABresult
1X1
011
000
67 0 ▶ if(ref($x) eq 'ARRAY' && ref($y) eq 'ARRAY'){
Branch: 1 branch
BranchTrueFalseTotal
if (ref $x eq "ARRAY" and ref $y eq "ARRAY") 0 0 0
Condition0%0/3
ref $x eq "ARRAY" and ref $y eq "ARRAY"
!ll&&!rl&&r
000
MC/DC0%0/2
ref $x eq "ARRAY" and ref $y eq "ARRAY"
ref $x eq "ARRAY" ref $y eq "ARRAY"
Truth table0%0/3
A and B
A= ref $x eq "ARRAY"B= ref $y eq "ARRAY"
ABresult
0X0
100
111
68 0 ▶ return 0 unless same_list($x,$y);
Branch: 1 branch
BranchTrueFalseTotal
unless same_list($x, $y) 0 0 0
69 0 next;
70 }
71 0 ▶ return 0 unless $a->[$i] eq $b->[$i];
Branch: 1 branch
BranchTrueFalseTotal
unless $a->[$i] eq $b->[$i] 0 0 0
72 }
73 0 return 1;
74 }
75  
76 sub count_table
77 0 ▶{
Subroutine count_table: not called CC=1 SCAR=6.9
Pod undocumented
78 0 $dbh->selectcol_arrayref("SELECT COUNT(*) FROM $_[0]")->[0]
79 }
80  
81  
82 sub truncate_table
83 0 ▶{
Subroutine truncate_table: not called CC=1 SCAR=6.9
Pod undocumented
84 0 $dbh->do("DELETE FROM $_[0]");
85 }
86  
87 sub drop_table
88 0 ▶{
Subroutine drop_table: not called CC=1 SCAR=6.9
Pod undocumented
89 0 local $dbh->{RaiseError};
90 0 local $dbh->{PrintError};
91 0 $dbh->do("DROP TABLE $_[0]")
92 }
93  
94 10 1;
95 __END__
« DBomb/Meta/ColumnInfo.pm ↑ Summary DBomb/Query/Insert.pm »