From 5cbeb508905cc22aeedbd6b2ad84fc279defe5fa Mon Sep 17 00:00:00 2001 From: Kenichi Ishigaki Date: Thu, 2 Jul 2009 10:00:51 +0000 Subject: [PATCH] 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. --- t/08_busy.t | 2 ++ t/08_busy_func.t | 2 ++ t/12_unicode.t | 4 ++-- t/15_ak_dbd.t | 4 ++-- t/19_bindparam.t | 4 ++-- t/26_commit.t | 6 +++--- t/28_schemachange.t | 4 ++-- t/34_online_backup.t | 4 ++-- t/34_online_backup_func.t | 4 ++-- t/lib/Test.pm | 8 +++++--- t/rt_32889_prepare_cached_reexecute.t | 20 ++++++++++---------- 11 files changed, 34 insertions(+), 28 deletions(-) diff --git a/t/08_busy.t b/t/08_busy.t index ed700d5..2307a7f 100644 --- a/t/08_busy.t +++ b/t/08_busy.t @@ -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, diff --git a/t/08_busy_func.t b/t/08_busy_func.t index 8eb6f94..af728dd 100644 --- a/t/08_busy_func.t +++ b/t/08_busy_func.t @@ -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, diff --git a/t/12_unicode.t b/t/12_unicode.t index d6fdbe1..c4ed32b 100644 --- a/t/12_unicode.t +++ b/t/12_unicode.t @@ -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); diff --git a/t/15_ak_dbd.t b/t/15_ak_dbd.t index 21a1c67..ddde0f7 100644 --- a/t/15_ak_dbd.t +++ b/t/15_ak_dbd.t @@ -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' ); diff --git a/t/19_bindparam.t b/t/19_bindparam.t index 044004d..955663d 100644 --- a/t/19_bindparam.t +++ b/t/19_bindparam.t @@ -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' ); diff --git a/t/26_commit.t b/t/26_commit.t index fe570fe..75716ed 100644 --- a/t/26_commit.t +++ b/t/26_commit.t @@ -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 diff --git a/t/28_schemachange.t b/t/28_schemachange.t index 4c440d9..3aa5d2c 100644 --- a/t/28_schemachange.t +++ b/t/28_schemachange.t @@ -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" ); diff --git a/t/34_online_backup.t b/t/34_online_backup.t index 10a3708..eded34e 100644 --- a/t/34_online_backup.t +++ b/t/34_online_backup.t @@ -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=$$" diff --git a/t/34_online_backup_func.t b/t/34_online_backup_func.t index bf4c2c4..acb23f8 100644 --- a/t/34_online_backup_func.t +++ b/t/34_online_backup_func.t @@ -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=$$" diff --git a/t/lib/Test.pm b/t/lib/Test.pm index cfd1467..c12fce2 100644 --- a/t/lib/Test.pm +++ b/t/lib/Test.pm @@ -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' ); diff --git a/t/rt_32889_prepare_cached_reexecute.t b/t/rt_32889_prepare_cached_reexecute.t index 39a038b..e0a453b 100644 --- a/t/rt_32889_prepare_cached_reexecute.t +++ b/t/rt_32889_prepare_cached_reexecute.t @@ -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;