1
0
Fork 0
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:
Kenichi Ishigaki 2009-07-02 10:00:51 +00:00
parent 229f1ab4ba
commit 5cbeb50890
11 changed files with 34 additions and 28 deletions

View file

@ -20,12 +20,14 @@ use Test::NoWarnings;
plan tests => 12;
my $dbh = connect_ok(
dbfile => 'foo',
RaiseError => 1,
PrintError => 0,
AutoCommit => 0,
);
my $dbh2 = connect_ok(
dbfile => 'foo',
RaiseError => 1,
PrintError => 0,
AutoCommit => 0,

View file

@ -13,12 +13,14 @@ use Test::More tests => 12;
use Test::NoWarnings;
my $dbh = connect_ok(
dbfile => 'foo',
RaiseError => 1,
PrintError => 0,
AutoCommit => 0,
);
my $dbh2 = connect_ok(
dbfile => 'foo',
RaiseError => 1,
PrintError => 0,
AutoCommit => 0,

View file

@ -60,7 +60,7 @@ ok(
### Real DBD::SQLite testing starts here
my ($textback, $bytesback);
SCOPE: {
my $dbh = connect_ok( RaiseError => 1 );
my $dbh = connect_ok( dbfile => 'foo', RaiseError => 1 );
is( $dbh->{unicode}, 0, 'Unicode is off' );
ok(
$dbh->do("CREATE TABLE table1 (a TEXT, b BLOB)"),
@ -83,7 +83,7 @@ SCOPE: {
# Start over but now activate Unicode support.
SCOPE: {
my $dbh = connect_ok( unicode => 1 );
my $dbh = connect_ok( dbfile => 'foo', unicode => 1 );
is( $dbh->{unicode}, 1, 'Unicode is on' );
($textback, $bytesback) = database_roundtrip($dbh, $utfstring, $bytestring);

View file

@ -11,7 +11,7 @@ use Test::More tests => 37;
use Test::NoWarnings;
# 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
ok( $dbh->do(<<'END_SQL'), 'CREATE TABLE' );
@ -29,7 +29,7 @@ is( $quoted, "'test1'", '->quote(test1) ok' );
ok( $dbh->disconnect, '->disconnect' );
# Reconnect
$dbh = connect_ok();
$dbh = connect_ok( dbfile => 'foo' );
# Delete the table and recreate it
ok( $dbh->do('DROP TABLE one'), 'DROP' );

View file

@ -12,7 +12,7 @@ use Test::NoWarnings;
use DBI ':sql_types';
# 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
ok( $dbh->do(<<'END_SQL'), 'CREATE TABLE' );
@ -52,7 +52,7 @@ SCOPE: {
# Reconnect
ok( $dbh->disconnect, '->disconnect' );
$dbh = connect_ok();
$dbh = connect_ok( dbfile => 'foo' );
SCOPE: {
my $sth = $dbh->prepare("SELECT * FROM one ORDER BY id");
isa_ok( $sth, 'DBI::st' );

View file

@ -45,7 +45,7 @@ sub rows {
# Main Tests
# Create a database
my $dbh = connect_ok( RaiseError => 1 );
my $dbh = connect_ok( dbfile => 'foo', RaiseError => 1 );
# Create the table
ok( $dbh->do(<<'END_SQL'), 'CREATE TABLE' );
@ -77,7 +77,7 @@ rows( $dbh, 0 );
insert( $dbh );
rows( $dbh, 1 );
ok( $dbh->disconnect, '->disconnect ok' );
$dbh = connect_ok();
$dbh = connect_ok( dbfile => 'foo' );
rows( $dbh, 0 );
# Check that AutoCommit is back on again after the reconnect
@ -87,7 +87,7 @@ is( $dbh->{AutoCommit}, 1, 'AutoCommit is on' );
insert( $dbh );
rows( $dbh, 1 );
ok( $dbh->disconnect, '->disconnect ok' );
$dbh = connect_ok();
$dbh = connect_ok( dbfile => 'foo' );
rows( $dbh, 1 );
# Check whether commit issues a warning in AutoCommit mode

View file

@ -19,7 +19,7 @@ my $drop2 = 'DROP TABLE table2';
# diag("Parent connecting... ($$)\n");
SCOPE: {
my $dbh = connect_ok();
my $dbh = connect_ok( dbfile => 'foo' );
ok( $dbh->do($create1), $create1 );
ok( $dbh->do($create2), $create2 );
ok( $dbh->disconnect, '->disconnect ok' );
@ -48,7 +48,7 @@ if ( not defined( $pid = fork() ) ) {
SCOPE: {
# Parent process
my $dbh = connect_ok();
my $dbh = connect_ok( dbfile => 'foo' );
# diag("Waiting for child... ($$)");
ok( waitpid($pid, 0) != -1, "waitpid" );

View file

@ -14,7 +14,7 @@ BEGIN {
plan tests => 6;
# 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(
'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:
{
my $foo = connect_ok( RaiseError => 1 );
my $foo = connect_ok( dbfile => 'foo', RaiseError => 1 );
my ($count) = $foo->selectrow_array(
"SELECT count(foo) FROM online_backup_test2 WHERE foo=$$"

View file

@ -8,7 +8,7 @@ use t::lib::Test;
use DBI;
# 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(
'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:
{
my $foo = connect_ok( RaiseError => 1 );
my $foo = connect_ok( dbfile => 'foo', RaiseError => 1 );
my ($count) = $foo->selectrow_array(
"SELECT count(foo) FROM online_backup_test2 WHERE foo=$$"

View file

@ -33,9 +33,11 @@ END { clean() }
# A simplified connect function for the most common case
sub connect_ok {
my @params = ( 'dbi:SQLite:dbname=foo', '', '' );
if ( @_ ) {
push @params, { @_ };
my $attr = { @_ };
my $dbfile = delete $attr->{dbfile} || ':memory:';
my @params = ( "dbi:SQLite:dbname=$dbfile", '', '' );
if ( %$attr ) {
push @params, $attr;
}
my $dbh = DBI->connect( @params );
Test::More::isa_ok( $dbh, 'DBI::db' );

View file

@ -16,7 +16,7 @@ use Test::NoWarnings;
# Create the table
SCOPE: {
my $dbh = connect_ok();
my $dbh = connect_ok( dbfile => 'foo' );
ok( $dbh->do(<<'END_SQL'), 'CREATE TABLE' );
create table foo (
id integer primary key not null
@ -50,7 +50,7 @@ sub fetchrow_1 {
# A well-behaved non-cached statement
SCOPE: {
my $dbh = connect_ok();
my $dbh = connect_ok( dbfile => 'foo' );
SCOPE: {
my $sth = $dbh->prepare($sql);
}
@ -59,7 +59,7 @@ SCOPE: {
}
SCOPE: {
my $dbh = connect_ok();
my $dbh = connect_ok( dbfile => 'foo' );
SCOPE: {
my $sth = $dbh->prepare($sql);
$sth->execute;
@ -69,7 +69,7 @@ SCOPE: {
}
SCOPE: {
my $dbh = connect_ok();
my $dbh = connect_ok( dbfile => 'foo' );
SCOPE: {
my $sth = $dbh->prepare($sql);
$sth->execute;
@ -88,7 +88,7 @@ SCOPE: {
# Double execute, no warnings
SCOPE: {
my $dbh = connect_ok();
my $dbh = connect_ok( dbfile => 'foo' );
SCOPE: {
my $sth = $dbh->prepare($sql);
$sth->execute;
@ -102,7 +102,7 @@ SCOPE: {
# We expect a warnings from this one
SCOPE: {
my $dbh = connect_ok();
my $dbh = connect_ok( dbfile => 'foo' );
my $sth = $dbh->prepare($sql);
$sth->execute;
fetchrow_1($sth);
@ -118,7 +118,7 @@ SCOPE: {
# A well-behaved cached statement
SCOPE: {
my $dbh = connect_ok();
my $dbh = connect_ok( dbfile => 'foo' );
SCOPE: {
my $sth = $dbh->prepare_cached($sql);
}
@ -127,7 +127,7 @@ SCOPE: {
}
SCOPE: {
my $dbh = connect_ok();
my $dbh = connect_ok( dbfile => 'foo' );
SCOPE: {
my $sth = $dbh->prepare_cached($sql);
$sth->execute;
@ -139,7 +139,7 @@ SCOPE: {
}
SCOPE: {
my $dbh = connect_ok();
my $dbh = connect_ok( dbfile => 'foo' );
SCOPE: {
my $sth = $dbh->prepare_cached($sql);
$sth->execute;
@ -164,7 +164,7 @@ SCOPE: {
# Badly-behaved prepare_cached (but still acceptable)
SCOPE: {
my $dbh = connect_ok();
my $dbh = connect_ok( dbfile => 'foo' );
SCOPE: {
my $sth = $dbh->prepare_cached($sql);
$sth->execute;