r9450: 22 May 2004 Kevin Rosenberg
[clsql.git] / tests / utils.lisp
1 ;;; -*- Mode: LISP; Syntax: ANSI-Common-Lisp; Base: 10 -*-
2 ;;;; *************************************************************************
3 ;;;; FILE IDENTIFICATION
4 ;;;;
5 ;;;; Name:    utils.lisp
6 ;;;; Purpose: Classes and utilities for testing
7 ;;;; Author:  Kevin M. Rosenberg
8 ;;;; Created: Mar 2002
9 ;;;;
10 ;;;; $Id$
11 ;;;;
12 ;;;; This file, part of CLSQL, is Copyright (c) 2002-2004 by Kevin M. Rosenberg
13 ;;;;
14 ;;;; CLSQL users are granted the rights to distribute and use this software
15 ;;;; as governed by the terms of the Lisp Lesser GNU Public License
16 ;;;; (http://opensource.franz.com/preamble.html), also known as the LLGPL.
17 ;;;; *************************************************************************
18
19 (in-package #:clsql-tests)
20
21 (defvar *config-pathname*
22   (make-pathname :defaults (user-homedir-pathname)
23                  :name ".clsql-test"
24                  :type "config"))
25
26 (defvar +all-db-types+
27     #-clisp '(:postgresql :postgresql-socket :mysql :sqlite :odbc :oracle
28               #+allegro :aodbc)
29     #+clisp '(:sqlite))
30
31 (defclass conn-specs ()
32   ((aodbc :accessor aodbc-spec :initform nil)
33    (mysql :accessor mysql-spec :initform nil)
34    (postgresql :accessor postgresql-spec :initform nil)
35    (postgresql-socket :accessor postgresql-socket-spec :initform nil)
36    (sqlite :accessor sqlite-spec :initform nil)
37    (odbc :accessor odbc-spec :initform nil)
38    (oracle :accessor oracle-spec :initform nil))
39   (:documentation "Connection specs for CLSQL testing"))
40
41
42 (defun read-specs (&optional (path *config-pathname*))
43   (if (probe-file path)
44       (with-open-file (stream path :direction :input)
45         (let ((specs (make-instance 'conn-specs)))
46           (dolist (spec (read stream) specs)
47             (push (second spec)
48                   (slot-value specs (intern (symbol-name (first spec))
49                                             (find-package '#:clsql-tests)))))))
50       (progn
51         (warn "CLSQL test config file ~S not found" path)
52         nil)))
53
54 (defun spec-fn (db-type)
55   (intern (concatenate 'string (symbol-name db-type)
56                        (symbol-name '#:-spec))
57           (find-package '#:clsql-tests)))
58
59 (defun db-type-spec (db-type specs)
60   (funcall (spec-fn db-type) specs))
61
62
63 (defun summarize-test-report (sexp &optional (output *standard-output*))
64   (flet ((db-title (db-type underlying-db-type)
65            (format nil "~A~A"
66                    db-type 
67                    (if (eq db-type underlying-db-type)
68                        ""
69                        (format nil "/~A" underlying-db-type)))))
70     (with-open-file (in sexp :direction :input)
71       (let ((eof (cons nil nil)))
72         (do ((form (read in nil eof) (read in nil eof)))
73             ((eq form eof))
74           (destructuring-bind (db-type
75                                underlying-db-type
76                                utime
77                                total-tests
78                                failed-tests
79                                impl-type
80                                impl-version
81                                machine-type)
82               form
83             (declare (ignorable utime impl-version))
84             (if failed-tests
85                 (format output "~&~A: ~D of ~D tests failed (~A, ~A).~&"
86                         (db-title db-type underlying-db-type)
87                         (length failed-tests)
88                         total-tests
89                         machine-type
90                         impl-type)
91                 (format output "~&~A: All ~D tests passed (~A, ~A).~%"
92                         (db-title db-type underlying-db-type)
93                         total-tests
94                         machine-type
95                         impl-type))))))))