Permalink
Browse files

Project now loads prerequisites with the dojo.

  • Loading branch information...
1 parent 43e7cc3 commit e063af12d3660d582b9c06a58743ce1d3be84a58 @sritchie sritchie committed Nov 27, 2011
View
@@ -9,6 +9,6 @@
:exclusions [org.clojure/clojure]]]
:main koan-engine.runner
:koan {:koan-root "src/koans"
- :dojo-resource "dojo"
- :answer-resource "answers"
- :koan-resource "koans"})
+ :dojo-resource "dojo.clj"
+ :answer-resource "answers.clj"
+ :koan-resource "koans.clj"})
View
@@ -0,0 +1,7 @@
+(use 'cascalog.api
+ '[cascalog.testing :only (test?-)]
+ '[cascalog.util :only (defalias)])
+
+(defalias ?= test?-)
+
+
View
@@ -1,11 +1,7 @@
#!/bin/sh
CLASSPATH=src
-for f in lib/dev/*.jar; do
- CLASSPATH=$CLASSPATH:$f
-done
-
-for f in lib/*.jar; do
+for f in lib/*.jar lib/dev/*.jar resources/; do
CLASSPATH=$CLASSPATH:$f
done
@@ -14,4 +10,3 @@ if [ "$OSTYPE" = "cygwin" ]; then
fi
java -cp "$CLASSPATH" clojure.main -i script/run.clj
-echo
View
@@ -1,4 +1,4 @@
-(load "koan_engine/core")
+(load "koan_engine/runner")
(do
(in-ns 'koan-engine.runner)
(-main "run"))
View
@@ -1,11 +1,8 @@
#!/bin/sh
CLASSPATH=src
-for f in lib/dev/*.jar; do
- CLASSPATH=$CLASSPATH:$f
-done
-for f in lib/*.jar; do
+for f in lib/*.jar lib/dev/*.jar resources/; do
CLASSPATH=$CLASSPATH:$f
done
View
@@ -1,4 +1,4 @@
-(load "koan_engine/core")
+(load "koan_engine/runner")
(do
(in-ns 'koan-engine.runner)
(-main "test"))
@@ -1,13 +1,9 @@
(ns koan-engine.checker
(:refer-clojure :exclude [test])
- (:use cascalog.api
- [koan-engine.koans :only [ordered-koans]]
- [koan-engine.core :only [meditations ?= __ ___]]
- [koan-engine.util :only [fancy-assert]]
+ (:use [koan-engine.koans :only [ordered-koans]]
+ [koan-engine.util :only [fancy-assert with-dojo]]
[clojure.string :only [join split trim] :as string]))
-;; TODO: Use cascalog.api elsewhere.
-;; TODO: add ?= back in somewhere!
;; TODO: Move out into resources directory!
(def answers
{"tuples" {"__" [[["truth."]]
@@ -56,39 +52,39 @@
;; load-string won't have the proper requirements.
;;
;; In the actual koan we prefix form with some use and requires.
-(defn ensure-failing-without-answers []
+(defn ensure-failing-without-answers [dojo-path]
(if (every?
(fn [koan]
(let [form (koan-text koan)
form (string/replace form "(meditations" "(ensure-failure")
fake-err (java.io.PrintStream. (java.io.ByteArrayOutputStream.))
real-err System/err
- result (try
- (load-string form)
- true
- (catch AssertionError e (prn e) false)
- (catch Exception e (prn e) false))]
+ result (try (with-dojo [dojo-path]
+ (load-string form))
+ true
+ (catch AssertionError e (prn e) false)
+ (catch Exception e (prn e) false))]
(if result
:pass
(print-non-failing-error koan))))
ordered-koans)
(println "\nTests all fail before the answers are filled in.")))
-(defn ensure-passing-with-answers []
- (try
- (dorun (map
- (fn [koan]
- (load-string
- (-> (koan-text koan)
- (fill-in-answers koan "__")
- (fill-in-answers koan "___"))))
- ordered-koans))
- (println "\nAll tests pass after the answers are filled in.")
- (catch Exception e
- (println "\nAnswer sheet fail: " e)
- (.printStackTrace e)
- (println "Answer sheet fail"))))
+(defn ensure-passing-with-answers [dojo-path]
+ (try (dorun
+ (map
+ (fn [koan]
+ (with-dojo [dojo-path]
+ (load-string (-> (koan-text koan)
+ (fill-in-answers koan "__")
+ (fill-in-answers koan "___")))))
+ ordered-koans))
+ (println "\nAll tests pass after the answers are filled in.")
+ (catch Exception e
+ (println "\nAnswer sheet fail: " e)
+ (.printStackTrace e)
+ (println "Answer sheet fail"))))
-(defn test []
- (ensure-failing-without-answers)
- (ensure-passing-with-answers))
+(defn test [{:keys [dojo-resource]}]
+ (ensure-failing-without-answers dojo-resource)
+ (ensure-passing-with-answers dojo-resource))
View
@@ -1,6 +1,4 @@
(ns koan-engine.core
- (:use [cascalog.testing :only (test?-)]
- [cascalog.util :only (defalias)])
(:require [koan-engine.util :as u]))
(def __ :fill-in-the-blank)
@@ -10,10 +8,6 @@
;; [cascalog.testing :only (test?-)]
;; [cascalog.util :only (defalias)]
-;; TODO: Move out!
-;; More concise for koans.
-(defalias ?= test?-)
-
(defmacro meditations [& forms]
(let [pairs (partition 2 forms)
tests (map (fn [[doc# code#]]
@@ -32,10 +32,7 @@
(recur more)))))
(defn tests-pass? [file-path]
- (binding [*ns* (create-ns (gensym "koans"))]
- (refer 'clojure.core)
- (use 'cascalog.api) ;; TODO: Move out other namespace.
- (use '[koan-engine.core :only [meditations ?= __ ___]])
+ (u/with-dojo ["dojo.clj"]
(try (load-file file-path)
true
(catch Exception e
View
@@ -4,13 +4,19 @@
[koan-engine.checker :as checker]))
;; TODO: Incorporate each of these custom options in the runner.
-;; koan-root: check!
+;; koan-root: check!
+;; dojo-resource: NOPE
+;; answer-resource: NOPE
+;; koan-resource: NOPE
+
(def default-koan-map
{:koan-root "src/koans"
- :dojo-resource "dojo"
- :answer-resource "answers"
- :koan-resource "koans"})
+ :dojo-resource "dojo.clj"
+ :answer-resource "answers.clj"
+ :koan-resource "koans.clj"})
+;; TODO: Run validations on koan-map.
+;; Do all resources exist?
(defn -main [task]
(u/require-version (u/parse-required-version))
(let [koan-map (merge default-koan-map
View
@@ -1,5 +1,6 @@
(ns koan-engine.util
- (:require [clojure.string :as s]))
+ (:require [clojure.string :as s]
+ [clojure.java.io :as io]))
(defn version<
"< for Clojure's version map."
@@ -50,3 +51,17 @@
(into {})
('org.clojure/clojure))]
(map read-string (take 3 (s/split version-string #"[\.\-]")))))
+
+(defmacro do-isolated [& forms]
+ `(binding [*ns* (create-ns (gensym "jail"))]
+ (refer 'clojure.core)
+ ~@forms))
+
+(defmacro with-dojo [[dojo-path] & body]
+ `(let [dojo# (when-let [dojo# (clojure.java.io/resource ~dojo-path)]
+ (read-string (format "(do %s)" (slurp dojo#))))]
+ (do-isolated
+ (use '~'[koan-engine.core :only [meditations __ ___]]
+ '~'[koan-engine.checker :only [ensure-failure]])
+ (eval dojo#)
+ ~@body)))

0 comments on commit e063af1

Please sign in to comment.