From 70227e5f0b76bb649fc6c1a478d7374953fd815b Mon Sep 17 00:00:00 2001 From: "Kevin M. Rosenberg" Date: Fri, 9 Apr 2004 16:17:55 +0000 Subject: [PATCH] r8910: rework so that tests are automatically run for multiple backends --- ChangeLog | 6 ++ TODO | 3 +- clsql-tests.asd | 2 - tests/README | 27 +++------ tests/test-connection.lisp | 6 +- tests/test-fddl.lisp | 5 ++ tests/test-fdml.lisp | 5 ++ tests/test-init.lisp | 109 ++++++++++++++++++++++++++----------- tests/test-ooddl.lisp | 6 ++ tests/test-oodml.lisp | 4 ++ tests/test-syntax.lisp | 8 ++- 11 files changed, 122 insertions(+), 59 deletions(-) diff --git a/ChangeLog b/ChangeLog index e54a205..931ef8c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +10 Apr 2004 Kevin Rosenberg (kevin@rosenberg.net) + * Version 2.5.1 released: + tests/*.lisp: Rework so tests are run + on multiple backends automatically based + on the contents of ~/.clsql-tests.config + 09 Apr 2004 Kevin Rosenberg (kevin@rosenberg.net) * Version 2.5.0 released: All tests for CLSQL and CLSQL-CLASSIC pass diff --git a/TODO b/TODO index d6950a6..35617a8 100644 --- a/TODO +++ b/TODO @@ -1,7 +1,6 @@ GENERAL -* test on (and port to) openmcl and mcl. SCL no longer affordable to - individuals; +* test on mcl. SCL no longer affordable to individuals; * implement remaining functions for CLSQL AODBC backend; * port Oracle and ODBC backend to UFFI. diff --git a/clsql-tests.asd b/clsql-tests.asd index 7a7d6d9..46e7261 100644 --- a/clsql-tests.asd +++ b/clsql-tests.asd @@ -40,8 +40,6 @@ (:file "test-syntax"))))) (defmethod perform ((o test-op) (c (eql (find-system 'clsql-tests)))) - (error "Automated performing of test-op is not yet supported.") - #+ignore (unless (funcall (intern (symbol-name '#:run-tests) (find-package '#:clsql-tests))) (error "test-op failed"))) diff --git a/tests/README b/tests/README index 51876c1..f93cfa9 100644 --- a/tests/README +++ b/tests/README @@ -1,28 +1,15 @@ * RUNNING THE REGRESSION SUITE -Just load clsql.asd or put it somewhere where ASDF can find it -and call: - -(asdf:oos 'asdf:load-op 'clsql) - -You'll then need to load a CLSQL backend before you can do anything. +Create a .clsql-tests.config file in your home directory. +See test-init.lisp for the structure of the data. -To run the regression tests load clsql-tests.asd or put it -somewhere where ASDF can find it, edit the file tests/test-init.lisp -and set the following variables to appropriate values: - - *test-database-server* - *test-database-name* - *test-database-user* - *test-database-password* - -And then call: +Load clsql.asd or put it somewhere where ASDF can find it +and call: -(asdf:oos 'asdf:load-op 'clsql-tests) -(clsql-tests:run-tests BACKEND) +(asdf:oos 'asdf:test-op 'clsql) -where BACKEND is the CLSQL database interface to use (currently one of -:postgresql, :postgresql-socket, :sqlite or :mysql). +The test suite will then automatically run on all of the backends that +you have defined in .clsql-tests.config * REGRESSION TEST SUITE GOALS diff --git a/tests/test-connection.lisp b/tests/test-connection.lisp index 625899c..2952444 100644 --- a/tests/test-connection.lisp +++ b/tests/test-connection.lisp @@ -15,10 +15,14 @@ (in-package #:clsql-tests) - +(setq *rt-connection* + '( + (deftest :connection/1 (let ((database (clsql:find-database (clsql:database-name clsql:*default-database*) :db-type (clsql:database-type clsql:*default-database*)))) (eql (clsql:database-type database) *test-database-type*)) t) + +)) diff --git a/tests/test-fddl.lisp b/tests/test-fddl.lisp index e45d04e..918c56f 100644 --- a/tests/test-fddl.lisp +++ b/tests/test-fddl.lisp @@ -18,6 +18,9 @@ #.(clsql:locally-enable-sql-reader-syntax) +(setq *rt-fddl* + '( + ;; list current tables (deftest :fddl/table/1 (apply #'values @@ -208,4 +211,6 @@ (clsql:drop-sequence [foo] :if-does-not-exist :ignore))) 6) +)) + #.(clsql:restore-sql-reader-syntax-state) diff --git a/tests/test-fdml.lisp b/tests/test-fdml.lisp index 6387add..ef364ba 100644 --- a/tests/test-fdml.lisp +++ b/tests/test-fdml.lisp @@ -18,6 +18,9 @@ #.(clsql:locally-enable-sql-reader-syntax) +(setq *rt-fdml* + '( + ;; inserts a record using all values only and then deletes it (deftest :fdml/insert/1 (progn @@ -392,4 +395,6 @@ (apply #'values (nreverse results))))))) nil nil ("lenin@soviet.org")) +)) + #.(clsql:restore-sql-reader-syntax-state) diff --git a/tests/test-init.lisp b/tests/test-init.lisp index 5dd6775..80bd6b3 100644 --- a/tests/test-init.lisp +++ b/tests/test-init.lisp @@ -1,7 +1,7 @@ ;;;; -*- Mode: LISP; Syntax: ANSI-Common-Lisp; Base: 10 -*- ;;;; ====================================================================== ;;;; File: test-init.lisp -;;;; Author: Marcus Pearce +;;;; Authors: Marcus Pearce , Kevin Rosenberg ;;;; Created: 30/03/2004 ;;;; Updated: $Id$ ;;;; ====================================================================== @@ -13,13 +13,35 @@ ;;;; ;;;; ====================================================================== +;;; This test suite looks for a configuration file named ".clsql-test.config" +;;; located in the users home directory. +;;; +;;; This file contains a single a-list that specifies the connection +;;; specs for each database type to be tested. For example, to test all +;;; platforms, a sample "test.config" may look like: +;;; +;;; ((: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")) +;;; (:sqlite ("path-to-sqlite-db"))) + (in-package #:clsql-tests) +(defvar *config-pathname* + (make-pathname :defaults (user-homedir-pathname) + :name ".clsql-test" + :type "config")) + +(defvar *rt-connection*) +(defvar *rt-fddl*) +(defvar *rt-fdml*) +(defvar *rt-ooddl*) +(defvar *rt-oodml*) +(defvar *rt-syntax*) + (defvar *test-database-type* nil) -(defvar *test-database-server* "") -(defvar *test-database-name* "") -(defvar *test-database-user* "") -(defvar *test-database-password* "") +(defvar *test-database-user* nil) (defclass thing () ((extraterrestrial :initform nil :initarg :extraterrestrial))) @@ -216,30 +238,13 @@ :last-name "Putin" :email "putin@soviet.org")) -(defun test-database-connection-spec () - (let ((dbserver *test-database-server*) - (dbname *test-database-name*) - (dbpassword *test-database-password*) - (dbtype *test-database-type*) - (username *test-database-user*)) - (case dbtype - (:postgresql - `("" ,dbname ,username ,dbpassword)) - (:postgresql-socket - `(,dbserver ,dbname ,username ,dbpassword)) - (:mysql - `("" ,dbname ,username ,dbpassword)) - (:sqlite - `(,dbname)) - (:oracle - `(,username ,dbpassword ,dbname)) - (t - (error "Unrecognized database type: ~A" dbtype))))) - -(defun test-connect-to-database (database-type) +(defun test-connect-to-database (database-type spec) (setf *test-database-type* database-type) + (when (>= (length spec) 3) + (setq *test-database-user* (third spec))) + ;; Connect to the database - (clsql:connect (test-database-connection-spec) + (clsql:connect spec :database-type database-type :make-default t :if-exists :old)) @@ -306,11 +311,51 @@ (clsql:update-records-from-instance employee10) (clsql:update-records-from-instance company1)) -(defun run-tests (backend) - (format t "~&Running CLSQL tests with ~A backend.~%" backend) - (test-connect-to-database backend) - (test-initialise-database) - (rtest:do-tests)) +(defclass conn-specs () + ((aodbc-spec :accessor aodbc :initform nil) + (mysql-spec :accessor mysql :initform nil) + (pgsql-spec :accessor postgresql :initform nil) + (pgsql-socket-spec :accessor postgresql-socket :initform nil) + (sqlite-spec :accessor sqlite :initform nil)) + (:documentation "Connection specifications for CLSQL testing")) + +(defun run-tests () + (let ((specs (read-specs))) + (unless specs + (warn "Not running tests because test configuration file is missing") + (return-from run-tests :skipped)) + (dolist (accessor '(postgresql postgresql-socket sqlite aodbc mysql)) + (unless (find-package (symbol-name accessor)) + (asdf:operate 'asdf:load-op + (intern (concatenate 'string + (symbol-name '#:clsql-) + (symbol-name accessor))))) + (rt:rem-all-tests) + (dolist (test (append *rt-connection* *rt-fddl* *rt-fdml* + *rt-ooddl* *rt-oodml* *rt-syntax*)) + (eval test)) + (let ((spec (funcall accessor specs)) + (backend (intern (symbol-name accessor) (find-package :keyword)))) + (when spec + (format t "~&Running CLSQL tests with ~A backend.~%" backend) + (test-connect-to-database backend spec) + (test-initialise-database) + (rtest:do-tests)))))) +(defun read-specs (&optional (path *config-pathname*)) + (if (probe-file path) + (with-open-file (stream path :direction :input) + (let ((config (read stream)) + (specs (make-instance 'conn-specs))) + (setf (aodbc specs) (cadr (assoc :aodbc config))) + (setf (mysql specs) (cadr (assoc :mysql config))) + (setf (postgresql specs) (cadr (assoc :postgresql config))) + (setf (postgresql-socket specs) + (cadr (assoc :postgresql-socket config))) + (setf (sqlite specs) (cadr (assoc :sqlite config))) + specs)) + (progn + (warn "CLSQL tester config file ~S not found" path) + nil))) diff --git a/tests/test-ooddl.lisp b/tests/test-ooddl.lisp index 11d1713..7089eba 100644 --- a/tests/test-ooddl.lisp +++ b/tests/test-ooddl.lisp @@ -19,6 +19,9 @@ #.(clsql:locally-enable-sql-reader-syntax) +(setq *rt-ooddl* + '( + ;; Ensure slots inherited from standard-classes are :virtual (deftest :ooddl/metaclass/1 (values @@ -84,4 +87,7 @@ fail-index) -1) +)) + #.(clsql:restore-sql-reader-syntax-state) + diff --git a/tests/test-oodml.lisp b/tests/test-oodml.lisp index f64da41..cf9eda7 100644 --- a/tests/test-oodml.lisp +++ b/tests/test-oodml.lisp @@ -18,6 +18,9 @@ #.(clsql:locally-enable-sql-reader-syntax) +(setq *rt-oodml* + '( + (deftest :oodml/select/1 (mapcar #'(lambda (e) (slot-value e 'last-name)) (clsql:select 'employee :order-by [last-name])) @@ -237,5 +240,6 @@ ; collect (slot-value e 'last-name)) ; ("Lenin" "Stalin" "Trotsky")) +)) #.(clsql:restore-sql-reader-syntax-state) diff --git a/tests/test-syntax.lisp b/tests/test-syntax.lisp index 1725b9a..62fe3f3 100644 --- a/tests/test-syntax.lisp +++ b/tests/test-syntax.lisp @@ -17,7 +17,9 @@ #.(clsql:locally-enable-sql-reader-syntax) - +(setq *rt-syntax* + '( + (deftest :syntax/generic/1 (clsql:sql "foo") "'foo'") @@ -158,5 +160,7 @@ :attribute 'baz) (clsql:sql table)]))) "(BETWEEN(THISTIME.BAR,(HIP * HOP),42) AND (THISTIME.BAZ LIKE 'THISTIME') AND BETWEEN(NEXTTIME.BAR,(HIP * HOP),43) AND (NEXTTIME.BAZ LIKE 'NEXTTIME') AND BETWEEN(SOMETIME.BAR,(HIP * HOP),44) AND (SOMETIME.BAZ LIKE 'SOMETIME') AND BETWEEN(NEVER.BAR,(HIP * HOP),45) AND (NEVER.BAZ LIKE 'NEVER'))") - + +)) + #.(clsql:restore-sql-reader-syntax-state) -- 2.34.1