Permalink
Browse files

Added koan-root support to test runner.

  • Loading branch information...
1 parent 87f16f1 commit acbb5ecd53369634fbb1d54496cb45130ae34a77 @sritchie sritchie committed Nov 27, 2011
Showing with 11 additions and 13 deletions.
  1. +0 −1 project.clj
  2. +1 −0 resources/koans.clj
  3. +9 −10 src/koan_engine/checker.clj
  4. +1 −2 src/koan_engine/runner.clj
View
@@ -10,5 +10,4 @@
:main koan-engine.runner
:koan {:koan-root "src/koans"
:dojo-resource "dojo.clj"
- :answer-resource "answers.clj"
:koan-resource "koans.clj"})
View
@@ -0,0 +1 @@
+[[]]
@@ -22,9 +22,8 @@
(concat (map pr-str replacements)
(repeat k)))))))
-;; TODO: Get path from root in resources directory.
-(defn koan-text [koan]
- (slurp (str "src/koans/" koan ".clj")))
+(defn koan-text [koan-root koan]
+ (slurp (str koan-root "/" koan ".clj")))
(defn answers-for [koan sym]
((answers koan {}) sym []))
@@ -48,10 +47,10 @@
pairs)]
`(do ~@tests)))
-(defn ensure-failing-without-answers [dojo-path]
+(defn ensure-failing-without-answers [koan-root dojo-path]
(if (every?
(fn [koan]
- (let [form (koan-text koan)
+ (let [form (koan-text koan-root koan)
form (string/replace form "(meditations" "(ensure-failure")
fake-err (java.io.PrintStream. (java.io.ByteArrayOutputStream.))
real-err System/err
@@ -66,12 +65,12 @@
ordered-koans)
(println "\nTests all fail before the answers are filled in.")))
-(defn ensure-passing-with-answers [dojo-path]
+(defn ensure-passing-with-answers [koan-root dojo-path]
(try (dorun
(map
(fn [koan]
(with-dojo [dojo-path]
- (load-string (-> (koan-text koan)
+ (load-string (-> (koan-text koan-root koan)
(fill-in-answers koan "__")
(fill-in-answers koan "___")))))
ordered-koans))
@@ -81,6 +80,6 @@
(.printStackTrace e)
(println "Answer sheet fail"))))
-(defn test [{:keys [dojo-resource]}]
- (ensure-failing-without-answers dojo-resource)
- (ensure-passing-with-answers dojo-resource))
+(defn test [{:keys [dojo-resource koan-root]}]
+ (ensure-failing-without-answers koan-root dojo-resource)
+ (ensure-passing-with-answers koan-root dojo-resource))
@@ -5,14 +5,13 @@
;; TODO: Incorporate each of these custom options in the runner.
;; koan-root: check!
-;; dojo-resource: NOPE
+;; dojo-resource: check!
;; answer-resource: NOPE
;; koan-resource: NOPE
(def default-koan-map
{:koan-root "src/koans"
:dojo-resource "dojo.clj"
- :answer-resource "answers.clj"
:koan-resource "koans.clj"})
;; TODO: Run validations on koan-map.

0 comments on commit acbb5ec

Please sign in to comment.