eb10ec33fe989ae5cd7751f0bd4a48af1ea63972
[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   '(:postgresql :postgresql-socket :mysql :sqlite :odbc :oracle
28     #+allegro :aodbc))
29
30 (defclass conn-specs ()
31   ((aodbc :accessor aodbc-spec :initform nil)
32    (mysql :accessor mysql-spec :initform nil)
33    (postgresql :accessor postgresql-spec :initform nil)
34    (postgresql-socket :accessor postgresql-socket-spec :initform nil)
35    (sqlite :accessor sqlite-spec :initform nil)
36    (odbc :accessor odbc-spec :initform nil)
37    (oracle :accessor oracle-spec :initform nil))
38   (:documentation "Connection specs for CLSQL testing"))
39
40
41 (defun read-specs (&optional (path *config-pathname*))
42   (if (probe-file path)
43       (with-open-file (stream path :direction :input)
44         (let ((specs (make-instance 'conn-specs)))
45           (dolist (spec (read stream) specs)
46             (push (second spec)
47                   (slot-value specs (intern (symbol-name (first spec))
48                                             (find-package '#:clsql-tests)))))))
49       (progn
50         (warn "CLSQL test config file ~S not found" path)
51         nil)))
52
53 (defun spec-fn (db-type)
54   (intern (concatenate 'string (symbol-name db-type)
55                        (symbol-name '#:-spec))
56           (find-package '#:clsql-tests)))
57
58 (defun db-type-spec (db-type specs)
59   (funcall (spec-fn db-type) specs))
60
61
62 (defun summarize-test-report (sexp &optional (output *standard-output*))
63   (flet ((db-title (db-type underlying-db-type)
64            (format nil "~A~A"
65                    db-type 
66                    (if (eq db-type underlying-db-type)
67                        ""
68                        (format nil "/~A" underlying-db-type)))))
69     (with-open-file (in sexp :direction :input)
70       (let ((eof (cons nil nil)))
71         (do ((form (read in nil eof) (read in nil eof)))
72             ((eq form eof))
73           (destructuring-bind (db-type
74                                underlying-db-type
75                                utime
76                                total-tests
77                                failed-tests
78                                impl-type
79                                impl-version
80                                machine-type)
81               form
82             (declare (ignorable utime impl-version))
83             (if failed-tests
84                 (format output "~&~A: ~D of ~D tests failed (~A, ~A).~&"
85                         (db-title db-type underlying-db-type)
86                         (length failed-tests)
87                         total-tests
88                         machine-type
89                         impl-type)
90                 (format output "~&~A: All ~D tests passed (~A, ~A).~%"
91                         (db-title db-type underlying-db-type)
92                         total-tests
93                         machine-type
94                         impl-type))))))))