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

filter: Statementstmt 20.5% 24 / 117 Branchbran 0.0% 0 / 50 Conditioncond 0.0% 0 / 9 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 31.8% 7 / 22 Podpod 100% 12 / 12 totaltotal 20.0% 43 / 214 CC 30 SCAR 52.7
CC
30
Cov
14%
conformance_fact
462.0
conformance_apply_name
23.8
__ANON__
12.0
CRAP 194.5
« blib/lib/DBIO/DuckDB/DDL.pm ↑ Summary blib/lib/DBIO/DuckDB/Introspect/Columns.pm »
1 package DBIO::DuckDB::Test::Conformance;
2 # ABSTRACT: Answers the shared conformance case table for the DuckDB driver
3  
4 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 1 our $VERSION = '0.900007';
8  
9 1 my $Name_schema_serial = 0;
10  
11 1 ▶use base 'DBIO::Test::Conformance';
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 1 ▶use DBIO::Exception ();
Subroutine BEGIN: called CC=1 SCAR=0.0
14 1 ▶use DBIO::DuckDB::Introspect ();
Subroutine BEGIN: called CC=1 SCAR=0.0
15 1 ▶use DBIO::DuckDB::Deploy ();
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17  
18  
19 0 ▶sub conformance_live_available {
Subroutine conformance_live_available: not called CC=2 SCAR=17.9
Pod documented
20 0 ▶ return eval { require DBD::DuckDB; 1 } ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
eval { do { require DBD::DuckDB; 1 } } ? : 0 0 0
21 }
22  
23  
24 0 ▶sub conformance_connect {
Subroutine conformance_connect: not called CC=1 SCAR=6.9
Pod documented
25 0 my ($class, $schema_class) = @_;
26 0 $schema_class->load_components('DuckDB');
27 0 return $schema_class->connect('dbi:DuckDB:dbname=:memory:', '', '', {
28 AutoCommit => 1, RaiseError => 1, PrintError => 0,
29 });
30 }
31  
32  
33 0 ▶sub conformance_install {
Subroutine conformance_install: not called CC=1 SCAR=6.9
Pod documented
34 0 my ($class, $schema, $case) = @_;
35 0 $schema->deploy;
36 0 return;
37 }
38  
39  
40 0 ▶sub conformance_cleanup {
Subroutine conformance_cleanup: not called CC=2 SCAR=17.9
Pod documented
41 0 my ($class, $schema, $case, $namespace) = @_;
42 # the schema an upgrade returns shares the handle of the one it started
43 # from, which the runner closes last; DBD::DuckDB 0.16 ends the process on
44 # a second disconnect of one handle
45 0 ▶ return if $schema->storage->{_conformance_shared_handle};
Branch: 1 branch
BranchTrueFalseTotal
if $schema->storage->{"_conformance_shared_handle"} 0 0 0
46 0 $schema->storage->disconnect;
47 0 return;
48 }
49  
50  
51 0 ▶sub conformance_diff_is_empty {
Subroutine conformance_diff_is_empty: not called CC=2 SCAR=17.9
Pod documented
52 0 my ($class, $schema, $case) = @_;
53 0 my $diff = DBIO::DuckDB::Deploy->new(schema => $schema)->diff;
54 0 ▶ return $diff->has_changes ? 0 : 1;
Branch: 1 branch
BranchTrueFalseTotal
$diff->has_changes ? : 0 0 0
55 }
56  
57  
58 0 ▶sub conformance_upgrade {
Subroutine conformance_upgrade: not called CC=1 SCAR=6.9
Pod documented
59 0 my ($class, $schema, $to_class, $case) = @_;
60 0 my $to = $class->_connect_target($schema, $to_class);
61 0 DBIO::DuckDB::Deploy->new(schema => $to)->upgrade(allow_destructive => 1);
62 0 return $to;
63 }
64  
65  
66 0 ▶sub conformance_deploy {
Subroutine conformance_deploy: not called CC=1 SCAR=6.9
Pod documented
67 0 my ($class, $schema, $to_class, $case) = @_;
68 0 return DBIO::DuckDB::Deploy->new(schema => $class->_connect_target($schema, $to_class));
69 }
70  
71 0 ▶sub _connect_target {
Subroutine _connect_target: not called CC=1 SCAR=6.9
72 0 my ($class, $schema, $to_class) = @_;
73 0 my $dbh = $schema->storage->dbh;
74 0 $to_class->load_components('DuckDB');
75 0 ▶ my $to = $to_class->connect(sub { $dbh }, {
Subroutine __ANON__: not called CC=1 SCAR=6.9
76 0 AutoCommit => 1, RaiseError => 1, PrintError => 0,
77 });
78 0 $to->storage->{_conformance_shared_handle} = 1;
79 0 return $to;
80 }
81  
82  
83 0 ▶sub conformance_name_kinds { { extension => 1, library => 1 } }
Subroutine conformance_name_kinds: not called CC=1 SCAR=6.9
Pod documented
84  
85  
86 0 ▶sub conformance_apply_name {
Subroutine conformance_apply_name: not called CC=5 SCAR=31.7
Pod documented
87 0 my ($class, $kind, $name) = @_;
88  
89 0 my $schema_class = 'DBIO::DuckDB::Test::Conformance::NameSchema'
90 . (++$Name_schema_serial);
91 {
92 0 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.2
93 0 @{"${schema_class}::ISA"} = ('DBIO::Schema');
94 }
95 0 my $schema = $class->conformance_connect($schema_class);
96 0 my @sql = eval {
97 0 my $storage = $schema->storage;
98 0 my $activation;
99 0 ▶ if ($kind eq 'extension') {
Branch: 1 branch
BranchTrueFalseTotal
if ($kind eq 'extension') { } 0 0 0
100 0 $schema_class->duckdb_extensions($name);
101 0 $activation = $storage->_extension_activation(undef);
102 }
103 else {
104 0 $activation = { load => [ $name ], search_path => [] };
105 }
106 0 $storage->_extension_activation_sql($activation);
107 };
108 0 my $err = $@;
109 0 eval { $schema->storage->disconnect };
110 0 ▶ die $err if $err;
Branch: 1 branch
BranchTrueFalseTotal
if $err 0 0 0
111  
112 0 ▶ my ($shown) = map { /\ALOAD (\S+)\z/ ? $1 : () } @sql;
Branch: 1 branch
BranchTrueFalseTotal
/\ALOAD (\S+)\z/ ? : 0 0 0
113 0 ▶ DBIO::Exception->throw("conformance: no LOAD statement for the $kind name")
Branch: 1 branch
BranchTrueFalseTotal
unless defined $shown 0 0 0
114 unless defined $shown;
115 0 return $shown;
116 }
117  
118  
119 0 ▶sub conformance_answered_through { { DDL => 2, Diff => 4, Bind => 1 } }
Subroutine conformance_answered_through: not called CC=1 SCAR=6.9
Pod documented
120  
121  
122 0 ▶sub conformance_refusals {
Subroutine conformance_refusals: not called CC=1 SCAR=6.9
Pod documented
123 return {
124 0 'ddl-type-size-char' => {
125 kind => 'deviation',
126 fact => qr/Sized: the server accepted a row it must reject/,
127 reason => 'DuckDB parses the length of VARCHAR(n) and ignores it: the '
128 . 'value is stored whole, never truncated, and the column reads '
129 . 'back as VARCHAR without a length '
130 . '(https://duckdb.org/docs/stable/sql/data_types/text); the '
131 . 'driver adds no CHECK for it',
132 },
133 'diff-column-added-not-null-populated' => {
134 kind => 'server',
135 reason => qr/NOT NULL without a default, and table base holds rows/,
136 },
137 'diff-not-null-over-nulls' => {
138 kind => 'server',
139 reason => qr/holds rows where it is NULL/,
140 },
141 'diff-column-type-change' => {
142 kind => 'deviation',
143 fact => qr/column_size of Num\.n: expected '20', the server shows NULL/,
144 reason => 'DuckDB parses the length of VARCHAR(n) and ignores it, so '
145 . 'the column reads back as VARCHAR without a length '
146 . '(https://duckdb.org/docs/stable/sql/data_types/text); the '
147 . 'type change itself and the rows are right',
148 },
149 'ddl-fk-actions' => {
150 kind => 'server',
151 reason => qr/ON DELETE CASCADE is not available/,
152 },
153 'diff-table-added-complete' => {
154 kind => 'server',
155 reason => qr/ON DELETE CASCADE is not available/,
156 },
157 'diff-fk-action-changed' => {
158 kind => 'server',
159 reason => qr/ON DELETE CASCADE is not available/,
160 },
161 'ddl-type-size-bit' => {
162 kind => 'deviation',
163 fact => qr/column_size of Sized\.b: expected '8', the server shows NULL/,
164 reason => 'BIT is a variable-length bitstring in DuckDB; a declared '
165 . 'width is parsed and not kept, so the column reads back '
166 . 'without a size '
167 . '(https://duckdb.org/docs/stable/sql/data_types/bitstring)',
168 },
169 };
170 }
171  
172  
173 0 ▶sub conformance_fact {
Subroutine conformance_fact: not called CC=21 SCAR=61.4
Pod documented
174 0 my ($class, $schema, $name, $args) = @_;
175 0 my $dbh = $schema->storage->dbh;
176 0 my $intro = DBIO::DuckDB::Introspect->new(dbh => $dbh);
177 0 my $model = $intro->model;
178 0 my $table = $args->{table};
179 0 ▶ my $has = exists $model->{tables}{$table} ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
exists $model->{'tables'}{$table} ? : 0 0 0
180 0 ▶ my @cols = @{ $args->{columns} || [] };
Condition0%0/2
$args->{'columns'} || []
l!l
00
MC/DC0%0/1
$args->{'columns'} || []
$args->{'columns'}
Truth table0%0/2
A
A= $args->{'columns'}
Aresult
11
00
181 0 ▶ my $same = sub {
Subroutine __ANON__: not called CC=3 SCAR=24.8
182 0 my ($got) = @_;
183 0 ▶ return 0 unless @$got == @cols;
Branch: 1 branch
BranchTrueFalseTotal
unless @$got == @cols 0 0 0
184 0 ▶ return (join("\0", @$got) eq join("\0", @cols)) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
join("\000", @$got) eq join("\000", @cols) ? : 0 0 0
185 0 };
186  
187 0 ▶ if ($name eq 'object_kind') {
Branch: 1 branch
BranchTrueFalseTotal
if ($name eq "object_kind") 0 0 0
188 0 ▶ return $has ? $model->{tables}{$table}{kind} : undef;
Branch: 1 branch
BranchTrueFalseTotal
$has ? : 0 0 0
189 }
190 0 ▶ if ($name eq 'table_name') {
Branch: 1 branch
BranchTrueFalseTotal
if ($name eq "table_name") 0 0 0
191 0 ▶ return $has ? $table : undef;
Branch: 1 branch
BranchTrueFalseTotal
$has ? : 0 0 0
192 }
193 0 ▶ if ($name eq 'table_in_namespace') {
Branch: 1 branch
BranchTrueFalseTotal
if ($name eq "table_in_namespace") 0 0 0
194 my ($n) = $dbh->selectrow_array(
195 'SELECT count(*) FROM information_schema.tables '
196 . 'WHERE table_schema = ? AND table_name = ?',
197 undef, $args->{namespace}, $args->{unqualified},
198 0 );
199 0 ▶ return $n ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$n ? : 0 0 0
200 }
201 0 ▶ if ($name eq 'column_names') {
Branch: 1 branch
BranchTrueFalseTotal
if ($name eq "column_names") 0 0 0
202 0 return $intro->table_columns($table);
203 }
204 0 ▶ if ($name eq 'column_size') {
Branch: 1 branch
BranchTrueFalseTotal
if ($name eq "column_size") 0 0 0
205 0 return $intro->table_columns_info($table)->{ $args->{column} }{size};
206 }
207 0 ▶ if ($name eq 'column_auto_increment') {
Branch: 1 branch
BranchTrueFalseTotal
if ($name eq "column_auto_increment") 0 0 0
208 0 ▶ 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'} ? : 0 0 0
209 }
210 0 ▶ if ($name eq 'primary_key_columns') {
Branch: 1 branch
BranchTrueFalseTotal
if ($name eq "primary_key_columns") 0 0 0
211 0 return $intro->table_pk_info($table);
212 }
213 0 ▶ if ($name eq 'unique_exists') {
Branch: 1 branch
BranchTrueFalseTotal
if ($name eq "unique_exists") 0 0 0
214 0 ▶ return (grep { $same->($_->[1]) } @{ $intro->table_uniq_info($table) }) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
grep({&$same($_->[1]);} @{$intro->table_uniq_info($table);}) ? : 0 0 0
215 }
216 0 ▶ if ($name eq 'foreign_key_count') {
Branch: 1 branch
BranchTrueFalseTotal
if ($name eq "foreign_key_count") 0 0 0
217 0 return scalar @{ $intro->table_fk_info($table) };
218 }
219 0 ▶ if ($name eq 'index_count') {
Branch: 1 branch
BranchTrueFalseTotal
if ($name eq "index_count") 0 0 0
220 0 ▶ my $indexes = $model->{indexes}{$table} || {};
Condition0%0/2
$model->{'indexes'}{$table} || {}
l!l
00
MC/DC0%0/1
$model->{'indexes'}{$table} || {}
$model->{'indexes'}{$table}
Truth table0%0/2
A
A= $model->{'indexes'}{$table}
Aresult
11
00
221 return scalar grep {
222 0 ($_->{origin} || '') ne 'pk' and $same->($_->{columns})
223 0 ▶ } values %$indexes;
Condition0%0/5
($_->{'origin'} || '') ne 'pk' && &$same($_->{'columns'})
!ll&&!rl&&r
000
$_->{'origin'} || ''
l!l
00
MC/DC0%0/2
($_->{'origin'} || '') ne 'pk' && &$same($_->{'columns'})
$_->{'origin'} &$same($_->{'columns'})
Truth table0%0/3
A && B
A= $_->{'origin'}B= &$same($_->{'columns'})
ABresult
0X0
100
111
224 }
225  
226 0 DBIO::Exception->throw("unknown conformance fact '$name'");
227 }
228  
229 1 1;
230  
231 __END__
« blib/lib/DBIO/DuckDB/DDL.pm ↑ Summary blib/lib/DBIO/DuckDB/Introspect/Columns.pm »