r8914: rework test suites
authorKevin M. Rosenberg <kevin@rosenberg.net>
Fri, 9 Apr 2004 17:57:14 +0000 (17:57 +0000)
committerKevin M. Rosenberg <kevin@rosenberg.net>
Fri, 9 Apr 2004 17:57:14 +0000 (17:57 +0000)
ChangeLog
TODO
base/database.lisp
base/utils.lisp
classic-tests/package.lisp
classic-tests/tests.lisp
clsql-classic-tests.asd
clsql-tests.asd
debian/changelog
tests/package.lisp
tests/test-init.lisp

index 931ef8c04136c0ee08722b44b96c766fdb994ca2..aad7993a92a207c4da54e47a0ec6b17c989baec2 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,8 +1,13 @@
 10 Apr 2004 Kevin Rosenberg (kevin@rosenberg.net)
        * Version 2.5.1 released:
-       tests/*.lisp: Rework so tests are run
+       tests/*.lisp: Rework so tests are run
        on multiple backends automatically based
-       on the contents of ~/.clsql-tests.config
+       on the contents of ~/.clsql-tests.config.
+       Reuse helper functions from classic-tests.
+       * base/database.lisp: Support connection-spec
+       as string for CONNECT
+       * classic-tests/tests.lisp: Automatically
+       load database backends as needed. 
        
 09 Apr 2004 Kevin Rosenberg (kevin@rosenberg.net)
         * Version 2.5.0 released:
diff --git a/TODO b/TODO
index 35617a879a75dbaa5d561d9c412cb0a13bb3181c..739fe7a658a857b939ef41a52bc4174d95785827 100644 (file)
--- a/TODO
+++ b/TODO
@@ -21,12 +21,6 @@ COMMONSQL SPEC
 
  >> Initialisation and connection 
 
-    CONNECT 
-     o should accept string as connection spec 
-
-    DISCONNECT
-     o should accept string as connection spec 
-
     INITIALIZE-DATABASE-TYPE
      o should initialise appropriate backend 
 
index 78b6faafa2867d7846eeef96675b06e8e0e4d3e1..a7313ebc62fd62b25ea63dcffa6dcea5bada5b18 100644 (file)
@@ -81,6 +81,10 @@ connection.  If make-default is true, then *default-database* is set
 to the new connection, otherwise *default-database is not changed. If
 pool is t the connection will be taken from the general pool, if pool
 is a conn-pool object the connection will be taken from this pool."
+
+  (when (stringp connection-spec)
+    (setq connection-spec (string-to-list-connection-spec connection-spec)))
+  
   (if pool
       (acquire-from-pool connection-spec database-type pool)
       (let* ((db-name (database-name-from-spec connection-spec database-type))
index f123b4feccc885f0ab0ebc2e41b2a2ba01c480b4..3f9ad8a6348862c3dce8723b4cd5dee1d80db835 100644 (file)
       procstr)))
 
 
+(defun delimited-string-to-list (string &optional (separator #\space) 
+                                                 skip-terminal)
+  "Split a string with delimiter, from KMRCL."
+  (declare (optimize (speed 3) (safety 0) (space 0) (compilation-speed 0))
+          (type string string)
+          (type character separator))
+  (do* ((len (length string))
+       (output '())
+       (pos 0)
+       (end (position-char separator string pos len)
+            (position-char separator string pos len)))
+       ((null end)
+       (if (< pos len)
+           (push (subseq string pos) output)
+           (when (or (not skip-terminal) (zerop len))
+             (push "" output)))
+       (nreverse output))
+    (declare (type fixnum pos len)
+            (type (or null fixnum) end))
+    (push (subseq string pos end) output)
+    (setq pos (1+ end))))
+
+(defun string-to-list-connection-spec (str)
+  (let ((at-pos (position #\@ str)))
+    (cond
+      ((and at-pos (> (length str) at-pos))
+       ;; Connection spec is SQL*NET format
+       (append (delimited-string-to-list (subseq str 0 at-pos) #\/)
+              (list (subseq str (1+ at-pos)))))
+      (t
+       (delimited-string-to-list str #\/)))))
index 27d73b9b65c779d69e8f4de99e778b5dc252cd63..b8d23bd1fb0eb97aa00b8df9ae38b1502bdc9b16 100644 (file)
 (in-package #:cl-user)
 
 (defpackage #:clsql-classic-tests
-  (:use #:asdf #:cl #:clsql #:ptester))
+  (:use #:asdf #:cl #:clsql #:ptester)
+  (:export
+   #:*config-pathname*
+   #:+all-db-types+
+   #:conn-specs
+   #:aodbc-spec
+   #:mysql-spec
+   #:postgresql-spec
+   #:postgresql-socket-spec
+   #:sqlite-spec
+   #:read-specs
+   #:db-type-spec
+   #:db-type-ensure-system
+   ))
+
 
 
index 3faed38017313db57c3dddf43e140029ecfd4733..94db68cb643e7d604fac803f8d2e1e397ad6e79f 100644 (file)
 
 ;;; This test suite looks for a configuration file named ".clsql-test.config"
 ;;; located in the users home directory.
-;;;
+;;;; -*- Mode: LISP; Syntax: ANSI-Common-Lisp; Base: 10 -*-
+;;;; *************************************************************************
+;;;; FILE IDENTIFICATION
+;;;;
+;;;; File:    tests.lisp
+;;;; Author: Kevin Rosenberg
+;;;; $Id$
+;;;;
+;;;; This file is part of CLSQL.
+;;;;
+;;;; CLSQL users are granted the rights to distribute and use this software
+;;;; as governed by the terms of the Lisp Lesser GNU Public License
+;;;; (http://opensource.franz.com/preamble.html), also known as the LLGPL.
+;;;; *************************************************************************
+
+;;; You need a file named "~/.clsql-tests.config"
+
 ;;; 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:
                 :name ".clsql-test"
                 :type "config"))
 
+(defvar +all-db-types+
+  #-clisp '(:postgresql :postgresql-socket :sqlite :aodbc :mysql)
+  #+clisp '(:sqlite))
 
 (defclass conn-specs ()
-  ((aodbc-spec :accessor aodbc-spec)
-   (mysql-spec :accessor mysql-spec)
-   (pgsql-spec :accessor pgsql-spec)
-   (pgsql-socket-spec :accessor pgsql-socket-spec)
-   (sqlite-spec :accessor sqlite-spec))
-  (:documentation "Test fixture for CLSQL testing"))
+  ((aodbc-spec :accessor aodbc-spec :initform nil)
+   (mysql-spec :accessor mysql-spec :initform nil)
+   (pgsql-spec :accessor postgresql-spec :initform nil)
+   (pgsql-socket-spec :accessor postgresql-socket-spec :initform nil)
+   (sqlite-spec :accessor sqlite-spec :initform nil))
+  (:documentation "Connection specs for CLSQL testing"))
 
 
 (defun read-specs (&optional (path *config-pathname*))
              (specs (make-instance 'conn-specs)))
          (setf (aodbc-spec specs) (cadr (assoc :aodbc config)))
          (setf (mysql-spec specs) (cadr (assoc :mysql config)))
-         (setf (pgsql-spec specs) (cadr (assoc :postgresql config)))
-         (setf (pgsql-socket-spec specs) 
+         (setf (postgresql-spec specs) (cadr (assoc :postgresql config)))
+         (setf (postgresql-socket-spec specs) 
                (cadr (assoc :postgresql-socket config)))
          (setf (sqlite-spec specs) (cadr (assoc :sqlite config)))
          specs))
       (progn
-       (warn "CLSQL tester config file ~S not found" path)
+       (warn "CLSQL test config file ~S not found" path)
        nil)))
 
-(defmethod mysql-table-test ((test conn-specs))
-  (test-table (mysql-spec test) :mysql))
-
-(defmethod aodbc-table-test ((test conn-specs))
-  (test-table (aodbc-spec test) :aodbc))
-
-(defmethod pgsql-table-test ((test conn-specs))
-  (test-table (pgsql-spec test) :postgresql))
-
-(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)))
 (defun drop-test-table (db)
   (clsql:execute-command "DROP TABLE test_clsql" :database db))
 
+(defun db-type-spec (db-type specs)
+  (let ((accessor (intern (concatenate 'string (symbol-name db-type)
+                                      (symbol-name '#:-spec))
+                         (find-package '#:clsql-classic-tests))))
+    (funcall accessor specs)))
+
+(defun db-type-ensure-system (db-type)
+  (unless (find-package (symbol-name db-type))
+    (asdf:operate 'asdf:load-op
+                 (intern (concatenate 'string
+                                      (symbol-name '#:clsql-)
+                                      (symbol-name db-type))))))
+
 (defun run-tests ()
   (let ((specs (read-specs)))
     (unless specs
       (warn "Not running test because test configuration file is missing")
       (return-from run-tests :skipped))
+    (mysql-low-level specs)
     (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)
-      ))
+      (dolist (db-type +all-db-types+)
+       (let ((spec (db-type-spec db-type specs)))
+         (when spec
+           (db-type-ensure-system db-type)
+           (test-table spec db-type))))))
   t)
index 74f2dfbc36dcfd9eda0539ea263aa388734e6f67..3d2961fa734d1da4104cb27e8326909146e09dbc 100644 (file)
   :licence "Lessor Lisp General Public License"
   :description "Testing suite for CLSQL"
 
-  :depends-on (clsql #-clisp clsql-mysql 
-                    #-clisp clsql-postgresql
-                    #-clisp clsql-postgresql-socket
-                    ptester
-                    #+(and allegro (not allegro-cl-trial)) clsql-aodbc
-                    clsql-sqlite)
+  :depends-on (clsql ptester #-clisp clsql-mysql)
   :components
   ((:module :classic-tests
            :components
index 46e726154adf17570f81e7f28a820227653af1a2..6d44b878a69569a216ff2c2f76611865605d3151 100644 (file)
@@ -16,8 +16,8 @@
 ;;;; ======================================================================
 
 (in-package #:cl-user)
-(defpackage #:clsql-classic-tests-system (:use #:asdf #:cl))
-(in-package #:clsql-classic-tests-system)
+(defpackage #:clsql-tests-system (:use #:asdf #:cl))
+(in-package #:clsql-tests-system)
 
 (defsystem clsql-tests
     :name "CLSQL Tests"
@@ -26,7 +26,7 @@
     :version ""
     :licence ""
     :description "A regression test suite for CLSQL."
-    :depends-on (clsql rt)
+    :depends-on (clsql clsql-classic-tests rt)
     :components 
     ((:module tests
              :serial t
index c230cd67d7ce9eb174013128368df11d1d39f63e..fcb6d455a6e0cb681af0c8e349e90d7ef48a4fca 100644 (file)
@@ -1,3 +1,9 @@
+cl-sql (2.5.1-1) unstable; urgency=low
+
+  * New upstream
+
+ -- Kevin M. Rosenberg <kmr@debian.org>  Fri,  9 Apr 2004 11:56:38 -0600
+
 cl-sql (2.5.0-1) unstable; urgency=low
 
   * New upstream
index f3858d33be766859b12f0ed7e5c005c50d24b8a0..a4333f141b40d7930bb737ea42e0aad8e7bb2a10 100644 (file)
@@ -17,6 +17,6 @@
 (in-package #:cl-user)
 
 (defpackage #:clsql-tests
-  (:use #:clsql #:common-lisp #:rtest)
+  (:use #:clsql #:common-lisp #:rtest #:clsql-classic-tests)
   (:export #:run-tests #:test-initialise-database #:test-connect-to-database)
   (:documentation "Regression tests for CLSQL."))
index 80bd6b323760a401d14150b3a6daf5f2fc57a07f..89b6ce204ff7638aa5d1ba8e1ba23ee42a364931 100644 (file)
 
 (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*)
   (clsql:update-records-from-instance employee10)
   (clsql:update-records-from-instance company1))
 
-(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))))
+    (dolist (db-type +all-db-types+)
+      (let ((spec (db-type-spec db-type specs)))
        (when spec
-         (format t "~&Running CLSQL tests with ~A backend.~%" backend)
-         (test-connect-to-database backend spec)
+         (db-type-ensure-system db-type)
+         (rt:rem-all-tests)
+         (dolist (test (append *rt-connection* *rt-fddl* *rt-fdml*
+                               *rt-ooddl* *rt-oodml* *rt-syntax*))
+           (eval test))
+         (format t "~&Running CLSQL tests with ~A backend.~%" db-type)
+         (test-connect-to-database db-type 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)))
-