mirror of
https://github.com/DBD-SQLite/DBD-SQLite
synced 2025-06-07 14:19:10 -04:00
DBD-SQLite: switched to use :memory: for most of the tests
Speaking more specifically, for the tests that don't require reconnection. It seems this makes it easier to find memory leaks by DBD::SQLite itself.
This commit is contained in:
parent
229f1ab4ba
commit
5cbeb50890
11 changed files with 34 additions and 28 deletions
|
@ -20,12 +20,14 @@ use Test::NoWarnings;
|
||||||
plan tests => 12;
|
plan tests => 12;
|
||||||
|
|
||||||
my $dbh = connect_ok(
|
my $dbh = connect_ok(
|
||||||
|
dbfile => 'foo',
|
||||||
RaiseError => 1,
|
RaiseError => 1,
|
||||||
PrintError => 0,
|
PrintError => 0,
|
||||||
AutoCommit => 0,
|
AutoCommit => 0,
|
||||||
);
|
);
|
||||||
|
|
||||||
my $dbh2 = connect_ok(
|
my $dbh2 = connect_ok(
|
||||||
|
dbfile => 'foo',
|
||||||
RaiseError => 1,
|
RaiseError => 1,
|
||||||
PrintError => 0,
|
PrintError => 0,
|
||||||
AutoCommit => 0,
|
AutoCommit => 0,
|
||||||
|
|
|
@ -13,12 +13,14 @@ use Test::More tests => 12;
|
||||||
use Test::NoWarnings;
|
use Test::NoWarnings;
|
||||||
|
|
||||||
my $dbh = connect_ok(
|
my $dbh = connect_ok(
|
||||||
|
dbfile => 'foo',
|
||||||
RaiseError => 1,
|
RaiseError => 1,
|
||||||
PrintError => 0,
|
PrintError => 0,
|
||||||
AutoCommit => 0,
|
AutoCommit => 0,
|
||||||
);
|
);
|
||||||
|
|
||||||
my $dbh2 = connect_ok(
|
my $dbh2 = connect_ok(
|
||||||
|
dbfile => 'foo',
|
||||||
RaiseError => 1,
|
RaiseError => 1,
|
||||||
PrintError => 0,
|
PrintError => 0,
|
||||||
AutoCommit => 0,
|
AutoCommit => 0,
|
||||||
|
|
|
@ -60,7 +60,7 @@ ok(
|
||||||
### Real DBD::SQLite testing starts here
|
### Real DBD::SQLite testing starts here
|
||||||
my ($textback, $bytesback);
|
my ($textback, $bytesback);
|
||||||
SCOPE: {
|
SCOPE: {
|
||||||
my $dbh = connect_ok( RaiseError => 1 );
|
my $dbh = connect_ok( dbfile => 'foo', RaiseError => 1 );
|
||||||
is( $dbh->{unicode}, 0, 'Unicode is off' );
|
is( $dbh->{unicode}, 0, 'Unicode is off' );
|
||||||
ok(
|
ok(
|
||||||
$dbh->do("CREATE TABLE table1 (a TEXT, b BLOB)"),
|
$dbh->do("CREATE TABLE table1 (a TEXT, b BLOB)"),
|
||||||
|
@ -83,7 +83,7 @@ SCOPE: {
|
||||||
|
|
||||||
# Start over but now activate Unicode support.
|
# Start over but now activate Unicode support.
|
||||||
SCOPE: {
|
SCOPE: {
|
||||||
my $dbh = connect_ok( unicode => 1 );
|
my $dbh = connect_ok( dbfile => 'foo', unicode => 1 );
|
||||||
is( $dbh->{unicode}, 1, 'Unicode is on' );
|
is( $dbh->{unicode}, 1, 'Unicode is on' );
|
||||||
|
|
||||||
($textback, $bytesback) = database_roundtrip($dbh, $utfstring, $bytestring);
|
($textback, $bytesback) = database_roundtrip($dbh, $utfstring, $bytestring);
|
||||||
|
|
|
@ -11,7 +11,7 @@ use Test::More tests => 37;
|
||||||
use Test::NoWarnings;
|
use Test::NoWarnings;
|
||||||
|
|
||||||
# Create a database
|
# Create a database
|
||||||
my $dbh = connect_ok( RaiseError => 1, PrintError => 1, PrintWarn => 1 );
|
my $dbh = connect_ok( dbfile => 'foo', RaiseError => 1, PrintError => 1, PrintWarn => 1 );
|
||||||
|
|
||||||
# Create the table
|
# Create the table
|
||||||
ok( $dbh->do(<<'END_SQL'), 'CREATE TABLE' );
|
ok( $dbh->do(<<'END_SQL'), 'CREATE TABLE' );
|
||||||
|
@ -29,7 +29,7 @@ is( $quoted, "'test1'", '->quote(test1) ok' );
|
||||||
ok( $dbh->disconnect, '->disconnect' );
|
ok( $dbh->disconnect, '->disconnect' );
|
||||||
|
|
||||||
# Reconnect
|
# Reconnect
|
||||||
$dbh = connect_ok();
|
$dbh = connect_ok( dbfile => 'foo' );
|
||||||
|
|
||||||
# Delete the table and recreate it
|
# Delete the table and recreate it
|
||||||
ok( $dbh->do('DROP TABLE one'), 'DROP' );
|
ok( $dbh->do('DROP TABLE one'), 'DROP' );
|
||||||
|
|
|
@ -12,7 +12,7 @@ use Test::NoWarnings;
|
||||||
use DBI ':sql_types';
|
use DBI ':sql_types';
|
||||||
|
|
||||||
# Create a database
|
# Create a database
|
||||||
my $dbh = connect_ok( RaiseError => 1, PrintError => 1, PrintWarn => 1 );
|
my $dbh = connect_ok( dbfile => 'foo', RaiseError => 1, PrintError => 1, PrintWarn => 1 );
|
||||||
|
|
||||||
# Create the table
|
# Create the table
|
||||||
ok( $dbh->do(<<'END_SQL'), 'CREATE TABLE' );
|
ok( $dbh->do(<<'END_SQL'), 'CREATE TABLE' );
|
||||||
|
@ -52,7 +52,7 @@ SCOPE: {
|
||||||
|
|
||||||
# Reconnect
|
# Reconnect
|
||||||
ok( $dbh->disconnect, '->disconnect' );
|
ok( $dbh->disconnect, '->disconnect' );
|
||||||
$dbh = connect_ok();
|
$dbh = connect_ok( dbfile => 'foo' );
|
||||||
SCOPE: {
|
SCOPE: {
|
||||||
my $sth = $dbh->prepare("SELECT * FROM one ORDER BY id");
|
my $sth = $dbh->prepare("SELECT * FROM one ORDER BY id");
|
||||||
isa_ok( $sth, 'DBI::st' );
|
isa_ok( $sth, 'DBI::st' );
|
||||||
|
|
|
@ -45,7 +45,7 @@ sub rows {
|
||||||
# Main Tests
|
# Main Tests
|
||||||
|
|
||||||
# Create a database
|
# Create a database
|
||||||
my $dbh = connect_ok( RaiseError => 1 );
|
my $dbh = connect_ok( dbfile => 'foo', RaiseError => 1 );
|
||||||
|
|
||||||
# Create the table
|
# Create the table
|
||||||
ok( $dbh->do(<<'END_SQL'), 'CREATE TABLE' );
|
ok( $dbh->do(<<'END_SQL'), 'CREATE TABLE' );
|
||||||
|
@ -77,7 +77,7 @@ rows( $dbh, 0 );
|
||||||
insert( $dbh );
|
insert( $dbh );
|
||||||
rows( $dbh, 1 );
|
rows( $dbh, 1 );
|
||||||
ok( $dbh->disconnect, '->disconnect ok' );
|
ok( $dbh->disconnect, '->disconnect ok' );
|
||||||
$dbh = connect_ok();
|
$dbh = connect_ok( dbfile => 'foo' );
|
||||||
rows( $dbh, 0 );
|
rows( $dbh, 0 );
|
||||||
|
|
||||||
# Check that AutoCommit is back on again after the reconnect
|
# Check that AutoCommit is back on again after the reconnect
|
||||||
|
@ -87,7 +87,7 @@ is( $dbh->{AutoCommit}, 1, 'AutoCommit is on' );
|
||||||
insert( $dbh );
|
insert( $dbh );
|
||||||
rows( $dbh, 1 );
|
rows( $dbh, 1 );
|
||||||
ok( $dbh->disconnect, '->disconnect ok' );
|
ok( $dbh->disconnect, '->disconnect ok' );
|
||||||
$dbh = connect_ok();
|
$dbh = connect_ok( dbfile => 'foo' );
|
||||||
rows( $dbh, 1 );
|
rows( $dbh, 1 );
|
||||||
|
|
||||||
# Check whether commit issues a warning in AutoCommit mode
|
# Check whether commit issues a warning in AutoCommit mode
|
||||||
|
|
|
@ -19,7 +19,7 @@ my $drop2 = 'DROP TABLE table2';
|
||||||
|
|
||||||
# diag("Parent connecting... ($$)\n");
|
# diag("Parent connecting... ($$)\n");
|
||||||
SCOPE: {
|
SCOPE: {
|
||||||
my $dbh = connect_ok();
|
my $dbh = connect_ok( dbfile => 'foo' );
|
||||||
ok( $dbh->do($create1), $create1 );
|
ok( $dbh->do($create1), $create1 );
|
||||||
ok( $dbh->do($create2), $create2 );
|
ok( $dbh->do($create2), $create2 );
|
||||||
ok( $dbh->disconnect, '->disconnect ok' );
|
ok( $dbh->disconnect, '->disconnect ok' );
|
||||||
|
@ -48,7 +48,7 @@ if ( not defined( $pid = fork() ) ) {
|
||||||
|
|
||||||
SCOPE: {
|
SCOPE: {
|
||||||
# Parent process
|
# Parent process
|
||||||
my $dbh = connect_ok();
|
my $dbh = connect_ok( dbfile => 'foo' );
|
||||||
# diag("Waiting for child... ($$)");
|
# diag("Waiting for child... ($$)");
|
||||||
ok( waitpid($pid, 0) != -1, "waitpid" );
|
ok( waitpid($pid, 0) != -1, "waitpid" );
|
||||||
|
|
||||||
|
|
|
@ -14,7 +14,7 @@ BEGIN {
|
||||||
plan tests => 6;
|
plan tests => 6;
|
||||||
|
|
||||||
# Connect to the test db and add some stuff:
|
# Connect to the test db and add some stuff:
|
||||||
my $foo = connect_ok( RaiseError => 1 );
|
my $foo = connect_ok( dbfile => 'foo', RaiseError => 1 );
|
||||||
$foo->do(
|
$foo->do(
|
||||||
'CREATE TABLE online_backup_test( id INTEGER PRIMARY KEY, foo INTEGER )'
|
'CREATE TABLE online_backup_test( id INTEGER PRIMARY KEY, foo INTEGER )'
|
||||||
);
|
);
|
||||||
|
@ -53,7 +53,7 @@ $dbh->disconnect;
|
||||||
|
|
||||||
# Reconnect to foo db and check data made it over:
|
# Reconnect to foo db and check data made it over:
|
||||||
{
|
{
|
||||||
my $foo = connect_ok( RaiseError => 1 );
|
my $foo = connect_ok( dbfile => 'foo', RaiseError => 1 );
|
||||||
|
|
||||||
my ($count) = $foo->selectrow_array(
|
my ($count) = $foo->selectrow_array(
|
||||||
"SELECT count(foo) FROM online_backup_test2 WHERE foo=$$"
|
"SELECT count(foo) FROM online_backup_test2 WHERE foo=$$"
|
||||||
|
|
|
@ -8,7 +8,7 @@ use t::lib::Test;
|
||||||
use DBI;
|
use DBI;
|
||||||
|
|
||||||
# Connect to the test db and add some stuff:
|
# Connect to the test db and add some stuff:
|
||||||
my $foo = connect_ok( RaiseError => 1 );
|
my $foo = connect_ok( dbfile => 'foo', RaiseError => 1 );
|
||||||
$foo->do(
|
$foo->do(
|
||||||
'CREATE TABLE online_backup_test( id INTEGER PRIMARY KEY, foo INTEGER )'
|
'CREATE TABLE online_backup_test( id INTEGER PRIMARY KEY, foo INTEGER )'
|
||||||
);
|
);
|
||||||
|
@ -47,7 +47,7 @@ $dbh->disconnect;
|
||||||
|
|
||||||
# Reconnect to foo db and check data made it over:
|
# Reconnect to foo db and check data made it over:
|
||||||
{
|
{
|
||||||
my $foo = connect_ok( RaiseError => 1 );
|
my $foo = connect_ok( dbfile => 'foo', RaiseError => 1 );
|
||||||
|
|
||||||
my ($count) = $foo->selectrow_array(
|
my ($count) = $foo->selectrow_array(
|
||||||
"SELECT count(foo) FROM online_backup_test2 WHERE foo=$$"
|
"SELECT count(foo) FROM online_backup_test2 WHERE foo=$$"
|
||||||
|
|
|
@ -33,9 +33,11 @@ END { clean() }
|
||||||
|
|
||||||
# A simplified connect function for the most common case
|
# A simplified connect function for the most common case
|
||||||
sub connect_ok {
|
sub connect_ok {
|
||||||
my @params = ( 'dbi:SQLite:dbname=foo', '', '' );
|
my $attr = { @_ };
|
||||||
if ( @_ ) {
|
my $dbfile = delete $attr->{dbfile} || ':memory:';
|
||||||
push @params, { @_ };
|
my @params = ( "dbi:SQLite:dbname=$dbfile", '', '' );
|
||||||
|
if ( %$attr ) {
|
||||||
|
push @params, $attr;
|
||||||
}
|
}
|
||||||
my $dbh = DBI->connect( @params );
|
my $dbh = DBI->connect( @params );
|
||||||
Test::More::isa_ok( $dbh, 'DBI::db' );
|
Test::More::isa_ok( $dbh, 'DBI::db' );
|
||||||
|
|
|
@ -16,7 +16,7 @@ use Test::NoWarnings;
|
||||||
|
|
||||||
# Create the table
|
# Create the table
|
||||||
SCOPE: {
|
SCOPE: {
|
||||||
my $dbh = connect_ok();
|
my $dbh = connect_ok( dbfile => 'foo' );
|
||||||
ok( $dbh->do(<<'END_SQL'), 'CREATE TABLE' );
|
ok( $dbh->do(<<'END_SQL'), 'CREATE TABLE' );
|
||||||
create table foo (
|
create table foo (
|
||||||
id integer primary key not null
|
id integer primary key not null
|
||||||
|
@ -50,7 +50,7 @@ sub fetchrow_1 {
|
||||||
# A well-behaved non-cached statement
|
# A well-behaved non-cached statement
|
||||||
|
|
||||||
SCOPE: {
|
SCOPE: {
|
||||||
my $dbh = connect_ok();
|
my $dbh = connect_ok( dbfile => 'foo' );
|
||||||
SCOPE: {
|
SCOPE: {
|
||||||
my $sth = $dbh->prepare($sql);
|
my $sth = $dbh->prepare($sql);
|
||||||
}
|
}
|
||||||
|
@ -59,7 +59,7 @@ SCOPE: {
|
||||||
}
|
}
|
||||||
|
|
||||||
SCOPE: {
|
SCOPE: {
|
||||||
my $dbh = connect_ok();
|
my $dbh = connect_ok( dbfile => 'foo' );
|
||||||
SCOPE: {
|
SCOPE: {
|
||||||
my $sth = $dbh->prepare($sql);
|
my $sth = $dbh->prepare($sql);
|
||||||
$sth->execute;
|
$sth->execute;
|
||||||
|
@ -69,7 +69,7 @@ SCOPE: {
|
||||||
}
|
}
|
||||||
|
|
||||||
SCOPE: {
|
SCOPE: {
|
||||||
my $dbh = connect_ok();
|
my $dbh = connect_ok( dbfile => 'foo' );
|
||||||
SCOPE: {
|
SCOPE: {
|
||||||
my $sth = $dbh->prepare($sql);
|
my $sth = $dbh->prepare($sql);
|
||||||
$sth->execute;
|
$sth->execute;
|
||||||
|
@ -88,7 +88,7 @@ SCOPE: {
|
||||||
|
|
||||||
# Double execute, no warnings
|
# Double execute, no warnings
|
||||||
SCOPE: {
|
SCOPE: {
|
||||||
my $dbh = connect_ok();
|
my $dbh = connect_ok( dbfile => 'foo' );
|
||||||
SCOPE: {
|
SCOPE: {
|
||||||
my $sth = $dbh->prepare($sql);
|
my $sth = $dbh->prepare($sql);
|
||||||
$sth->execute;
|
$sth->execute;
|
||||||
|
@ -102,7 +102,7 @@ SCOPE: {
|
||||||
|
|
||||||
# We expect a warnings from this one
|
# We expect a warnings from this one
|
||||||
SCOPE: {
|
SCOPE: {
|
||||||
my $dbh = connect_ok();
|
my $dbh = connect_ok( dbfile => 'foo' );
|
||||||
my $sth = $dbh->prepare($sql);
|
my $sth = $dbh->prepare($sql);
|
||||||
$sth->execute;
|
$sth->execute;
|
||||||
fetchrow_1($sth);
|
fetchrow_1($sth);
|
||||||
|
@ -118,7 +118,7 @@ SCOPE: {
|
||||||
# A well-behaved cached statement
|
# A well-behaved cached statement
|
||||||
|
|
||||||
SCOPE: {
|
SCOPE: {
|
||||||
my $dbh = connect_ok();
|
my $dbh = connect_ok( dbfile => 'foo' );
|
||||||
SCOPE: {
|
SCOPE: {
|
||||||
my $sth = $dbh->prepare_cached($sql);
|
my $sth = $dbh->prepare_cached($sql);
|
||||||
}
|
}
|
||||||
|
@ -127,7 +127,7 @@ SCOPE: {
|
||||||
}
|
}
|
||||||
|
|
||||||
SCOPE: {
|
SCOPE: {
|
||||||
my $dbh = connect_ok();
|
my $dbh = connect_ok( dbfile => 'foo' );
|
||||||
SCOPE: {
|
SCOPE: {
|
||||||
my $sth = $dbh->prepare_cached($sql);
|
my $sth = $dbh->prepare_cached($sql);
|
||||||
$sth->execute;
|
$sth->execute;
|
||||||
|
@ -139,7 +139,7 @@ SCOPE: {
|
||||||
}
|
}
|
||||||
|
|
||||||
SCOPE: {
|
SCOPE: {
|
||||||
my $dbh = connect_ok();
|
my $dbh = connect_ok( dbfile => 'foo' );
|
||||||
SCOPE: {
|
SCOPE: {
|
||||||
my $sth = $dbh->prepare_cached($sql);
|
my $sth = $dbh->prepare_cached($sql);
|
||||||
$sth->execute;
|
$sth->execute;
|
||||||
|
@ -164,7 +164,7 @@ SCOPE: {
|
||||||
# Badly-behaved prepare_cached (but still acceptable)
|
# Badly-behaved prepare_cached (but still acceptable)
|
||||||
|
|
||||||
SCOPE: {
|
SCOPE: {
|
||||||
my $dbh = connect_ok();
|
my $dbh = connect_ok( dbfile => 'foo' );
|
||||||
SCOPE: {
|
SCOPE: {
|
||||||
my $sth = $dbh->prepare_cached($sql);
|
my $sth = $dbh->prepare_cached($sql);
|
||||||
$sth->execute;
|
$sth->execute;
|
||||||
|
|
Loading…
Add table
Reference in a new issue