Permalink
Browse files

Removed cyclic dependency with runner namespace.

  • Loading branch information...
1 parent 903bcd2 commit 43e7cc327520bb4405cda3eea3aa95ad8eea3680 @sritchie sritchie committed Nov 27, 2011
View
@@ -212,11 +212,25 @@ Using the [koans](http://en.wikipedia.org/wiki/koan) metaphor as a tool for
learning a programming language started with the
[Ruby Koans](http://rubykoans.com) by [EdgeCase](http://github.com/edgecase).
-
### License
The use and distribution terms for this software are covered by the
Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php)
which can be found in the file epl-v10.html at the root of this distribution.
By using this software in any fashion, you are agreeing to be bound by
the terms of this license.
+
+### Next
+
+Lein plugin
+* advantages
+ * Drop into an existing project and you get koans.
+ * lein koan run
+ * lein koan test
+
+What if I want to run this project outside of leiningen?
+
+* Pull in the library with lein deps
+script/run should be able to take care of everything.
+
+
View
@@ -1,10 +1,14 @@
(defproject cascalog-koan-engine "0.1.0"
:description "Koan Engine for Clojure projects."
- :main koan-engine.core
:dependencies [[org.clojure/clojure "1.3.0"]
[cascalog "1.8.4"]
[fresh "1.0.2"]
[jline "0.9.94" :exclusions [junit]]]
:dev-dependencies [[org.apache.hadoop/hadoop-core "0.20.2-dev"]
[swank-clojure "1.4.0-SNAPSHOT"
- :exclusions [org.clojure/clojure]]])
+ :exclusions [org.clojure/clojure]]]
+ :main koan-engine.runner
+ :koan {:koan-root "src/koans"
+ :dojo-resource "dojo"
+ :answer-resource "answers"
+ :koan-resource "koans"})
View
@@ -1,5 +1,4 @@
(load "koan_engine/core")
(do
- (in-ns 'koan-engine.core)
- (println "RUNNINBG")
- (-main))
+ (in-ns 'koan-engine.runner)
+ (-main "run"))
View
@@ -1,4 +1,4 @@
-(load "koan_engine/checker")
+(load "koan_engine/core")
(do
- (in-ns 'koan-engine.checker)
- (run))
+ (in-ns 'koan-engine.runner)
+ (-main "test"))
@@ -1,4 +1,5 @@
(ns koan-engine.checker
+ (:refer-clojure :exclude [test])
(:use cascalog.api
[koan-engine.koans :only [ordered-koans]]
[koan-engine.core :only [meditations ?= __ ___]]
@@ -8,7 +9,6 @@
;; TODO: Use cascalog.api elsewhere.
;; TODO: add ?= back in somewhere!
;; TODO: Move out into resources directory!
-
(def answers
{"tuples" {"__" [[["truth."]]
[[1]]
@@ -89,6 +89,6 @@
(.printStackTrace e)
(println "Answer sheet fail"))))
-(defn run []
+(defn test []
(ensure-failing-without-answers)
(ensure-passing-with-answers))
@@ -1,7 +1,6 @@
(ns koan-engine.core
(:use [cascalog.testing :only (test?-)]
- [cascalog.util :only (defalias)]
- [koan-engine.freshness :only [setup-freshener]])
+ [cascalog.util :only (defalias)])
(:require [koan-engine.util :as u]))
(def __ :fill-in-the-blank)
@@ -21,7 +20,3 @@
`(u/fancy-assert ~code# ~doc#))
pairs)]
`(do ~@tests)))
-
-(defn -main []
- (u/require-version (u/parse-required-version))
- (setup-freshener))
@@ -9,8 +9,9 @@
tests-pass?]])
(:import [java.util.concurrent ScheduledThreadPoolExecutor TimeUnit]))
-(defn files-to-keep-fresh []
- (clj-files-in (file "src" "koans")))
+(defn files-to-keep-fresh [koan-root]
+ (constantly
+ (clj-files-in (file koan-root))))
(defn report-refresh [report]
(when-let [refreshed-files (seq (:reloaded report))]
@@ -24,11 +25,15 @@
(println))
:refreshed)
-(def refresh! (freshener files-to-keep-fresh report-refresh))
+(defn refresh! [{:keys [koan-root]}]
+ (freshener (files-to-keep-fresh koan-root)
+ report-refresh))
(def scheduler (ScheduledThreadPoolExecutor. 1))
-(defn setup-freshener []
+(defn setup-freshener [koan-map]
(println "Starting auto-runner...")
- (.scheduleWithFixedDelay scheduler refresh! 0 500 TimeUnit/MILLISECONDS)
+ (.scheduleWithFixedDelay scheduler
+ (refresh! koan-map)
+ 0 500 TimeUnit/MILLISECONDS)
(.awaitTermination scheduler Long/MAX_VALUE TimeUnit/SECONDS))
@@ -0,0 +1,20 @@
+(ns koan-engine.runner
+ (:use [koan-engine.freshness :only [setup-freshener]])
+ (:require [koan-engine.util :as u]
+ [koan-engine.checker :as checker]))
+
+;; TODO: Incorporate each of these custom options in the runner.
+;; koan-root: check!
+(def default-koan-map
+ {:koan-root "src/koans"
+ :dojo-resource "dojo"
+ :answer-resource "answers"
+ :koan-resource "koans"})
+
+(defn -main [task]
+ (u/require-version (u/parse-required-version))
+ (let [koan-map (merge default-koan-map
+ (:koan (u/read-project)))]
+ (case task
+ "run" (setup-freshener koan-map)
+ "test" (checker/test koan-map))))
@@ -36,14 +36,16 @@
(throw (Exception. (str '~message "\n" '~x )
e#))))))
-(defn parse-required-version []
+(defn read-project []
(let [rdr (clojure.lang.LineNumberingPushbackReader.
- (java.io.FileReader. (java.io.File. "project.clj")))
- project-form (read rdr)
- version-string (->> project-form
- (drop 3)
- (apply hash-map)
- :dependencies
+ (java.io.FileReader. (java.io.File. "project.clj")))]
+ (->> (read rdr)
+ (drop 3)
+ (apply hash-map))))
+
+(defn parse-required-version []
+ (let [{deps :dependencies} (read-project)
+ version-string (->> deps
(map (fn [xs] (vec (take 2 xs))))
(into {})
('org.clojure/clojure))]

0 comments on commit 43e7cc3

Please sign in to comment.