r8910: rework so that tests are automatically run for multiple backends
authorKevin M. Rosenberg <kevin@rosenberg.net>
Fri, 9 Apr 2004 16:17:55 +0000 (16:17 +0000)
committerKevin M. Rosenberg <kevin@rosenberg.net>
Fri, 9 Apr 2004 16:17:55 +0000 (16:17 +0000)
ChangeLog
TODO
clsql-tests.asd
tests/README
tests/test-connection.lisp
tests/test-fddl.lisp
tests/test-fdml.lisp
tests/test-init.lisp
tests/test-ooddl.lisp
tests/test-oodml.lisp
tests/test-syntax.lisp

index e54a205f4fc68546565dedf232cf3dfe6246e94c..931ef8c04136c0ee08722b44b96c766fdb994ca2 100644 (file)
--- 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 d6950a663595e7c2c2696d576dc1c6ffd525180e..35617a879a75dbaa5d561d9c412cb0a13bb3181c 100644 (file)
--- 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.
 
index 7a7d6d9b6da392e320c9f469a68ebba098e334cb..46e726154adf17570f81e7f28a820227653af1a2 100644 (file)
@@ -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")))
index 51876c19c1932074c0fda8a0f1c783bd786217b4..f93cfa99081e7493a5095ed0b40831ab384f2d09 100644 (file)
@@ -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
 
index 625899c417969e0fcc643d1eceb7f2c59d6ff80f..2952444743c80c1f763573d56c1a037e48b785c8 100644 (file)
 
 (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)
+
+))
index e45d04e103a702aa5346e536330feebf07d8b873..918c56f878ca0b964f701527437c82512274df6c 100644 (file)
@@ -18,6 +18,9 @@
 
 #.(clsql:locally-enable-sql-reader-syntax)
 
+(setq *rt-fddl*
+      '(
+      
 ;; list current tables 
 (deftest :fddl/table/1
     (apply #'values 
         (clsql:drop-sequence [foo] :if-does-not-exist :ignore)))
   6)
 
+))
+
 #.(clsql:restore-sql-reader-syntax-state)
index 6387add49165652c626756569f5ede511a80c775..ef364ba40b8eb80c4414792409133491e394660b 100644 (file)
@@ -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
             (apply #'values (nreverse results)))))))
   nil nil ("lenin@soviet.org"))
 
+))
+
 #.(clsql:restore-sql-reader-syntax-state)
index 5dd6775a7834978b05f8456d081728971c7d534b..80bd6b323760a401d14150b3a6daf5f2fc57a07f 100644 (file)
@@ -1,7 +1,7 @@
 ;;;; -*- Mode: LISP; Syntax: ANSI-Common-Lisp; Base: 10 -*-
 ;;;; ======================================================================
 ;;;; File:    test-init.lisp
-;;;; Author:  Marcus Pearce <m.t.pearce@city.ac.uk>
+;;;; Authors: Marcus Pearce <m.t.pearce@city.ac.uk>, Kevin Rosenberg
 ;;;; Created: 30/03/2004
 ;;;; Updated: $Id$
 ;;;; ======================================================================
 ;;;;
 ;;;; ======================================================================
 
+;;; 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)))
                                   :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))
   (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)))
 
index 11d17135bdaeda7d89d745103fb3959719ba710b..7089eba9b437b3de0b68f908bc26ad487b959249 100644 (file)
@@ -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)
+
index f64da4153ecec06db703740fb110eb1e1fd82f5d..cf9eda715d8253792e934cf2dec313f8ca46a44e 100644 (file)
@@ -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]))
 ;          collect (slot-value e 'last-name))
 ;  ("Lenin" "Stalin" "Trotsky"))
 
+))
 
 #.(clsql:restore-sql-reader-syntax-state)
index 1725b9a9169965a431c58eb40171b5cc5387db4b..62fe3f33803283f59303c8fa32c2cfb036311081 100644 (file)
@@ -17,7 +17,9 @@
 
 #.(clsql:locally-enable-sql-reader-syntax)
 
-
+(setq *rt-syntax*
+      '(
+       
 (deftest :syntax/generic/1
     (clsql:sql "foo")
   "'foo'")
                                              :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)