-
-
Notifications
You must be signed in to change notification settings - Fork 159
/
test.clj
executable file
·57 lines (48 loc) · 1.68 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
56
57
#!/usr/bin/env bb
(require
'[cheshire.core :as json]
'[clojure.string :as str]
'[clojure.java.shell :as shell]
'[babashka.fs :as fs])
(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)
type (if practice? "practice" "concept")
dir (str root "exercises/" type "/" slug "/")
example (if practice?
(str dir ".meta/example.clj")
(str dir ".meta/exemplar.clj"))
src (str dir "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
dir
dir)))
"status"))))
(defn test-exercises! []
(let [exercises (or (seq (take 1 *command-line-args*))
(into practice-exercises concept-exercises))]
(for [exercise 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)))