Skip to content

Commit

Permalink
[t/99-common.pl] add many tests, many being skipped currently
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin Berends committed Jun 2, 2010
1 parent 31bd2b7 commit 312bbbc
Show file tree
Hide file tree
Showing 4 changed files with 118 additions and 9 deletions.
3 changes: 2 additions & 1 deletion Makefile
Expand Up @@ -26,7 +26,8 @@ lib/FakeDBI.pir: lib/FakeDBI.pm6 lib/FakeDBD/CSV.pir lib/FakeDBD/mysql.pir
export PERL6LIB=lib; $(PERL6_EXE) --target=pir --output=lib/FakeDBI.pir lib/FakeDBI.pm6

test: lib/FakeDBI.pir lib/FakeDBD/CSV.pir lib/FakeDBD/mysql.pir
export PERL6LIB=lib; prove --exec $(PERL6_EXE) t/05-CSV.t
@#export PERL6LIB=lib; prove --exec $(PERL6_EXE) t/20-CSV-common.t
export PERL6LIB=lib; prove --exec $(PERL6_EXE) t/25-mysql-common.t
export PERL6LIB=lib; prove --exec $(PERL6_EXE) t/10-mysql.t

# standard install is to the shared system wide directory
Expand Down
6 changes: 2 additions & 4 deletions lib/FakeDBD/CSV.pm6
Expand Up @@ -19,7 +19,7 @@ grammar FakeDBD::CSV::SQL {
token column_type {:i int|char|numeric}
}

