-
Notifications
You must be signed in to change notification settings - Fork 2.1k
/
koans.clj
58 lines (51 loc) · 1.46 KB
/
koans.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
(ns runner.koans
(:use [clojure.java.io :only [file]]))
(def ordered-koans
["equalities"
"lists"
"vectors"
"sets"
"maps"
"functions"
"conditionals"
"higher_order_functions"
"runtime_polymorphism"
"lazy_sequences"
"sequence_comprehensions"
"creating_functions"
"recursion"
"destructuring"
"refs"
"atoms"
"macros"
"datatypes"
"java_interop"])
(defn ordered-koan-paths []
(map (fn [koan-name]
(.getCanonicalPath (file "src" "koans" (str koan-name ".clj"))))
ordered-koans))
(defn among-paths? [files]
(into #{} (map #(.getCanonicalPath %) files)))
(defn next-koan-path [last-koan-path]
(loop [[this-koan & more :as koan-paths] (ordered-koan-paths)]
(when (seq more)
(if (= last-koan-path this-koan)
(first more)
(recur more)))))
(defn tests-pass? [file-path]
(use '[path-to-enlightenment :only [meditations __ ___]])
(try
(load-file file-path)
true
(catch Exception e
(println)
(println "Problem in" file-path)
(println "---------------------")
(println "Assertion failed!")
(let [actual-error (or (.getCause e) e)
message (or (.getMessage actual-error)
(.toString actual-error))]
(println (.replaceFirst message "^Assert failed: " "")))
false)))
(defn namaste []
(println "\nYou have achieved clojure enlightenment. Namaste."))