X-Git-Url: http://git.kpe.io/?a=blobdiff_plain;f=tests%2Ftests.lisp;h=76d0dd9f4c935ab9bfda4bdbfadeb18e3d1add69;hb=0196e0db0edccccab4cd8a0d6309e768a98667fd;hp=e426ca2f53626e5ae174a181c9f1515e7475250b;hpb=0e7a7ec4320a2ffcffad1dfc74e461a337c4ca6b;p=clsql.git diff --git a/tests/tests.lisp b/tests/tests.lisp index e426ca2..76d0dd9 100644 --- a/tests/tests.lisp +++ b/tests/tests.lisp @@ -7,7 +7,7 @@ ;;;; Programmer: Kevin M. Rosenberg ;;;; Date Started: Mar 2002 ;;;; -;;;; $Id: tests.lisp,v 1.2 2003/05/02 03:17:41 kevin Exp $ +;;;; $Id$ ;;;; ;;;; This file, part of CLSQL, is Copyright (c) 2002 by Kevin M. Rosenberg ;;;; @@ -26,7 +26,8 @@ ;;; ((:mysql ("localhost" "a-mysql-db" "user1" "secret")) ;;; (:aodbc ("my-dsn" "a-user" "pass")) ;;; (:postgresql ("localhost" "another-db" "user2" "dont-tell")) -;;; (:postgresql-socket ("pg-server" "a-db-name" "user" "secret-password"))) +;;; (:postgresql-socket ("pg-server" "a-db-name" "user" "secret-password")) +;;; (:sqlite ("path-to-sqlite-db"))) (in-package :clsql-tests) @@ -40,7 +41,8 @@ ((aodbc-spec :accessor aodbc-spec) (mysql-spec :accessor mysql-spec) (pgsql-spec :accessor pgsql-spec) - (pgsql-socket-spec :accessor pgsql-socket-spec)) + (pgsql-socket-spec :accessor pgsql-socket-spec) + (sqlite-spec :accessor sqlite-spec)) (:documentation "Test fixture for CLSQL testing")) @@ -54,8 +56,11 @@ (setf (pgsql-spec specs) (cadr (assoc :postgresql config))) (setf (pgsql-socket-spec specs) (cadr (assoc :postgresql-socket config))) + (setf (sqlite-spec specs) (cadr (assoc :sqlite config))) specs)) - (error "CLSQL tester config file ~S not found" path))) + (progn + (warn "CLSQL tester config file ~S not found" path) + nil))) (defmethod mysql-table-test ((test conn-specs)) (test-table (mysql-spec test) :mysql)) @@ -69,6 +74,9 @@ (defmethod pgsql-socket-table-test ((test conn-specs)) (test-table (pgsql-socket-spec test) :postgresql-socket)) +(defmethod sqlite-table-test ((test conn-specs)) + (test-table (sqlite-spec test) :sqlite)) + (defmethod test-table (spec type) (when spec (let ((db (clsql:connect spec :database-type type :if-exists :new))) @@ -103,8 +111,32 @@ ) (disconnect :database db))))) +;;; +;;; SQLite is typeless: execute untyped tests only. +;;; +(defmethod test-table (spec (type (eql :sqlite))) + (when spec + (let ((db (clsql:connect spec :database-type type :if-exists :new))) + (unwind-protect + (progn + (create-test-table db) + (dolist (row (query "select * from test_clsql" :database db :types nil)) + (test-table-row row nil type)) + (loop for row across (map-query 'vector #'list "select * from test_clsql" + :database db :types nil) + do (test-table-row row nil type)) + (loop for row in (map-query 'list #'list "select * from test_clsql" + :database db :types nil) + do (test-table-row row nil type)) + + (do-query ((int float bigint str) "select * from test_clsql") + (test-table-row (list int float bigint str) nil type)) + (drop-test-table db) + ) + (disconnect :database db))))) (defmethod mysql-low-level ((test conn-specs)) + #-clisp (let ((spec (mysql-spec test))) (when spec (let ((db (clsql-mysql::database-connect spec :mysql))) @@ -195,11 +227,12 @@ (test t nil :fail-info (format nil "Invalid types field (~S) passed to test-table-row" types)))) - (test (transform-float-1 int) - float - :test #'eql - :fail-info - (format nil "Wrong float value ~A for int ~A (row ~S)" float int row)) + (unless (eq db-type :sqlite) ; SQLite is typeless. + (test (transform-float-1 int) + float + :test #'eql + :fail-info + (format nil "Wrong float value ~A for int ~A (row ~S)" float int row))) (test float (parse-double str) :test #'double-float-equal @@ -220,18 +253,18 @@ (defun drop-test-table (db) (clsql:execute-command "DROP TABLE test_clsql" :database db)) -(defun clsql-tests () +(defun run-tests () (let ((specs (read-specs))) + (unless specs + (warn "Not running test because test configuration file is missing") + (return-from run-tests :skipped)) (with-tests (:name "CLSQL") (mysql-low-level specs) (mysql-table-test specs) (pgsql-table-test specs) (pgsql-socket-table-test specs) (aodbc-table-test specs) + (sqlite-table-test specs) )) t) -(deftest clsql.all (clsql-tests) t) - - -