-
Notifications
You must be signed in to change notification settings - Fork 128
Expand file tree
/
Copy pathtest.pxi
More file actions
75 lines (56 loc) · 2.12 KB
/
test.pxi
File metadata and controls
75 lines (56 loc) · 2.12 KB
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
66
67
68
69
70
71
72
73
74
75
(ns pixie.test
(require pixie.string :as s))
(def tests (atom {}))
(def ^:dynamic *stats*)
(def ^:dynamic *current-test*)
(defmacro deftest [nm & body]
`(do (defn ~nm []
(println "Running:" (str (namespace (var ~nm)) "/" (name (var ~nm))))
(try
~@body
(swap! *stats* update-in [:pass] (fnil inc 0))
(catch ex
(println "while running" ~(name nm) " " (quote (do ~@body)))
(swap! *stats* update-in [:fail] (fnil inc 0))
(println (str ex))
(swap! *stats* update-in [:errors] (fnil conj []) ex))))
(swap! tests assoc (symbol (str (namespace (var ~nm)) "/" (name (var ~nm)))) ~nm)))
(defn run-tests [& args]
(push-binding-frame!)
(set! (var *stats*) (atom {:fail 0 :pass 0}))
(let [match (or (first args) "")
tests (transduce (comp (filter #(>= (s/index-of (str (key %1)) match) 0))
(map val))
conj
@tests)]
(println "Running:" (count tests) "tests")
(foreach [test tests]
(test)))
(let [stats @*stats*]
(println stats)
(pop-binding-frame!)
stats))
(defn load-all-tests []
(println "Looking for tests...")
(foreach [path @load-paths]
(println "Looking for tests in:" path)
(foreach [desc (pixie.path/file-list path)]
(if (= (nth desc 1) :file)
(let [filename (nth desc 2)]
(if (pixie.string/starts-with filename "test-")
(if (pixie.string/ends-with filename ".pxi")
(let [fullpath (str (nth desc 0) "/" filename)]
(println "Loading" fullpath)
(load-file fullpath)))))))))
(defmacro assert= [x y]
`(let* [xr# ~x
yr# ~y]
(assert (= xr# yr#) (str (show '~x xr#) " != " (show '~y yr#)))))
(defmacro assert [x]
`(let [x# ~x]
(assert x# (str '~x " is " x#))))
(defn show
([orig res]
(if (= orig res)
(pr-str orig)
(str (pr-str orig) " = " (pr-str res)))))