forked from exercism/clojure
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.clj
executable file
·55 lines (46 loc) · 1.83 KB
/
test.clj
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
#!/usr/bin/env bb
(require
'[cheshire.core :as json]
'[clojure.string :as str]
'[clojure.java.shell :as shell]
'[clojure.java.io :as io])
(def root (str (fs/parent *file*) "/"))
(def test-runner-dir (str (fs/parent *file*) "/"))
(defn- ->snake_case [s] (str/replace s \- \_))
(def practice-exercises
(map #(% "slug")
(-> (str root "config.json")
slurp
json/parse-string
(get "exercises")
(get "practice"))))
(def concept-exercises
(map #(% "slug")
(-> (str root "config.json")
slurp
json/parse-string
(get "exercises")
(get "concept"))))
(defn test-exercise [slug]
(let [practice? (contains? (set practice-exercises) slug)
example (if practice?
(str root "exercises/practice/" slug "/.meta/src/example.clj")
(str root "exercises/concept/" slug "/.meta/exemplar.clj"))
src (if practice?
(str root "exercises/practice/" slug "/src/" (->snake_case slug) ".clj")
(str root "exercises/concept/" slug "/src/" (->snake_case slug) ".clj"))]
(shell/sh "cp" example src)
(= "pass" ((json/parse-string
(:out (shell/sh (str test-runner-dir "test-runner.clj")
slug
(str root (if practice? "exercises/practice/" "exercises/concept/") slug "/")
(str root (if practice? "exercises/practice/" "exercises/concept/") slug "/"))))
"status"))))
(defn test-exercises! []
(for [exercise (into practice-exercises concept-exercises)]
{(keyword exercise) (test-exercise exercise)}))
(let [results (test-exercises!)
fails (filter #(false? (first (vals %))) results)]
(prn {:tested (count results)
:fails fails})
(System/exit (count fails)))