Generate an error in the internal tests.
[lisp-unit.git] / internal-test / fundamental-assertions.lisp
blobfdc4a9dc9707bc6c886433b8b0cfca22da4d136e
1 #|
3 LISP-UNIT Internal Tests
5 Copyright (c) 2010-2016, Thomas M. Hermann
7 Permission is hereby granted, free of charge, to any person obtaining
8 a copy of this software and associated documentation files (the "Software"),
9 to deal in the Software without restriction, including without limitation
10 the rights to use, copy, modify, merge, publish, distribute, sublicense,
11 and/or sell copies of the Software, and to permit persons to whom the
12 Software is furnished to do so, subject to the following conditions:
14 The above copyright notice and this permission notice shall be included
15 in all copies or substantial portions of the Software.
17 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18 OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
21 OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
22 ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
23 OTHER DEALINGS IN THE SOFTWARE.
27 (in-package :lisp-unit)
29 ;;; Internal utility functions
31 (defun %expansion-equal (form1 form2)
32 "Descend into the forms checking for equality."
33 (let ((item1 (first form1))
34 (item2 (first form2)))
35 (cond
36 ((and (null item1) (null item2)))
37 ((and (listp item1) (listp item2))
38 (and (%expansion-equal item1 item2)
39 (%expansion-equal (rest form1) (rest form2))))
40 ((and (symbolp item1) (symbolp item2))
41 (and (string= (symbol-name item1) (symbol-name item2))
42 (%expansion-equal (rest form1) (rest form2))))
43 (t nil))))
45 (defun expansion-equal (macro-form expansion)
46 "MACROEXPAND-1 the macro-form and compare with the expansion."
47 (let ((*gensym-counter* 1))
48 (%expansion-equal (macroexpand-1 macro-form) expansion)))
50 (defun test-macro-expansions (expansions)
51 "Test each fundamental assertion and report the results."
52 (loop for (assertion macro-form expansion) in expansions collect
53 (list assertion (expansion-equal macro-form expansion))))
55 ;;; Expansions
57 (defvar *expand-assert-expansions*
58 '(("EXPAND-ASSERT-BASIC"
59 (expand-assert
60 :equal form form expected (extra1 extra2) :test #'eq)
61 (INTERNAL-ASSERT :EQUAL
62 (QUOTE FORM)
63 (LAMBDA NIL FORM)
64 (LAMBDA NIL EXPECTED)
65 (EXPAND-EXTRAS (EXTRA1 EXTRA2))
66 (FUNCTION EQ)))
67 ("EXPAND-ASSERT-ERROR"
68 (expand-assert
69 :error form (expand-error-form form) condition (extra1 extra2))
70 (INTERNAL-ASSERT :ERROR
71 (QUOTE FORM)
72 (LAMBDA NIL (HANDLER-CASE FORM (CONDITION (ERROR) ERROR)))
73 (LAMBDA NIL (QUOTE CONDITION))
74 (EXPAND-EXTRAS (EXTRA1 EXTRA2))
75 (FUNCTION EQL)))
76 ("EXPAND-ASSERT-MACRO"
77 (expand-assert
78 :macro form
79 (expand-macro-form form nil)
80 expansion (extra1 extra2))
81 (INTERNAL-ASSERT :MACRO
82 (QUOTE FORM)
83 (LAMBDA NIL (MACROEXPAND-1 (QUOTE FORM) NIL))
84 (LAMBDA NIL EXPANSION)
85 (EXPAND-EXTRAS (EXTRA1 EXTRA2))
86 (FUNCTION EQL)))
87 ("EXPAND-ASSERTS-PRINT"
88 (expand-assert
89 :output form (expand-output-form form) output (extra1 extra2))
90 (INTERNAL-ASSERT :OUTPUT
91 (QUOTE FORM)
92 (LAMBDA NIL
93 (LET* ((#:G1 (MAKE-STRING-OUTPUT-STREAM))
94 (*STANDARD-OUTPUT* (MAKE-BROADCAST-STREAM
95 *STANDARD-OUTPUT* #:G1)))
96 FORM
97 (GET-OUTPUT-STREAM-STRING #:G1)))
98 (LAMBDA NIL OUTPUT)
99 (EXPAND-EXTRAS (EXTRA1 EXTRA2))
100 (FUNCTION EQL))))
101 "The correct expansions for the expand-assert macro.")
103 (defvar *expansion-macros*
104 '(("EXPAND-ERROR-FORM"
105 (expand-error-form form)
106 (HANDLER-CASE FORM (CONDITION (ERROR) ERROR)))
107 ("EXPAND-OUTPUT-FORM"
108 (expand-output-form form)
109 (LET* ((#:G1 (MAKE-STRING-OUTPUT-STREAM))
110 (*STANDARD-OUTPUT*
111 (MAKE-BROADCAST-STREAM *STANDARD-OUTPUT* #:G1)))
112 FORM
113 (GET-OUTPUT-STREAM-STRING #:G1)))
114 ("EXPAND-MACRO-FORM"
115 (expand-macro-form form env)
116 (MACROEXPAND-1 'FORM ENV))
117 ("EXPAND-EXTRAS"
118 (expand-extras (extra1 extra2))
119 (LAMBDA NIL (LIST (QUOTE EXTRA1) EXTRA1 (QUOTE EXTRA2) EXTRA2))))
120 "The correct expansions for macros that expand forms.")
122 (defvar *fundamental-assertion-expansions*
123 '(("ASSERT-EQ"
124 (assert-eq expected form extra1 extra2)
125 (EXPAND-ASSERT
126 :EQUAL FORM FORM EXPECTED (EXTRA1 EXTRA2) :TEST (FUNCTION EQ)))
127 ("ASSERT-EQL"
128 (assert-eql expected form extra1 extra2)
129 (EXPAND-ASSERT
130 :EQUAL FORM FORM EXPECTED (EXTRA1 EXTRA2) :TEST (FUNCTION EQL)))
131 ("ASSERT-EQUAL"
132 (assert-equal expected form extra1 extra2)
133 (EXPAND-ASSERT
134 :EQUAL FORM FORM EXPECTED (EXTRA1 EXTRA2) :TEST (FUNCTION EQUAL)))
135 ("ASSERT-EQUALP"
136 (assert-equalp expected form extra1 extra2)
137 (EXPAND-ASSERT
138 :EQUAL FORM FORM EXPECTED (EXTRA1 EXTRA2) :TEST (FUNCTION EQUALP)))
139 ("ASSERT-ERROR"
140 (assert-error 'condition form extra1 extra2)
141 (EXPAND-ASSERT
142 :ERROR FORM (EXPAND-ERROR-FORM FORM) 'CONDITION (EXTRA1 EXTRA2)))
143 ("ASSERT-EXPANDS"
144 (assert-expands expansion form extra1 extra2)
145 (EXPAND-ASSERT
146 :MACRO FORM (EXPAND-MACRO-FORM FORM NIL) EXPANSION (EXTRA1 EXTRA2)))
147 ("ASSERT-FALSE"
148 (assert-false form extra1 extra2)
149 (EXPAND-ASSERT :RESULT FORM FORM NIL (EXTRA1 EXTRA2)))
150 ("ASSERT-EQUALITY"
151 (assert-equality test expected form extra1 extra2)
152 (EXPAND-ASSERT
153 :EQUAL FORM FORM EXPECTED (EXTRA1 EXTRA2) :TEST TEST))
154 ("ASSERT-PRINTS"
155 (assert-prints output form extra1 extra2)
156 (EXPAND-ASSERT
157 :OUTPUT FORM (expand-output-form form) OUTPUT (EXTRA1 EXTRA2)))
158 ("ASSERT-TRUE"
159 (assert-true form extra1 extra2)
160 (EXPAND-ASSERT :RESULT FORM FORM T (EXTRA1 EXTRA2))))
161 "The correct expansions for the fundamental assertions.")