mirror of
https://github.com/DBD-SQLite/DBD-SQLite
synced 2025-06-07 14:19:10 -04:00
Adding t::lib::Test, to reduce the amount of duplicated code in the newer Test::More tests
This commit is contained in:
parent
a3ff0b1f7c
commit
86c057f680
18 changed files with 71 additions and 68 deletions
|
@ -1,11 +1,18 @@
|
|||
#!/usr/bin/perl
|
||||
|
||||
# Test that everything compiles, so the rest of the test suite can
|
||||
# load modules without having to check if it worked.
|
||||
|
||||
use strict;
|
||||
BEGIN {
|
||||
$| = 1;
|
||||
$^W = 1;
|
||||
}
|
||||
|
||||
use Test::More tests => 1;
|
||||
use Test::More tests => 4;
|
||||
|
||||
ok( $] >= 5.005, 'Perl version is new enough' );
|
||||
|
||||
use_ok('DBI');
|
||||
use_ok('DBD::SQLite');
|
||||
use_ok('t::lib::Test');
|
||||
|
|
|
@ -7,7 +7,7 @@ BEGIN {
|
|||
}
|
||||
|
||||
use Test::More tests => 5;
|
||||
use DBI;
|
||||
use t::lib::Test;
|
||||
|
||||
my $dbh = DBI->connect("dbi:SQLite:dbname=foo", "", "");
|
||||
ok($dbh);
|
||||
|
@ -19,5 +19,3 @@ ok($dbh->func(5000, 'busy_timeout'));
|
|||
is($dbh->func('busy_timeout'), 5000);
|
||||
print "# sqlite_busy_timeout=", $dbh->func('busy_timeout'), "\n";
|
||||
$dbh->disconnect;
|
||||
|
||||
END { unlink 'foo' }
|
||||
|
|
|
@ -7,7 +7,7 @@ BEGIN {
|
|||
}
|
||||
|
||||
use Test::More tests => 4;
|
||||
use DBI;
|
||||
use t::lib::Test;
|
||||
|
||||
my $dbh = DBI->connect("dbi:SQLite:dbname=foo", "", "");
|
||||
ok($dbh);
|
||||
|
@ -21,5 +21,3 @@ print("# ", join(', ', @$names), "\n");
|
|||
ok($names->[0] eq "f1"); # make sure the "f." is removed
|
||||
undef $sth;
|
||||
$dbh->disconnect;
|
||||
|
||||
END { unlink 'foo' }
|
||||
|
|
|
@ -7,7 +7,7 @@ BEGIN {
|
|||
}
|
||||
|
||||
use Test::More tests => 11;
|
||||
use DBI;
|
||||
use t::lib::Test;
|
||||
|
||||
my $dbh = DBI->connect("dbi:SQLite:dbname=foo", "", "", {AutoCommit => 1});
|
||||
ok($dbh);
|
||||
|
@ -33,5 +33,3 @@ is($dbh->do("delete from f where f1='test'"), 3);
|
|||
$sth->finish;
|
||||
undef $sth;
|
||||
$dbh->disconnect;
|
||||
|
||||
END { unlink 'foo' }
|
||||
|
|
|
@ -7,7 +7,7 @@ BEGIN {
|
|||
}
|
||||
|
||||
use Test::More tests => 21;
|
||||
use DBI;
|
||||
use t::lib::Test;
|
||||
|
||||
my $dbh = DBI->connect("dbi:SQLite:dbname=foo", "", "", { RaiseError => 1, AutoCommit => 1 });
|
||||
ok($dbh);
|
||||
|
@ -64,5 +64,3 @@ $sth->finish;
|
|||
undef $sth;
|
||||
$dbh->do("delete from f where f1='test'");
|
||||
$dbh->disconnect;
|
||||
|
||||
END { unlink 'foo' }
|
||||
|
|
31
t/05tran.t
31
t/05tran.t
|
@ -7,9 +7,8 @@ BEGIN {
|
|||
}
|
||||
|
||||
use Test::More tests => 2;
|
||||
use t::lib::Test;
|
||||
|
||||
use DBI;
|
||||
unlink("foo");
|
||||
my $dbh = DBI->connect("dbi:SQLite:dbname=foo", "", "",
|
||||
{AutoCommit => 0, RaiseError => 1});
|
||||
|
||||
|
@ -29,19 +28,19 @@ $dbh->do("INSERT INTO TRN VALUES('C', 1, 4)");
|
|||
$dbh->do("INSERT INTO TRN VALUES('D', 3, 3)");
|
||||
$dbh->rollback; #not work?
|
||||
|
||||
my $sth = $dbh->prepare(
|
||||
"SELECT TRN.id AS ID, MST.LBL AS TITLE,
|
||||
SUM(qty) AS TOTAL FROM TRN,MST
|
||||
WHERE TRN.ID = MST.ID
|
||||
GROUP BY TRN.ID ORDER BY TRN.ID DESC");
|
||||
my $rows = $sth->execute();
|
||||
ok($rows, "0E0");
|
||||
my $names = $sth->{NAME};
|
||||
print(join(', ', @$names), "\n");
|
||||
while(my $raD = $sth->fetchrow_arrayref()) {
|
||||
print join(":", @$raD), "\n";
|
||||
SCOPE: {
|
||||
my $sth = $dbh->prepare(
|
||||
"SELECT TRN.id AS ID, MST.LBL AS TITLE,
|
||||
SUM(qty) AS TOTAL FROM TRN,MST
|
||||
WHERE TRN.ID = MST.ID
|
||||
GROUP BY TRN.ID ORDER BY TRN.ID DESC");
|
||||
my $rows = $sth->execute();
|
||||
ok($rows, "0E0");
|
||||
my $names = $sth->{NAME};
|
||||
print(join(', ', @$names), "\n");
|
||||
while(my $raD = $sth->fetchrow_arrayref()) {
|
||||
print join(":", @$raD), "\n";
|
||||
}
|
||||
}
|
||||
undef $sth;
|
||||
$dbh->disconnect;
|
||||
|
||||
END { unlink 'foo' }
|
||||
$dbh->disconnect;
|
||||
|
|
|
@ -7,9 +7,8 @@ BEGIN {
|
|||
}
|
||||
|
||||
use Test::More tests => 2;
|
||||
use DBI;
|
||||
use t::lib::Test;
|
||||
|
||||
unlink('foo');
|
||||
my $db = DBI->connect('dbi:SQLite:foo', '', '', { RaiseError => 1, PrintError => 0 });
|
||||
eval {
|
||||
$db->do('ssdfsdf sdf sd sdfsdfdsf sdfsdf');
|
||||
|
@ -25,5 +24,3 @@ eval {
|
|||
$db->do('insert into testerror values (1, 5)');
|
||||
};
|
||||
ok($@);
|
||||
|
||||
END { unlink 'foo' }
|
||||
|
|
|
@ -7,7 +7,7 @@ BEGIN {
|
|||
}
|
||||
|
||||
use Test::More tests => 8;
|
||||
use DBI;
|
||||
use t::lib::Test;
|
||||
|
||||
my $db = DBI->connect('dbi:SQLite:foo', '', '',
|
||||
{
|
||||
|
@ -77,5 +77,3 @@ if (!defined($pid)) {
|
|||
$db->commit;
|
||||
wait;
|
||||
}
|
||||
|
||||
END { unlink('foo', 'foo-journal') }
|
||||
|
|
|
@ -7,7 +7,7 @@ BEGIN {
|
|||
}
|
||||
|
||||
use Test::More tests => 18;
|
||||
use DBI;
|
||||
use t::lib::Test;
|
||||
|
||||
sub now {
|
||||
return time();
|
||||
|
@ -121,5 +121,3 @@ $result = $dbh->selectrow_arrayref( "SELECT noop(1.0625)" );
|
|||
is_deeply( $result, [ 1.0625 ], "SELECT noop(1.0625)" );
|
||||
|
||||
$dbh->disconnect;
|
||||
|
||||
END { unlink 'foo' }
|
||||
|
|
|
@ -7,7 +7,7 @@ BEGIN {
|
|||
}
|
||||
|
||||
use Test::More tests => 15;
|
||||
use DBI;
|
||||
use t::lib::Test;
|
||||
|
||||
# Create the aggregate test packages
|
||||
SCOPE: {
|
||||
|
@ -128,5 +128,3 @@ $dbh->func( "fail_undef", -1, $aggr, 'create_aggregate' );
|
|||
$result = $dbh->selectrow_arrayref( "SELECT fail_undef() FROM aggr_test" );
|
||||
# ok( !$result && $DBI::errstr =~ /new\(\) should return a blessed reference/ );
|
||||
ok( !defined $result->[0] && $last_warn =~ /new\(\) should return a blessed reference/ );
|
||||
|
||||
END { unlink 'foo' }
|
||||
|
|
|
@ -15,7 +15,7 @@ BEGIN {
|
|||
}
|
||||
|
||||
use Test::More tests => 8;
|
||||
use DBI;
|
||||
use t::lib::Test;
|
||||
use Encode qw/decode/;
|
||||
|
||||
BEGIN {
|
||||
|
@ -100,8 +100,4 @@ is_deeply(\@sorted, $db_sorted, "collate perllocale (@sorted // @$db_sorted)");
|
|||
$db_sorted = $dbh->selectcol_arrayref("$sql COLLATE no_accents");
|
||||
is_deeply(\@sorted, $db_sorted, "collate no_accents (@sorted // @$db_sorted)");
|
||||
|
||||
|
||||
|
||||
$dbh->disconnect;
|
||||
|
||||
END { unlink 'foo' }
|
||||
|
|
|
@ -7,7 +7,7 @@ BEGIN {
|
|||
}
|
||||
|
||||
use Test::More tests => 3;
|
||||
use DBI;
|
||||
use t::lib::Test;
|
||||
|
||||
my $N_OPCODES = 50; # how many opcodes before calling the progress handler
|
||||
|
||||
|
@ -48,5 +48,3 @@ $result = $dbh->do( "SELECT * from progress_test ORDER BY foo DESC " );
|
|||
ok(!$n_callback);
|
||||
|
||||
$dbh->disconnect;
|
||||
|
||||
END { unlink 'foo' }
|
||||
|
|
|
@ -7,9 +7,8 @@ BEGIN {
|
|||
}
|
||||
|
||||
use Test::More tests => 26;
|
||||
use DBI;
|
||||
use t::lib::Test;
|
||||
|
||||
unlink('foo', 'foo-journal');
|
||||
my $db = DBI->connect('dbi:SQLite:foo', '', '',
|
||||
{
|
||||
RaiseError => 1,
|
||||
|
@ -66,9 +65,6 @@ undef $sel;
|
|||
|
||||
$db->disconnect;
|
||||
|
||||
END { unlink('foo', 'foo-journal'); }
|
||||
|
||||
|
||||
sub dumpblob {
|
||||
my $blob = shift;
|
||||
print("# showblob length: ", length($blob), "\n");
|
||||
|
|
|
@ -8,7 +8,6 @@ BEGIN {
|
|||
$^W = 1;
|
||||
}
|
||||
|
||||
use strict;
|
||||
use vars qw($test_dsn $test_user $test_password $mdriver $dbdriver $state);
|
||||
|
||||
#
|
||||
|
|
|
@ -7,7 +7,7 @@ BEGIN {
|
|||
}
|
||||
|
||||
use Test::More tests => 27;
|
||||
use DBI;
|
||||
use t::lib::Test;
|
||||
|
||||
my $dbh = DBI->connect("dbi:SQLite:dbname=foo", "", "", { });
|
||||
ok($dbh);
|
||||
|
@ -58,5 +58,3 @@ ok($types->[1] eq 'char(1)');
|
|||
ok $dbh->do("create table meta5 ( f1 integer PRIMARY KEY )");
|
||||
@pk = $dbh->primary_key(undef, undef, 'meta5');
|
||||
ok($pk[0] eq 'f1');
|
||||
|
||||
END { unlink 'foo' }
|
||||
|
|
|
@ -7,8 +7,8 @@ BEGIN {
|
|||
}
|
||||
|
||||
use Test::More;
|
||||
use t::lib::Test;
|
||||
use Fatal qw(open);
|
||||
use DBI;
|
||||
|
||||
my @c_files = <*.c>, <*.xs>;
|
||||
plan tests => scalar(@c_files);
|
||||
|
|
|
@ -7,15 +7,16 @@ BEGIN {
|
|||
}
|
||||
|
||||
use Test::More tests => 6;
|
||||
use DBI;
|
||||
use t::lib::Test;
|
||||
|
||||
my $dbh = DBI->connect('dbi:SQLite:dbname=:memory:',undef,undef,{RaiseError => 1});
|
||||
|
||||
ok $dbh->do(<<''), 'Created test table';
|
||||
ok( $dbh->do(<<'END_SQL'), 'Created test table' );
|
||||
CREATE TABLE test (
|
||||
id INTEGER PRIMARY KEY NOT NULL,
|
||||
name VARCHAR(255)
|
||||
);
|
||||
END_SQL
|
||||
|
||||
my $sth = $dbh->column_info(undef,undef,'test',undef);
|
||||
is $@, '', 'No error creating the table';
|
||||
|
@ -23,7 +24,7 @@ is $@, '', 'No error creating the table';
|
|||
ok $sth, 'We can get column information';
|
||||
|
||||
my %expected = (
|
||||
TYPE_NAME => [qw[ INTEGER VARCHAR ]],
|
||||
TYPE_NAME => [qw[ INTEGER VARCHAR ]],
|
||||
COLUMN_NAME => [qw[ ID NAME ]],
|
||||
);
|
||||
|
||||
|
@ -31,13 +32,13 @@ SKIP: {
|
|||
if ($sth) {
|
||||
my $info = $sth->fetchall_arrayref({});
|
||||
|
||||
is scalar @$info, 2, 'We got information on two columns';
|
||||
is( scalar @$info, 2, 'We got information on two columns' );
|
||||
|
||||
for my $item (qw( TYPE_NAME COLUMN_NAME )) {
|
||||
my @info = map {uc $_->{$item}} (@$info);
|
||||
is_deeply \@info, $expected{$item}, "We got the right info in $item";
|
||||
foreach my $item (qw( TYPE_NAME COLUMN_NAME )) {
|
||||
my @info = map { uc $_->{$item} } (@$info);
|
||||
is_deeply( \@info, $expected{$item}, "We got the right info in $item" );
|
||||
};
|
||||
} else {
|
||||
skip "The table didn't get created correctly or we can't get column information.", 3;
|
||||
skip( "The table didn't get created correctly or we can't get column information.", 3 );
|
||||
}
|
||||
};
|
||||
|
|
26
t/lib/Test.pm
Normal file
26
t/lib/Test.pm
Normal file
|
@ -0,0 +1,26 @@
|
|||
package t::lib::Test;
|
||||
|
||||
# Support code for DBD::SQLite tests
|
||||
|
||||
use strict;
|
||||
|
||||
# Always load the DBI module
|
||||
use DBI ();
|
||||
|
||||
# Delete temporary files
|
||||
sub clean {
|
||||
my @files = qw{
|
||||
foo
|
||||
foo-journal
|
||||
};
|
||||
foreach my $file ( @files ) {
|
||||
unlink $file if -e $file;
|
||||
}
|
||||
}
|
||||
|
||||
# Clean up temporary test files both at the beginning and end of the
|
||||
# test script.
|
||||
BEGIN { clean() }
|
||||
END { clean() }
|
||||
|
||||
1;
|
Loading…
Add table
Reference in a new issue