1
0
Fork 0
mirror of https://github.com/DBD-SQLite/DBD-SQLite synced 2025-06-07 22:28:47 -04:00

Rewrote to use Test::More

This commit is contained in:
Adam Kennedy 2009-04-04 22:00:35 +00:00
parent 5e7f3ea9a6
commit a95211acc0

View file

@ -9,7 +9,7 @@ BEGIN {
$^W = 1; $^W = 1;
} }
use Test::More tests => 5; use Test::More tests => 9;
use t::lib::Test; use t::lib::Test;
my $create1 = 'CREATE TABLE table1 (id INTEGER NOT NULL, name CHAR (64) NOT NULL)'; my $create1 = 'CREATE TABLE table1 (id INTEGER NOT NULL, name CHAR (64) NOT NULL)';
@ -17,15 +17,11 @@ my $create2 = 'CREATE TABLE table2 (id INTEGER NOT NULL, name CHAR (64) NOT NULL
my $drop1 = 'DROP TABLE table1'; my $drop1 = 'DROP TABLE table1';
my $drop2 = 'DROP TABLE table2'; my $drop2 = 'DROP TABLE table2';
# diag("Parent starting... ($$)"); # diag("Parent connecting... ($$)\n");
my $dbh = connect_ok();
# Create the tables ok( $dbh->do($create1), $create1 );
SCOPE: { ok( $dbh->do($create2), $create2 );
my $dbh = DBI->connect('dbi:SQLite:dbname=foo', '', '') or die 'connect failed'; ok( $dbh->disconnect, '->disconnect ok' );
$dbh->do($create1) or die '$create1 failed';
$dbh->do($create2) or die '$create2 failed';
$dbh->disconnect or die 'disconnect failed';
}
my $pid; my $pid;
# diag("Forking... ($$)"); # diag("Forking... ($$)");
@ -33,25 +29,29 @@ if ( not defined( $pid = fork() ) ) {
die("fork: $!"); die("fork: $!");
} elsif ( $pid == 0 ) { } elsif ( $pid == 0 ) {
# Child process # Pause to let the parent connect
sleep(2);
# diag("Child starting... ($$)"); # diag("Child starting... ($$)");
my $dbh = connect_ok(); my $dbh = DBI->connect(
ok( $dbh->do($drop2), $drop2 ); 'dbi:SQLite:dbname=foo', '', ''
ok( $dbh->disconnect, '->disconnect ok' ); ) or die 'connect failed';
$dbh->do($drop2) or die "DROP ok";
$dbh->disconnect or die "disconnect ok";
# diag("Child exiting... ($$)"); # diag("Child exiting... ($$)");
exit(0); exit(0);
} else { }
SCOPE: {
# Parent process # Parent process
# diag("Waiting for child... ($$)"); # diag("Waiting for child... ($$)");
ok( waitpid($pid, 0) != -1, "waitpid" ); ok( waitpid($pid, 0) != -1, "waitpid" );
}
# Make sure the child actually deleted table2 # Make sure the child actually deleted table2
SCOPE: {
my $dbh = connect_ok(); my $dbh = connect_ok();
ok( $dbh->do($drop1), $drop1 ); ok( $dbh->do($drop1), $drop1 ) or diag("Error: '$DBI::errstr'");
ok( $dbh->do($create2), $create2 ); ok( $dbh->do($create2), $create2 ) or diag("Error: '$DBI::errstr'");
ok( $dbh->disconnect, '->disconnect ok' ); ok( $dbh->disconnect, '->disconnect ok' );
} }