class FakeDBD::CSV::SQL_Actions {
class FakeDBD::CSV::SQL::actions {
method create_table(Match $m) { print "doing CREATE TABLE ";
say ~$m<table_name> }
method drop_table(Match $m) { print "doing DROP TABLE ";
Expand All @@ -36,7 +36,7 @@ class FakeDBD::CSV::StatementHandle does FakeDBD::StatementHandle {
method execute(*@params is copy) {
#say "executing: $!sql_command";
my $result = FakeDBD::CSV::SQL.parse( $!sql_command,
:actions( FakeDBD::CSV::SQL_Actions ) );
:actions( FakeDBD::CSV::SQL::actions ) );
return Bool::True;
}
}
Expand Down Expand Up @@ -69,8 +69,6 @@ class FakeDBD::CSV:auth<mberends>:ver<0.0.1> {
}
}

#warn "module FakeDBD::CSV.pm has loaded";

=begin pod
=head1 SEE ALSO
Expand Down
68 changes: 68 additions & 0 deletions lib/FakeDBI.pm6
@@ -1,6 +1,7 @@
# FakeDBI.pm6

class FakeDBI:auth<mberends>:ver<0.0.1> {
has $!err;
has $!errstr;
method connect( $dsn, $username, $password, :$RaiseError=0, :$PrintError=0, :$AutoCommit=1 ) {
# warn "in FakeDBI.connect('$dsn')";
Expand Down Expand Up @@ -30,12 +31,79 @@ class FakeDBI:auth<mberends>:ver<0.0.1> {
}
return $driver;
}
# TODO: revise error reporting to conform better to Perl 5 DBI
method err() {
return $!err; # currently always returns an undefined value
}
method errstr() {
# avoid returning an undefined value
return $!errstr // ''; # // confuses a P5 syntax highlighter
}
}

# The following list of SQL constants was produced by the following
# adaptation of the EXPORT_TAGS suggestion in 'perldoc DBI':
# perl -MDBI -e'for (@{ $DBI::EXPORT_TAGS{sql_types} })
# { printf "our sub %s { %d }\n", $_, &{"DBI::$_"}; }'
our sub SQL_GUID { -11 }
our sub SQL_WLONGVARCHAR { -10 }
our sub SQL_WVARCHAR { -9 }
our sub SQL_WCHAR { -8 }
our sub SQL_BIGINT { -5 }
our sub SQL_BIT { -7 }
our sub SQL_TINYINT { -6 }
our sub SQL_LONGVARBINARY { -4 }
our sub SQL_VARBINARY { -3 }
our sub SQL_BINARY { -2 }
our sub SQL_LONGVARCHAR { -1 }
our sub SQL_UNKNOWN_TYPE { 0 }
our sub SQL_ALL_TYPES { 0 }
our sub SQL_CHAR { 1 }
our sub SQL_NUMERIC { 2 }
our sub SQL_DECIMAL { 3 }
our sub SQL_INTEGER { 4 }
our sub SQL_SMALLINT { 5 }
our sub SQL_FLOAT { 6 }
our sub SQL_REAL { 7 }
our sub SQL_DOUBLE { 8 }
our sub SQL_DATETIME { 9 }
our sub SQL_DATE { 9 }
our sub SQL_INTERVAL { 10 }
our sub SQL_TIME { 10 }
our sub SQL_TIMESTAMP { 11 }
our sub SQL_VARCHAR { 12 }
our sub SQL_BOOLEAN { 16 }
our sub SQL_UDT { 17 }
our sub SQL_UDT_LOCATOR { 18 }
our sub SQL_ROW { 19 }
our sub SQL_REF { 20 }
our sub SQL_BLOB { 30 }
our sub SQL_BLOB_LOCATOR { 31 }
our sub SQL_CLOB { 40 }
our sub SQL_CLOB_LOCATOR { 41 }
our sub SQL_ARRAY { 50 }
our sub SQL_ARRAY_LOCATOR { 51 }
our sub SQL_MULTISET { 55 }
our sub SQL_MULTISET_LOCATOR { 56 }
our sub SQL_TYPE_DATE { 91 }
our sub SQL_TYPE_TIME { 92 }
our sub SQL_TYPE_TIMESTAMP { 93 }
our sub SQL_TYPE_TIME_WITH_TIMEZONE { 94 }
our sub SQL_TYPE_TIMESTAMP_WITH_TIMEZONE { 95 }
our sub SQL_INTERVAL_YEAR { 101 }
our sub SQL_INTERVAL_MONTH { 102 }
our sub SQL_INTERVAL_DAY { 103 }
our sub SQL_INTERVAL_HOUR { 104 }
our sub SQL_INTERVAL_MINUTE { 105 }
our sub SQL_INTERVAL_SECOND { 106 }
our sub SQL_INTERVAL_YEAR_TO_MONTH { 107 }
our sub SQL_INTERVAL_DAY_TO_HOUR { 108 }
our sub SQL_INTERVAL_DAY_TO_MINUTE { 109 }
our sub SQL_INTERVAL_DAY_TO_SECOND { 110 }
our sub SQL_INTERVAL_HOUR_TO_MINUTE { 111 }
our sub SQL_INTERVAL_HOUR_TO_SECOND { 112 }
our sub SQL_INTERVAL_MINUTE_TO_SECOND { 113 }

=begin pod
=head1 SYNOPSIS
# the list is from Perl 5 DBI, uncommented is working here
Expand Down
50 changes: 46 additions & 4 deletions t/99-common.pl6
Expand Up @@ -6,7 +6,7 @@
#use FakeDBI;

diag "Testing FakeDBD::$mdriver";
plan 9;
plan 21;

# Verify that the driver loads before attempting a connect
my $drh = FakeDBI.install_driver($mdriver);
Expand All @@ -15,15 +15,16 @@ my $drh_version;
$drh_version = $drh.Version;
ok $drh_version > 0, "FakeDBD::$mdriver version $drh_version"; # test 2

# Connect to the data source
# Connect to the data sourcequantity*price AS amount FROM nom
my $dbh = FakeDBI.connect( $test_dsn, $test_user, $test_password );
ok $dbh, "connect to $test_dsn"; # test 3

# Test .prepare() and .execute() a few times while setting things up.
# Drop a table of the same name so that the following create can work.
my $sth = $dbh.prepare("DROP TABLE nom");
my $rc = $sth.execute();
isnt $rc, Bool::True, "do: drop table gave an expected error"; # test 4
isnt $rc, Bool::True, "do: drop table gave an expected error " ~
"(did a previous test not clean up?)"; # test 4

# Create a table
$sth = $dbh.prepare( "
Expand All @@ -40,8 +41,49 @@ skip 1, "err after successful create should be 0";
#is $dbh.err, 0, "err after successful create should be 0"; # test 6
is $dbh.errstr, Any, "errstr after successful create should be Any"; # test 7

ok $dbh.do("DROP TABLE nom"), "final cleanup";
# Insert rows using the various method calls
ok $dbh.do( "
INSERT nom (name, description, quantity, price)
VALUES ( 'BUBH', 'Hot beef burrito', 1, 4.95 )
"), "insert without parameters called from do"; # test 8
skip 1, "rows NYI";
#is $dbh.rows, 1, "simple insert should report 1 row affected"; # test 9
ok $sth = $dbh.prepare( "
INSERT nom (name, description, quantity, price)
VALUES ( ?, ?, ?, ? )
"), "prepare an insert command with parameters"; # test 10
ok $sth.execute('TAFM', 'Mild fish taco', 1, 4.85 ) &&
$sth.execute('BEOM', 'Medium size orange juice', 2, 1.20 ),
"execute twice with parameters"; # test 11
is $sth.rows, 1, "each insert with parameters also reports 1 row affected"; # test 12
skip 2, '$sth.bind_param_array() and $sth.execute_array() NYI';
#ok $sth.bind_param_array( 1, [ 'BEOM', 'Medium size orange juice', 2, 1.20 ] ),
# "bind_param_array"; # test 13
#ok $sth.execute_array( { ArrayTupleStatus => \my @tuple_status } ); # test 14

# Update some rows

# Delete some rows

# Select data using various method calls
ok $sth = $dbh.prepare( "
SELECT name, description, quantity, price, quantity*price AS amount
FROM nom
"), "prepare a select command without parameters"; # test 15
ok $sth.execute(), "execute a prepared select statement without parameters"; # test 16
my $arrayref = $sth.fetchall_arrayref();
is $arrayref.elems, 3, "fetchall_arrayref returns 3 rows"; # test 17
is $arrayref, [ # TODO: numeric columns return as numeric, not string
[ 'BUBH', 'Hot beef burrito', '1', '4.95', '4.95' ],
[ 'TAFM', 'Mild fish taco', '1', '4.85', '4.85' ],
[ 'BEOM', 'Medium size orange juice', '2', '1.20', '2.40' ] ],
"selected data matches what was written"; # test 18
skip 1, "fetchall_hashref NYI";
#my $hashref = $sth.fetchall_hashref();
#ok $hashref ~~ { }; # test 19

# Drop the table when finished, and disconnect
ok $dbh.do("DROP TABLE nom"), "final cleanup";
ok $dbh.disconnect, "disconnect";

# Return an unabiguous sign of successful completion
Expand Down

0 comments on commit 312bbbc

Please sign in to comment.