/
tests.lisp
60 lines (50 loc) · 2.31 KB
/
tests.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
58
59
(in-package :cl-mustache-test)
(defun walk-directory (directory pattern)
(directory (merge-pathnames pattern directory)))
(defvar *spec-directory* #P"~/cl/cl-mustache/mustache.spec/")
(defvar *all-specs*
(mapcar #'cl-mustache::utf8-json-decode (walk-directory *spec-directory* "specs/*.json")))
(fiveam:def-suite :mustache-specs)
(fiveam:in-suite :mustache-specs)
(defmacro mustache-spawn-test-suite (specs)
`(progn
,@(loop
for spec in (eval specs)
append (loop
for test across (cdr (assoc "tests" spec :test #'equalp))
for name = (cdr (assoc "name" test :test #'equalp))
for template = (cdr (assoc "template" test :test #'equalp))
for data = (cdr (assoc "data" test :test #'equalp))
for expected = (cdr (assoc "expected" test :test #'equalp))
for desc = (cdr (assoc "desc" test :test #'equalp))
for partial = (cdr (assoc "partials" test :test #'equalp))
collect `(fiveam:test ,(intern name) ,desc
(fiveam:is (string= ,expected (mustache-render ,template ',data ',partial))))))))
(defun pretty-result (test-result)
(flet ((result-type (result) (format nil "~(~A~)" (symbol-name (type-of result)))))
(let ((test-case (fiveam::test-case test-result)))
(list (symbol-name (fiveam::name test-case))
(fiveam::description test-case)
(result-type test-result)))))
(defvar *results*)
(defun run-tests ()
(mustache-spawn-test-suite *all-specs*)
(setf *results* (fiveam:run :mustache-specs))
(with-open-file (stream #P"~/public_html/results.html"
:direction :output :if-exists :supersede)
(cl-who:with-html-output (stream)
(:style :type "text/css"
".test-passed { background-color: #0f0; }"
".test-failure { background-color: #f00; }"
".unexpected-test-failure { background-color: #ff0; }")
(:table
(loop
for (name description result) in (mapcar #'pretty-result *results*)
do (cl-who:htm
(:tr
(:td (cl-who:fmt name))
(:td (cl-who:fmt description))
(:td :class result (cl-who:fmt result))))))))
'ook)
(defun explain ()
(fiveam:explain! *results*))