;;;; Authors: Marcus Pearce <m.t.pearce@city.ac.uk>, Kevin Rosenberg
;;;; Created: 30/03/2004
;;;; Updated: $Id$
-;;;; ======================================================================
-;;;;
-;;;; Description ==========================================================
-;;;; ======================================================================
;;;;
;;;; Initialisation utilities for running regression tests on CLSQL.
;;;;
;;;; ======================================================================
-;;; 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*)
(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))))
+ (load-necessary-systems specs)
+ (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)
- (test-initialise-database)
- (rtest:do-tests))))))
+ (do-tests-for-backend spec db-type))))))
+
+(defun load-necessary-systems (specs)
+ (dolist (db-type +all-db-types+)
+ (when (db-type-spec db-type specs)
+ (db-type-ensure-system db-type))))
-(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)))
+(defun do-tests-for-backend (spec db-type)
+ (format t
+ "~&
+*******************************************************************
+*** Running CLSQL tests with ~A backend.
+*******************************************************************
+" db-type)
+ (regression-test:rem-all-tests)
+
+ ;; Tests of clsql-base
+ (ignore-errors (destroy-database spec :database-type db-type))
+ (ignore-errors (create-database spec :database-type db-type))
+ (with-tests (:name "CLSQL")
+ (test-basic spec db-type))
+
+ (ignore-errors (destroy-database spec :database-type db-type))
+ (ignore-errors (create-database spec :database-type db-type))
+ (dolist (test (append *rt-connection* *rt-fddl* *rt-fdml*
+ *rt-ooddl* *rt-oodml* *rt-syntax*))
+ (eval test))
+ (test-connect-to-database db-type spec)
+ (test-initialise-database)
+ (rtest:do-tests))