]> asedeno.scripts.mit.edu Git - cl-protobufs.git/blob - tests/qtest.lisp
Make the schema printer aware of qualified names.
[cl-protobufs.git] / tests / qtest.lisp
1 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2 ;;;                                                                  ;;;
3 ;;; Free Software published under an MIT-like license. See LICENSE   ;;;
4 ;;;                                                                  ;;;
5 ;;; Copyright (c) 2012 Google, Inc.  All rights reserved.            ;;;
6 ;;;                                                                  ;;;
7 ;;; Original author: Scott McKay                                     ;;;
8 ;;;                                                                  ;;;
9 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
10
11 (in-package "PROTO-TEST")
12
13
14 ;;; Ultra light-weight test framework
15
16 (defmacro define-test (test-name () &body body)
17   `(defun ,test-name ()
18      (handler-case
19          (progn ,@body)
20        (error (e)
21          (warn "An error was signalled executing ~S: ~A"
22                ',test-name e)))))
23
24 (defmacro define-test-suite (suite-name () &body body)
25   (if (listp (car body))
26     ;; QRes-style body
27     `(defun ,suite-name ()
28        ,@(loop for test in (car body)
29                collect (list test)))
30     ;; The more sensible style
31     `(defun ,suite-name ()
32        ,@(loop for test in body
33                collect (list test)))))
34
35 (defvar *all-registered-tests* ())
36 (defmacro register-test (test-name)
37   `(pushnew ',test-name *all-registered-tests*))
38
39 (defmacro run-test (test-name)
40   `(progn
41      (format t "~&Running test ~A" ',test-name)
42      (funcall ',test-name)))
43
44 (defun run-all-tests ()
45   (dolist (test *all-registered-tests*)
46     (format t "~&Running test ~A" test)
47     (funcall test)))
48
49 (defmacro assert-equal (actual expected &key (test 'eql))
50   `(unless (,test ,actual ,expected)
51      (warn "The value ~S is not equal to the expected value ~S"
52            ',actual ',expected)))
53
54 (defmacro assert-true (form)
55   `(unless ,form
56      (warn "The value ~S does not evaluate to 'true'"
57            ',form)))
58
59 (defmacro assert-false (form)
60   `(when ,form
61      (warn "The value ~S does not evaluate to 'false'"
62            ',form)))