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