-
Notifications
You must be signed in to change notification settings - Fork 0
/
test0.arc
65 lines (54 loc) · 1.63 KB
/
test0.arc
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
60
61
62
63
64
65
; todo not sure about these names
(assign test-verbose* t)
(def test-iso3 (desc result expected)
(if (equal-wrt-testing expected result)
(when test-verbose*
(do (pr "ok " desc " => ")
(write result)
(prn)))
(do (pr "FAIL " desc " => ")
(write result)
(pr ", not the expected result ")
(write expected)
(prn)
(err "test failed"))))
(mac test-iso2 (expr expected)
`(test-iso3 ',expr ,expr ,expected))
(mac test-iso args
(if (is (len args) 2)
`(test-iso2 ,(args 0) ,(args 1))
`(test-iso3 ,(args 0) ,(args 1) ,(args 2))))
(mac catcherr body
`(on-err idfn (fn () ,@body)))
(def makeerr (msg)
(catcherr (err msg)))
; lexical marker to run code as a test instead of
; including in the runtime
(mac test-marker body
`(do ,@body))
(mac testis (expr expected)
`(test-iso (tostring (write ',expr)) (catcherr ,expr) ,expected))
(mac testf (input f qf expected)
(w/uniq (gexpected gresult)
`(with (,gexpected ,expected
,gresult (catcherr (,f ,input)))
(test-iso (tostring (write ',input) (pr " ") (write ',qf))
,gresult ,gexpected))))
(mac testt (expr)
`(if ,expr
(do (pr "ok ")
(write ',expr)
(pr " is true\n"))
(do (pr "FAIL ")
(write ',expr)
(pr " is nil\n")
(err "test failed"))))
(mac testnil (expr)
`(if (no ,expr)
(do (pr "ok ")
(write ',expr)
(pr " is nil\n"))
(do (pr "FAIL ")
(write ',expr)
(pr " is not nil\n")
(err "test failed"))))