summary refs log tree commit diff
path: root/lib/test.fnl
blob: fbaaf8d26dae9719b49521b7234a18e19f4f1039 (plain)
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
(local {: pprint} (require :lib.tableprint))
(local {: equal} (require :lib.equal))

(var plan 0)

(fn once [funky]
  (var bang false)
  (fn [...]
    (if (not bang)
      (do
        (funky ...)
        (set bang true)))))

(fn test [obj]
  (let [{: given : should : actual : expected} obj
        ok (if (equal actual expected) :ok "not ok")
        description (.. "Given " given " should " should)
        ]
    (set plan (+ 1 plan))
    (print (.. ok " " plan " - " description))
    (if (= "not ok" ok)
      (do
        (print "  ---")
        (if (= :table (type expected))
          (do
            (print (.. "  expected: " ))
            (pprint expected))
          (print (.. "  expected: " (tostring expected))))
        (if (= :table (type actual))
          (do
            (print (.. "  actual: " ))
            (pprint actual))
          (print (.. "  actual: " (tostring actual))))
        (print "  ...")
        )
      )
    ))

(local print-header (once (fn [] (print "TAP version 14"))))

(fn desc [str cb]
  (print-header)
  (print (.. "#" str))
  (cb test)
  )
(fn end []
  (print (.. 1 ".." plan))
  )


{:describe desc
 : end}