DuckDB/Test.pm

filter: Statementstmt 70.7% 29 / 41 Branchbran 25.0% 2 / 8 Conditioncond 0.0% 0 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 100% 9 / 9 Podpod 100% 1 / 1 totaltotal 66.1% 41 / 62 CC 8 SCAR 21.3
CC
8
Cov
61%
import
19.1
_database
4.1
BEGIN
1.0
CRAP 8.4
« DuckDB/Storage.pm ↑ Summary DuckDB/Introspect.pm »
1 package DBIO::DuckDB::Test;
2 # ABSTRACT: DuckDB-specific test utilities for DBIO
3  
4 8 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 8 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 8 ▶use DBIO::Test;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 8 ▶use DBIO::Test::Schema;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 8 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11  
12 8 ▶sub import {
Subroutine import: called CC=6 SCAR=29.5
13 8 my $self = shift;
14 8 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 8 8
15 0 my $caller = caller;
16 0 for my $exp (@_) {
17 0 ▶ if ($exp eq ':DiffSQL') {
Branch: 2 branches
BranchTrueFalseTotal
if ($exp eq ':DiffSQL') { } 0 0 0
elsif ($exp eq ':GlobalLock') { } 0 0 0
18 0 require DBIO::SQLMaker;
19 0 require SQL::Abstract::Test;
20 0 for (qw(is_same_sql_bind is_same_sql is_same_bind)) {
21 8 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
22 0 *{"${caller}::$_"} = \&{"SQL::Abstract::Test::$_"};
23 }
24 }
25 elsif ($exp eq ':GlobalLock') {
26 # no-op, parallel to DBIO::SQLite::Test
27 }
28 else {
29 0 croak "Unknown export $exp requested from $self";
30 }
31 }
32 }
33 }
34  
35  
36 6 ▶sub _database {
Subroutine _database: called CC=3 SCAR=14.2
37 6 my $self = shift;
38 6 my %args = @_;
39  
40 6 ▶ if ($ENV{DBIO_TEST_DUCKDB_DSN}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ENV{"DBIO_TEST_DUCKDB_DSN"}) 0 6 6
41 return (
42 0 ▶ (map { $ENV{"DBIO_TEST_DUCKDB_${_}"} // '' } qw/DSN DBUSER DBPASS/),
Condition0%0/2
$ENV{"DBIO_TEST_DUCKDB_$_"} // ""
l!l
00
MC/DC0%0/1
$ENV{"DBIO_TEST_DUCKDB_$_"} // ""
$ENV{"DBIO_TEST_DUCKDB_$_"}
Truth table0%0/2
A
A= $ENV{"DBIO_TEST_DUCKDB_$_"}
Aresult
11
00
43 { AutoCommit => 1, RaiseError => 1, PrintError => 0, %args },
44 );
45 }
46  
47 return (
48 6 'dbi:DuckDB:dbname=:memory:',
49 '', '',
50 { AutoCommit => 1, RaiseError => 1, PrintError => 0, %args },
51 );
52 }
53  
54  
55 6 ▶sub init_schema {
Subroutine init_schema: called CC=1 SCAR=0.0
Pod documented
56 6 my $self = shift;
57 6 my %args = @_;
58  
59 6 my ($dsn, $user, $pass, $opts) = $self->_database(%args);
60  
61 6 return DBIO::Test->init_schema(
62 dsn => $dsn,
63 user => $user,
64 pass => $pass,
65 connect_opts => $opts,
66 storage_type => '+DBIO::DuckDB::Storage',
67 %args,
68 );
69 }
70  
71 8 1;
72  
73 __END__
74  
75 =pod
76  
77 =encoding UTF-8
78  
79 =head1 NAME
80  
81 DBIO::DuckDB::Test - DuckDB-specific test utilities for DBIO
82  
83 =head1 VERSION
84  
85 version 0.900001
86  
87 =head1 SYNOPSIS
88  
89 use DBIO::DuckDB::Test;
90  
91 my $schema = DBIO::DuckDB::Test->init_schema;
92 my $rs = $schema->resultset('Artist');
93  
94 =head1 DESCRIPTION
95  
96 Extends L<DBIO::Test> with DuckDB-specific test helpers for the
97 L<DBIO::DuckDB> driver distribution. Mirrors L<DBIO::SQLite::Test>:
98 driver tests call C<< DBIO::DuckDB::Test->init_schema >> and get a
99 connected, deployed schema backed by an in-memory DuckDB.
100  
101 =head1 METHODS
102  
103 =head2 _database
104  
105 Returns C<($dsn, $user, $pass, \%opts)> for C<< $schema->connect() >>.
106 Honours C<DBIO_TEST_DUCKDB_DSN> if set, otherwise uses
107 C<dbi:DuckDB:dbname=:memory:>.
108  
109 =head2 init_schema
110  
111 my $schema = DBIO::DuckDB::Test->init_schema(%opts);
112  
113 Thin wrapper around L<DBIO::Test/init_schema>. Fills in C<dsn> and
114 C<storage_type> for DuckDB (honouring C<DBIO_TEST_DUCKDB_DSN>) and then
115 delegates to the core harness.
116  
117 Core's C<deploy_schema> calls C<< $schema->deploy >>, which
118 L<DBIO::Schema/deploy> routes through C<dbio_deploy_class> when set on
119 the storage class -- so DuckDB deployment goes through
120 L<DBIO::DuckDB::Deploy> (the native test-and-compare path), not
121 SQL::Translator. No extra install step needed here.
122  
123 =head1 AUTHOR
124  
125 DBIO Authors
126  
127 =head1 COPYRIGHT AND LICENSE
128  
129 Copyright (C) 2026 DBIO Authors
130  
131 This is free software; you can redistribute it and/or modify it under
132 the same terms as the Perl 5 programming language system itself.
133  
134 =cut
« DuckDB/Storage.pm ↑ Summary DuckDB/Introspect.pm »