blib/lib/DBIO/SQLite/Test/Conformance.pm

filter: Statementstmt 96.5% 84 / 87 Branchbran 76.1% 32 / 42 Conditioncond 63.6% 7 / 11 MC/DCmcdc 60.0% 3 / 5 Subroutinesub 100% 19 / 19 Podpod 100% 10 / 10 totaltotal 89.0% 155 / 174 CC 27 SCAR 26.3
CC
27
Cov
88%
conformance_fact
25.7
__ANON__
3.0
conformance_live_available
2.0
CRAP 13.9
« blib/lib/DBIO/SQLite/Storage.pm ↑ Summary blib/lib/DBIO/SQLite/Introspect/Columns.pm »
1 package DBIO::SQLite::Test::Conformance;
2 # ABSTRACT: Answers the shared conformance case table for the SQLite driver
3  
4 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 2 our $VERSION = '0.900007';
8  
9 2 ▶use base 'DBIO::Test::Conformance';
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 2 ▶use DBIO::Exception ();
Subroutine BEGIN: called CC=1 SCAR=0.0
12 2 ▶use DBIO::SQLite::Introspect ();
Subroutine BEGIN: called CC=1 SCAR=0.0
13 2 ▶use DBIO::SQLite::Deploy ();
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15  
16  
17 3 ▶sub conformance_live_available {
Subroutine conformance_live_available: called CC=2 SCAR=7.1
Pod documented
18 3 ▶ return eval { require DBD::SQLite; 1 } ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
eval { do { require DBD::SQLite; 1 } } ? : 3 0 3
19 }
20  
21  
22 53 ▶sub conformance_connect {
Subroutine conformance_connect: called CC=1 SCAR=0.0
Pod documented
23 53 my ($class, $schema_class) = @_;
24 53 $schema_class->load_components('SQLite');
25 53 return $schema_class->connect('dbi:SQLite::memory:', '', '', {
26 AutoCommit => 1, RaiseError => 1, PrintError => 0,
27 on_connect_call => 'use_foreign_keys',
28 sqlite_unicode => 1,
29 });
30 }
31  
32  
33 53 ▶sub conformance_install {
Subroutine conformance_install: called CC=1 SCAR=0.0
Pod documented
34 53 my ($class, $schema, $case) = @_;
35 53 $schema->deploy;
36 52 return;
37 }
38  
39  
40 53 ▶sub conformance_cleanup {
Subroutine conformance_cleanup: called CC=1 SCAR=0.0
Pod documented
41 53 my ($class, $schema, $case, $namespace) = @_;
42 53 $schema->storage->disconnect;
43 53 return;
44 }
45  
46  
47 39 ▶sub conformance_diff_is_empty {
Subroutine conformance_diff_is_empty: called CC=2 SCAR=7.1
Pod documented
48 39 my ($class, $schema, $case) = @_;
49 39 my $diff = DBIO::SQLite::Deploy->new(schema => $schema)->diff;
50 39 ▶ return $diff->has_changes ? 0 : 1;
Branch: 1 branch
BranchTrueFalseTotal
$diff->has_changes ? : 0 39 39
51 }
52  
53  
54 23 ▶sub _conformance_target {
Subroutine _conformance_target: called CC=1 SCAR=0.0
55 23 my ($class, $schema, $to_class) = @_;
56 23 my $dbh = $schema->storage->dbh;
57 23 $to_class->load_components('SQLite');
58 23 ▶ return $to_class->connect(sub { $dbh }, {
Subroutine __ANON__: called CC=1 SCAR=0.0
59 23 AutoCommit => 1, RaiseError => 1, PrintError => 0,
60 on_connect_call => 'use_foreign_keys',
61 });
62 }
63  
64 20 ▶sub conformance_upgrade {
Subroutine conformance_upgrade: called CC=1 SCAR=0.0
Pod documented
65 20 my ($class, $schema, $to_class, $case) = @_;
66 20 my $to = $class->_conformance_target($schema, $to_class);
67 20 DBIO::SQLite::Deploy->new(schema => $to)->upgrade(allow_destructive => 1);
68 18 return $to;
69 }
70  
71  
72 3 ▶sub conformance_deploy {
Subroutine conformance_deploy: called CC=1 SCAR=0.0
Pod documented
73 3 my ($class, $schema, $to_class, $case) = @_;
74 3 return DBIO::SQLite::Deploy->new(
75 schema => $class->_conformance_target($schema, $to_class),
76 );
77 }
78  
79  
80 6 ▶sub conformance_answered_through { { DDL => 2, Diff => 4, Bind => 1 } }
Subroutine conformance_answered_through: called CC=1 SCAR=0.0
Pod documented
81  
82  
83 7 ▶sub conformance_refusals {
Subroutine conformance_refusals: called CC=1 SCAR=0.0
Pod documented
84 # The value the NUMERIC column holds, as this perl writes it: its NV and its
85 # C runtime decide the text (1.23456789012346e+15 for a double on one,
86 # 1234567890123456.75 for a wider NV on another).
87 7 my $real = unpack 'd', pack 'd', '1234567890123456.7890';
88  
89 return {
90 7 'diff-column-added-not-null-populated' => {
91 kind => 'server',
92 reason => qr/NOT NULL without a default, and table base holds rows/,
93 },
94 'diff-not-null-over-nulls' => {
95 kind => 'server',
96 reason => qr/holds rows where it is NULL/,
97 },
98 'bind-empty-string' => {
99 kind => 'deviation',
100 fact => qr/the server accepted a row it must reject/,
101 reason => 'an INTEGER-affinity column keeps text that is not a '
102 . 'well-formed integer as text, so SQLite stores the empty '
103 . 'string in it (https://www.sqlite.org/datatype3.html, '
104 . 'section 3); only a STRICT table rejects it',
105 },
106 'bind-numeric-exact' => {
107 kind => 'deviation',
108 fact => qr/read back '-?\Q$real\E'/,
109 reason => 'NUMERIC affinity turns a text that is no 64-bit integer '
110 . 'into a REAL, and of a REAL only the first 15 significant '
111 . 'digits are preserved (https://www.sqlite.org/datatype3.html, '
112 . 'section 3.1); SQLite has no exact decimal type',
113 },
114 'ddl-type-size-char' => {
115 kind => 'deviation',
116 fact => qr/Sized: the server accepted a row it must reject/,
117 reason => 'SQLite does not enforce the length of a CHARACTER(n) column: '
118 . 'the declared size is kept for introspection, the value is '
119 . 'stored whole (https://www.sqlite.org/datatype3.html, '
120 . 'section 3.1); the driver adds no CHECK for it',
121 },
122 'ddl-qualified-source-name' => {
123 kind => 'server',
124 reason => qr/no schemas to qualify a name with/,
125 },
126 };
127 }
128  
129  
130 51 ▶sub conformance_fact {
Subroutine conformance_fact: called CC=23 SCAR=32.5
Pod documented
131 51 my ($class, $schema, $name, $args) = @_;
132 51 my $intro = DBIO::SQLite::Introspect->new(dbh => $schema->storage->dbh);
133 51 my $model = $intro->model;
134 51 my $table = $args->{table};
135 51 ▶ my $has = exists $model->{tables}{$table} ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
exists $model->{'tables'}{$table} ? : 46 5 51
136 51 ▶ my @cols = @{ $args->{columns} || [] };
Condition100%2/2
$args->{'columns'} || []
l!l
942
MC/DC100%1/1
$args->{'columns'} || []
$args->{'columns'}
Truth table100%2/2
A
A= $args->{'columns'}
Aresult
11
00
137 10 ▶ my $same = sub {
Subroutine __ANON__: called CC=3 SCAR=11.0
138 10 my ($got) = @_;
139 10 ▶ return 0 unless @$got == @cols;
Branch: 1 branch
BranchTrueFalseTotal
unless @$got == @cols 2 8 10
140 8 ▶ return (join("\0", @$got) eq join("\0", @cols)) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
join("\000", @$got) eq join("\000", @cols) ? : 7 1 8
141 51 };
142  
143 51 ▶ if ($name eq 'object_kind') {
Branch: 1 branch
BranchTrueFalseTotal
if ($name eq "object_kind") 15 36 51
144 15 ▶ return $has ? $model->{tables}{$table}{kind} : undef;
Branch: 1 branch
BranchTrueFalseTotal
$has ? : 10 5 15
145 }
146 36 ▶ if ($name eq 'table_name') {
Branch: 1 branch
BranchTrueFalseTotal
if ($name eq "table_name") 2 34 36
147 2 ▶ return $has ? $table : undef;
Branch: 1 branch
BranchTrueFalseTotal
$has ? : 2 0 2
148 }
149 34 ▶ if ($name eq 'table_in_namespace') {
Branch: 1 branch
BranchTrueFalseTotal
if ($name eq "table_in_namespace") 0 34 34
150 0 ▶ return 0 unless ($args->{namespace} // '') eq 'main';
Branch: 1 branch
BranchTrueFalseTotal
unless ($args->{"namespace"} // "") eq "main" 0 0 0
Condition0%0/2
$args->{"namespace"} // ""
l!l
00
MC/DC0%0/1
$args->{"namespace"} // ""
$args->{"namespace"}
Truth table0%0/2
A
A= $args->{"namespace"}
Aresult
11
00
151 0 ▶ return exists $model->{tables}{ $args->{unqualified} } ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
exists $model->{'tables'}{$args->{'unqualified'}} ? : 0 0 0
152 }
153 34 ▶ if ($name eq 'column_names') {
Branch: 1 branch
BranchTrueFalseTotal
if ($name eq "column_names") 11 23 34
154 11 return $intro->table_columns($table);
155 }
156 23 ▶ if ($name eq 'column_size') {
Branch: 1 branch
BranchTrueFalseTotal
if ($name eq "column_size") 3 20 23
157 3 return $intro->table_columns_info($table)->{ $args->{column} }{size};
158 }
159 20 ▶ if ($name eq 'column_auto_increment') {
Branch: 1 branch
BranchTrueFalseTotal
if ($name eq "column_auto_increment") 2 18 20
160 2 ▶ return $intro->table_columns_info($table)->{ $args->{column} }{is_auto_increment} ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$intro->table_columns_info($table)->{$args->{'column'}}{'is_auto_increment'} ? : 2 0 2
161 }
162 18 ▶ if ($name eq 'primary_key_columns') {
Branch: 1 branch
BranchTrueFalseTotal
if ($name eq "primary_key_columns") 3 15 18
163 3 return $intro->table_pk_info($table);
164 }
165 15 ▶ if ($name eq 'unique_exists') {
Branch: 1 branch
BranchTrueFalseTotal
if ($name eq "unique_exists") 5 10 15
166 5 ▶ return (grep { $same->($_->[1]) } @{ $intro->table_uniq_info($table) }) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
grep({&$same($_->[1]);} @{$intro->table_uniq_info($table);}) ? : 4 1 5
167 }
168 10 ▶ if ($name eq 'foreign_key_count') {
Branch: 1 branch
BranchTrueFalseTotal
if ($name eq "foreign_key_count") 6 4 10
169 6 return scalar @{ $intro->table_fk_info($table) };
170 }
171 4 ▶ if ($name eq 'index_count') {
Branch: 1 branch
BranchTrueFalseTotal
if ($name eq "index_count") 4 0 4
172 4 ▶ my $indexes = $model->{indexes}{$table} || {};
Condition100%2/2
$model->{'indexes'}{$table} || {}
l!l
31
MC/DC100%1/1
$model->{'indexes'}{$table} || {}
$model->{'indexes'}{$table}
Truth table100%2/2
A
A= $model->{'indexes'}{$table}
Aresult
11
00
173 return scalar grep {
174 4 ($_->{origin} || '') ne 'pk' and $same->($_->{columns})
175 6 ▶ } values %$indexes;
Condition60%3/5
($_->{'origin'} || '') ne 'pk' && &$same($_->{'columns'})
!ll&&!rl&&r
033
$_->{'origin'} || ''
l!l
60
MC/DC50%1/2
($_->{'origin'} || '') ne 'pk' && &$same($_->{'columns'})
$_->{'origin'} &$same($_->{'columns'})
Truth table66%2/3
A && B
A= $_->{'origin'}B= &$same($_->{'columns'})
ABresult
0X0
100
111
176 }
177  
178 0 DBIO::Exception->throw("unknown conformance fact '$name'");
179 }
180  
181 2 1;
182  
183 __END__
« blib/lib/DBIO/SQLite/Storage.pm ↑ Summary blib/lib/DBIO/SQLite/Introspect/Columns.pm »