forked from hankhero/cl-json
-
Notifications
You must be signed in to change notification settings - Fork 5
/
test-cl-json.lisp
57 lines (49 loc) · 1.93 KB
/
test-cl-json.lisp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
(defpackage testing-cl-json
(:use common-lisp))
(in-package :testing-cl-json)
(require :asdf)
(asdf:initialize-source-registry '(:source-registry (:directory :here)
:inherit-configuration))
(defun leave-lisp (message return)
(fresh-line *error-output*)
(when message
(format *error-output* message)
(terpri *error-output*))
(finish-output *error-output*)
(finish-output *standard-output*)
(uiop:quit return))
(defmacro quit-on-error (&body body)
`(call-quitting-on-error (lambda () ,@body)))
(defun call-quitting-on-error (thunk)
"Unless the environment variable DEBUG_CL_JSON_TEST
is bound, write a message and exit on an error. If
*asdf-test-debug* is true, enter the debugger."
(flet ((quit (c desc)
(format *error-output* "~&Encountered ~a during test.~%~a~%" desc c)
(cond
;; decline to handle the error.
((ignore-errors (funcall (find-symbol "GETENV" :asdf) "DEBUG_CL_JSON_TEST"))
(format t "~&Interactive mode (DEBUG_CL_JSON_TEST) -- Invoke debugger.~%")
(invoke-debugger c))
(t
(finish-output *standard-output*)
(finish-output *trace-output*)
(format *error-output* "~&ABORTING:~% ~S~%" c)
(uiop:print-condition-backtrace c)
(format *error-output* "~&ABORTING:~% ~S~%" c)
(finish-output *error-output*)
(leave-lisp "~&Script failed~%" 1)))))
(handler-bind
((error (lambda (c)
(quit c "ERROR")))
(storage-condition
(lambda (c) (quit c "STORAGE-CONDITION")))
(serious-condition (lambda (c)
(quit c "Other SERIOUS-CONDIITON"))))
(funcall thunk)
(format t "~&Script succeeded~%")
t)))
(quit-on-error
(format t "~&;;; Testing CL-JSON on ~a.~%" (lisp-implementation-type))
(asdf:test-system "cl-json"))
(uiop:quit 0)