mirror of
https://github.com/DBD-SQLite/DBD-SQLite
synced 2025-06-07 22:28:47 -04:00
Migrate from lib.pl to t::lib::Test
This commit is contained in:
parent
530cbdb8b4
commit
54682e35e1
1 changed files with 10 additions and 71 deletions
|
@ -9,78 +9,17 @@ BEGIN {
|
||||||
}
|
}
|
||||||
|
|
||||||
use t::lib::Test;
|
use t::lib::Test;
|
||||||
|
use Test::More tests => 5;
|
||||||
|
use Test::NoWarnings;
|
||||||
|
|
||||||
use vars qw($state);
|
# Create a database
|
||||||
|
my $dbh = connect_ok( PrintError => 0 );
|
||||||
|
|
||||||
#
|
# Create a database
|
||||||
# Include lib.pl
|
ok( $dbh->do('CREATE TABLE one ( num INTEGER UNIQUE)'), 'create table' );
|
||||||
#
|
|
||||||
do 't/lib.pl';
|
|
||||||
if ($@) {
|
|
||||||
print STDERR "Error while executing lib.pl: $@\n";
|
|
||||||
exit 10;
|
|
||||||
}
|
|
||||||
|
|
||||||
sub ServerError() {
|
# Insert a row into the test table
|
||||||
print STDERR ("Cannot connect: ", $DBI::errstr, "\n",
|
ok( $dbh->do('INSERT INTO one ( num ) values ( 1 )'), 'insert' );
|
||||||
"\tEither your server is not up and running or you have no\n",
|
|
||||||
"\tpermissions for acessing the DSN 'DBI:SQLite:dbname=foo'.\n",
|
|
||||||
"\tThis test requires a running server and write permissions.\n",
|
|
||||||
"\tPlease make sure your server is running and you have\n",
|
|
||||||
"\tpermissions, then retry.\n");
|
|
||||||
exit 10;
|
|
||||||
}
|
|
||||||
|
|
||||||
#
|
# Insert a duplicate
|
||||||
# Main loop; leave this untouched, put tests after creating
|
ok( ! $dbh->do('INSERT INTO one ( num ) values ( 1 )'), 'duplicate' );
|
||||||
# the new table.
|
|
||||||
#
|
|
||||||
my ($dbh, $def, $table, $cursor);
|
|
||||||
while (Testing()) {
|
|
||||||
|
|
||||||
#
|
|
||||||
# Connect to the database
|
|
||||||
Test($state or $dbh = DBI->connect('DBI:SQLite:dbname=foo', '', ''),
|
|
||||||
'connect')
|
|
||||||
or ServerError();
|
|
||||||
|
|
||||||
#
|
|
||||||
# Find a possible new table name
|
|
||||||
#
|
|
||||||
Test($state or $table = FindNewTable($dbh), 'FindNewTable')
|
|
||||||
or DbiError($dbh->err, $dbh->errstr);
|
|
||||||
|
|
||||||
#
|
|
||||||
# Create a new table; EDIT THIS!
|
|
||||||
#
|
|
||||||
Test($state or ($def = TableDefinition($table,
|
|
||||||
# CREATE TABLE nums (num INTEGER UNIQUE);
|
|
||||||
["num", "INTEGER", 4, 0],
|
|
||||||
) and
|
|
||||||
$dbh->do($def)), 'create', $def)
|
|
||||||
or DbiError($dbh->err, $dbh->errstr);
|
|
||||||
Test($state or ($dbh->do("CREATE UNIQUE INDEX idx_${table}_num ON $table (num)")))
|
|
||||||
or DbiError($dbh->err, $dbh->errstr);
|
|
||||||
|
|
||||||
|
|
||||||
#
|
|
||||||
# Insert a row into the test table.......
|
|
||||||
#
|
|
||||||
Test($state or $dbh->do("INSERT INTO $table (num)"
|
|
||||||
. " VALUES(1)" ), 'insert')
|
|
||||||
or DbiError($dbh->err, $dbh->errstr);
|
|
||||||
|
|
||||||
#
|
|
||||||
# Now try to insert a duplicate
|
|
||||||
#
|
|
||||||
Test($state or !$dbh->do("INSERT INTO $table (num)"
|
|
||||||
. " VALUES(1)" ), 'insert')
|
|
||||||
;
|
|
||||||
|
|
||||||
#
|
|
||||||
# Finally drop the test table.
|
|
||||||
#
|
|
||||||
Test($state or $dbh->do("DROP TABLE $table"), 'drop')
|
|
||||||
or DbiError($dbh->err, $dbh->errstr);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue