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

DBD-SQLite: added "use strict"s (and some "use vars"s and "my"s) to the tests

This commit is contained in:
Kenichi Ishigaki 2009-04-02 11:04:42 +00:00
parent 9bdfb9c0bb
commit fbedeb1a93
24 changed files with 68 additions and 22 deletions

View file

@ -1,3 +1,4 @@
use strict;
use Test; use Test;
BEGIN { plan tests => 5 } BEGIN { plan tests => 5 }
use DBI; use DBI;

View file

@ -1,3 +1,4 @@
use strict;
use Test; use Test;
use DBI; use DBI;
BEGIN { plan tests => 11 } BEGIN { plan tests => 11 }

View file

@ -1,3 +1,4 @@
use strict;
use Test; use Test;
BEGIN { plan tests => 21 } BEGIN { plan tests => 21 }
use DBI; use DBI;

View file

@ -1,3 +1,4 @@
use strict;
use Test; use Test;
BEGIN { plan tests => 2 } BEGIN { plan tests => 2 }
use DBI; use DBI;

View file

@ -1,3 +1,4 @@
use strict;
use Test; use Test;
BEGIN { plan tests => 2 } BEGIN { plan tests => 2 }
use DBI; use DBI;

View file

@ -1,5 +1,6 @@
#!perl #!perl
use strict;
use Test; use Test;
BEGIN { plan tests => 8 } BEGIN { plan tests => 8 }
use DBI; use DBI;

View file

@ -6,13 +6,15 @@
# after listdsn. # after listdsn.
# #
use strict;
use vars qw($test_dsn $test_user $test_password $mdriver $state);
# #
# Include lib.pl # Include lib.pl
# #
require DBI; require DBI;
$mdriver = ""; $mdriver = "";
foreach $file ("lib.pl", "t/lib.pl", "DBD-~DBD_DRIVER~/t/lib.pl") { foreach my $file ("lib.pl", "t/lib.pl", "DBD-~DBD_DRIVER~/t/lib.pl") {
do $file; if ($@) { print STDERR "Error while executing lib.pl: $@\n"; do $file; if ($@) { print STDERR "Error while executing lib.pl: $@\n";
exit 10; exit 10;
} }
@ -39,18 +41,18 @@ sub ServerError() {
# #
# Main loop; leave this untouched, put tests into the loop # Main loop; leave this untouched, put tests into the loop
# #
my @dsn;
while (Testing()) { while (Testing()) {
# Check if the server is awake. # Check if the server is awake.
$dbh = undef; my $dbh = undef;
Test($state or ($dbh = DBI->connect($test_dsn, $test_user, Test($state or ($dbh = DBI->connect($test_dsn, $test_user,
$test_password))) $test_password)))
or ServerError(); or ServerError();
Test($state or (@dsn = DBI->data_sources($mdriver)) >= 0); Test($state or (@dsn = DBI->data_sources($mdriver)) >= 0);
if (!$state) { if (!$state) {
my $d;
print "List of $mdriver data sources:\n"; print "List of $mdriver data sources:\n";
foreach $d (@dsn) { foreach my $d (@dsn) {
print " $d\n"; print " $d\n";
} }
print "List ends.\n"; print "List ends.\n";
@ -67,8 +69,7 @@ while (Testing()) {
"DBI:$mdriver:test;localhost", "DBI:$mdriver:test;localhost",
"DBI:$mdriver:database=test;host=localhost"); "DBI:$mdriver:database=test;host=localhost");
} }
my($dsn); foreach my $dsn (@dsnList) {
foreach $dsn (@dsnList) {
Test($state or ($dbh = DBI->connect($dsn, $test_user, Test($state or ($dbh = DBI->connect($dsn, $test_user,
$test_password))) $test_password)))
or print "Cannot connect to DSN $dsn: ${DBI::errstr}\n"; or print "Cannot connect to DSN $dsn: ${DBI::errstr}\n";

View file

@ -6,6 +6,7 @@ BEGIN {
} }
} }
use strict;
use Test::More tests => 8; use Test::More tests => 8;
use DBI; use DBI;
use Encode qw/decode/; use Encode qw/decode/;
@ -27,7 +28,7 @@ my @words = qw/berger Berg
fétu fête fève ferme/; fétu fête fève ferme/;
# my @words_utf8 = map {decode("iso-8859-1", $_)} @words; # my @words_utf8 = map {decode("iso-8859-1", $_)} @words;
@words_utf8 = @words; my @words_utf8 = @words;
utf8::upgrade($_) foreach @words_utf8; utf8::upgrade($_) foreach @words_utf8;

View file

@ -1,3 +1,4 @@
use strict;
use Test; use Test;
BEGIN { plan tests => 3; } BEGIN { plan tests => 3; }
use DBI; use DBI;

View file

@ -4,6 +4,9 @@
# #
# This is a simple insert/fetch test. # This is a simple insert/fetch test.
# #
use strict;
use vars qw($test_dsn $test_user $test_password $mdriver $state);
$^W = 1; $^W = 1;
# #
@ -19,7 +22,7 @@ $test_password = '';
# #
use DBI; use DBI;
$mdriver = ""; $mdriver = "";
foreach $file ("lib.pl", "t/lib.pl", "DBD-~DBD_DRIVER~/t/lib.pl") { foreach my $file ("lib.pl", "t/lib.pl", "DBD-~DBD_DRIVER~/t/lib.pl") {
do $file; if ($@) { print STDERR "Error while executing lib.pl: $@\n"; do $file; if ($@) { print STDERR "Error while executing lib.pl: $@\n";
exit 10; exit 10;
} }
@ -42,6 +45,7 @@ sub ServerError() {
# Main loop; leave this untouched, put tests after creating # Main loop; leave this untouched, put tests after creating
# the new table. # the new table.
# #
my ($dbh, $def, $table, $cursor);
while (Testing()) { while (Testing()) {
# #

View file

@ -6,6 +6,8 @@
# and modify/extend it. # and modify/extend it.
# #
use strict;
use vars qw($test_dsn $test_user $test_password $mdriver $state);
$^W = 1; $^W = 1;
# #
@ -22,7 +24,7 @@ $test_password = '';
require DBI; require DBI;
use vars qw($COL_NULLABLE); use vars qw($COL_NULLABLE);
$mdriver = ""; $mdriver = "";
foreach $file ("lib.pl", "t/lib.pl") { foreach my $file ("lib.pl", "t/lib.pl") {
do $file; if ($@) { print STDERR "Error while executing lib.pl: $@\n"; do $file; if ($@) { print STDERR "Error while executing lib.pl: $@\n";
exit 10; exit 10;
} }
@ -57,6 +59,7 @@ if (!defined(&SQL_INTEGER)) {
# Main loop; leave this untouched, put tests after creating # Main loop; leave this untouched, put tests after creating
# the new table. # the new table.
# #
my ($dbh, $def, $table, $cursor, $id, $name, $ref);
while (Testing()) { while (Testing()) {
# #
# Connect to the database # Connect to the database

View file

@ -6,6 +6,8 @@
# is expected to work correctly. # is expected to work correctly.
# #
use strict;
use vars qw($test_dsn $test_user $test_password $mdriver $dbdriver $state);
$^W = 1; $^W = 1;
@ -24,7 +26,7 @@ $test_password = '';
use DBI qw(:sql_types); use DBI qw(:sql_types);
$mdriver = ""; $mdriver = "";
foreach $file ("lib.pl", "t/lib.pl") { foreach my $file ("lib.pl", "t/lib.pl") {
do $file; if ($@) { print STDERR "Error while executing lib.pl: $@\n"; do $file; if ($@) { print STDERR "Error while executing lib.pl: $@\n";
exit 10; exit 10;
} }
@ -74,6 +76,7 @@ sub ShowBlob($) {
# Main loop; leave this untouched, put tests after creating # Main loop; leave this untouched, put tests after creating
# the new table. # the new table.
# #
my ($dbh, $table, $cursor, $row);
while (Testing()) { while (Testing()) {
# #
# Connect to the database # Connect to the database
@ -90,7 +93,7 @@ while (Testing()) {
or DbiError($dbh->error, $dbh->errstr); or DbiError($dbh->error, $dbh->errstr);
my($def); my($def);
foreach $size (128) { foreach my $size (128) {
# #
# Create a new table # Create a new table
# #
@ -110,10 +113,10 @@ while (Testing()) {
my ($blob, $qblob) = ""; my ($blob, $qblob) = "";
if (!$state) { if (!$state) {
my $b = ""; my $b = "";
for ($j = 0; $j < 256; $j++) { for (my $j = 0; $j < 256; $j++) {
$b .= chr($j); $b .= chr($j);
} }
for ($i = 0; $i < $size; $i++) { for (my $i = 0; $i < $size; $i++) {
$blob .= $b; $blob .= $b;
} }
if ($mdriver eq 'pNET') { if ($mdriver eq 'pNET') {

View file

@ -1,5 +1,6 @@
#!/usr/bin/perl -w #!/usr/bin/perl -w
use strict;
use Test; use Test;
BEGIN { plan tests => 26 } BEGIN { plan tests => 26 }
use DBI; use DBI;

View file

@ -5,6 +5,8 @@
# This is a test for statement attributes being present appropriately. # This is a test for statement attributes being present appropriately.
# #
use strict;
use vars qw($test_dsn $test_user $test_password $mdriver $dbdriver $state $COL_KEY $COL_NULLABLE);
# #
# Make -w happy # Make -w happy
@ -22,7 +24,7 @@ use DBI;
use vars qw($verbose); use vars qw($verbose);
$dbdriver = ""; $dbdriver = "";
foreach $file ("lib.pl", "t/lib.pl") { foreach my $file ("lib.pl", "t/lib.pl") {
do $file; if ($@) { print STDERR "Error while executing lib.pl: $@\n"; do $file; if ($@) { print STDERR "Error while executing lib.pl: $@\n";
exit 10; exit 10;
} }
@ -32,7 +34,7 @@ foreach $file ("lib.pl", "t/lib.pl") {
} }
@table_def = ( my @table_def = (
["id", "INTEGER", 4, $COL_KEY], ["id", "INTEGER", 4, $COL_KEY],
["name", "CHAR", 64, $COL_NULLABLE] ["name", "CHAR", 64, $COL_NULLABLE]
); );
@ -51,6 +53,7 @@ sub ServerError() {
# Main loop; leave this untouched, put tests after creating # Main loop; leave this untouched, put tests after creating
# the new table. # the new table.
# #
my ($dbh, $table, $def, $cursor, $ref);
while (Testing()) { while (Testing()) {
# #
# Connect to the database # Connect to the database
@ -90,7 +93,7 @@ while (Testing()) {
or DbiError($cursor->err, $cursor->errstr); or DbiError($cursor->err, $cursor->errstr);
if (!$state && $verbose) { if (!$state && $verbose) {
print "Names:\n"; print "Names:\n";
for ($i = 0; $i < @$ref; $i++) { for (my $i = 0; $i < @$ref; $i++) {
print " ", $$ref[$i], "\n"; print " ", $$ref[$i], "\n";
} }
} }
@ -103,7 +106,7 @@ while (Testing()) {
or DbiError($cursor->err, $cursor->errstr); or DbiError($cursor->err, $cursor->errstr);
if (!$state && $verbose) { if (!$state && $verbose) {
print "Nullable:\n"; print "Nullable:\n";
for ($i = 0; $i < @$ref; $i++) { for (my $i = 0; $i < @$ref; $i++) {
print " ", ($$ref[$i] & $COL_NULLABLE) ? "yes" : "no", "\n"; print " ", ($$ref[$i] & $COL_NULLABLE) ? "yes" : "no", "\n";
} }
} }

View file

@ -5,6 +5,8 @@
# This is a test for correctly handling NULL values. # This is a test for correctly handling NULL values.
# #
use strict;
use vars qw($test_dsn $test_user $test_password $mdriver $dbdriver $state);
# #
# Make -w happy # Make -w happy
@ -21,7 +23,7 @@ use DBI;
use vars qw($COL_NULLABLE); use vars qw($COL_NULLABLE);
$mdriver = ""; $mdriver = "";
foreach $file ("lib.pl", "t/lib.pl") { foreach my $file ("lib.pl", "t/lib.pl") {
do $file; if ($@) { print STDERR "Error while executing lib.pl: $@\n"; do $file; if ($@) { print STDERR "Error while executing lib.pl: $@\n";
exit 10; exit 10;
} }
@ -44,6 +46,7 @@ sub ServerError() {
# Main loop; leave this untouched, put tests after creating # Main loop; leave this untouched, put tests after creating
# the new table. # the new table.
# #
my ($dbh, $table, $def, $cursor, $rv);
while (Testing()) { while (Testing()) {
# #
# Connect to the database # Connect to the database

View file

@ -5,6 +5,9 @@
# This tests, whether the number of rows can be retrieved. # This tests, whether the number of rows can be retrieved.
# #
use strict;
use vars qw($test_dsn $test_user $test_password $mdriver $state);
$^W = 1; $^W = 1;
$| = 1; $| = 1;
@ -22,7 +25,7 @@ $test_password = '';
# #
use DBI; use DBI;
$mdriver = ""; $mdriver = "";
foreach $file ("lib.pl", "t/lib.pl", "DBD-~DBD_DRIVER~/t/lib.pl") { foreach my $file ("lib.pl", "t/lib.pl", "DBD-~DBD_DRIVER~/t/lib.pl") {
do $file; if ($@) { print STDERR "Error while executing lib.pl: $@\n"; do $file; if ($@) { print STDERR "Error while executing lib.pl: $@\n";
exit 10; exit 10;
} }
@ -56,6 +59,7 @@ sub TrueRows($) {
# Main loop; leave this untouched, put tests after creating # Main loop; leave this untouched, put tests after creating
# the new table. # the new table.
# #
my ($dbh, $table, $def, $cursor, $numrows);
while (Testing()) { while (Testing()) {
# #
# Connect to the database # Connect to the database

View file

@ -6,6 +6,9 @@
# http://rt.cpan.org/Public/Bug/Display.html?id=15186 # http://rt.cpan.org/Public/Bug/Display.html?id=15186
# About re-using statements with prepare_cached(). # About re-using statements with prepare_cached().
use strict;
use vars qw($test_dsn $test_user $test_password $mdriver $state);
$^W = 1; $^W = 1;
$| = 1; $| = 1;
@ -23,7 +26,7 @@ $test_password = '';
# #
use DBI; use DBI;
$mdriver = ""; $mdriver = "";
foreach $file ("lib.pl", "t/lib.pl", "DBD-~DBD_DRIVER~/t/lib.pl") { foreach my $file ("lib.pl", "t/lib.pl", "DBD-~DBD_DRIVER~/t/lib.pl") {
do $file; if ($@) { print STDERR "Error while executing lib.pl: $@\n"; do $file; if ($@) { print STDERR "Error while executing lib.pl: $@\n";
exit 10; exit 10;
} }
@ -57,6 +60,7 @@ sub TrueRows($) {
# Main loop; leave this untouched, put tests after creating # Main loop; leave this untouched, put tests after creating
# the new table. # the new table.
# #
my ($dbh, $table, $def, $cursor, $sth);
while (Testing()) { while (Testing()) {
# #
# Connect to the database # Connect to the database

View file

@ -5,6 +5,7 @@
# This driver should check whether 'ChopBlanks' works. # This driver should check whether 'ChopBlanks' works.
# #
use strict;
# #
# Make -w happy # Make -w happy

View file

@ -4,6 +4,10 @@
# #
# This is testing the transaction support. # This is testing the transaction support.
# #
use strict;
use vars qw($test_dsn $test_user $test_password $mdriver $state);
$^W = 1; $^W = 1;
@ -12,7 +16,7 @@ $^W = 1;
# #
require DBI; require DBI;
$mdriver = ""; $mdriver = "";
foreach $file ("lib.pl", "t/lib.pl") { foreach my $file ("lib.pl", "t/lib.pl") {
do $file; if ($@) { print STDERR "Error while executing lib.pl: $@\n"; do $file; if ($@) { print STDERR "Error while executing lib.pl: $@\n";
exit 10; exit 10;
} }
@ -58,6 +62,7 @@ sub NumRows($$$) {
# Main loop; leave this untouched, put tests after creating # Main loop; leave this untouched, put tests after creating
# the new table. # the new table.
# #
my ($dbh, $def, $table, $msg);
while (Testing()) { while (Testing()) {
# #
# Connect to the database # Connect to the database
@ -105,7 +110,7 @@ while (Testing()) {
Test($state or $dbh->do("INSERT INTO $table VALUES (1, 'Jochen')")) Test($state or $dbh->do("INSERT INTO $table VALUES (1, 'Jochen')"))
or ErrMsgF("Failed to insert value: err %s, errstr %s.\n", or ErrMsgF("Failed to insert value: err %s, errstr %s.\n",
$dbh->err, $dbh->errstr); $dbh->err, $dbh->errstr);
my $msg;
Test($state or !($msg = NumRows($dbh, $table, 1))) Test($state or !($msg = NumRows($dbh, $table, 1)))
or ErrMsg($msg); or ErrMsg($msg);
Test($state or $dbh->rollback) Test($state or $dbh->rollback)

View file

@ -1,3 +1,4 @@
use strict;
use Test; use Test;
BEGIN { plan tests => 27 } BEGIN { plan tests => 27 }
use DBI; use DBI;

View file

@ -1,3 +1,4 @@
use strict;
use Test; use Test;
use DBI; use DBI;
use Fatal qw(open); use Fatal qw(open);

View file

@ -1,3 +1,4 @@
use strict;
use Test; use Test;
BEGIN { plan tests => 2 } BEGIN { plan tests => 2 }
ok(-e 'foo'); ok(-e 'foo');

View file

@ -4,6 +4,7 @@
# #
# database specific definitions for a 'CSV' database # database specific definitions for a 'CSV' database
use strict;
# This function generates a mapping of ANSI type names to # This function generates a mapping of ANSI type names to
# database specific type names; it is called by TableDefinition(). # database specific type names; it is called by TableDefinition().

View file

@ -6,6 +6,8 @@
# and modify/extend it. # and modify/extend it.
# #
use strict;
$^W = 1; $^W = 1;
$| = 1; $| = 1;