Split freshener and koan ordering out into namespaces.

master
Colin Jones 13 years ago
parent 3644a48bcd
commit c2c9a15cea

@ -1,6 +1,8 @@
(ns path-to-answer-sheet
(:use [path-to-enlightenment :exclude (run)]
[clojure.string :only (join split trim)]))
(:use [runner.koans :only [ordered-koans]]
[path-to-enlightenment :only [meditations __ ___]]
[clojure.string :only [join split trim]]
[clojure.test :only [*test-out*]]))
(def answers
{"equalities" {"__" [true

@ -1,11 +1,8 @@
(ns path-to-enlightenment
(:use [fresh.core :only [clj-files-in freshener]]
[clojure.java.io :only [file]])
(:use [runner.freshness :only [setup-freshener]])
(:require [clojure.set]
[clojure.string]
[clojure.test])
(:import
[java.util.concurrent ScheduledThreadPoolExecutor TimeUnit]))
[clojure.test]))
(def __ :fill-in-the-blank)
(def ___ (fn [& args] __))
@ -19,26 +16,6 @@
pairs)]
`(and ~@tests)))
(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"])
(defn require-version [[required-major required-minor]]
(let [{:keys [major minor]} *clojure-version*]
(if (or (< major required-major)
@ -60,54 +37,7 @@
(map read-string
(take 3 (clojure.string/split version-string #"[\.\-]")))))
(defn files-to-keep-fresh []
(clj-files-in (file "src" "koans")))
(defn- tests-pass? [file-path]
(use 'path-to-enlightenment)
(load-file file-path))
(defn- among-paths? [files]
(into #{} (map #(.getCanonicalPath %) files)))
(defn- ordered-koan-paths []
(map (fn [koan-name]
(.getCanonicalPath (file "src" "koans" (str koan-name ".clj"))))
ordered-koans))
(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 namaste []
(println "\nYou have achieved clojure enlightenment. Namaste."))
(defn report-refresh [report]
(when-let [refreshed-files (seq (:reloaded report))]
(let [these-koans (filter
(among-paths? refreshed-files)
(ordered-koan-paths))]
(println "Refreshing:" these-koans)
(when (every? tests-pass? these-koans)
(if-let [next-koan-file (file (next-koan-path (last these-koans)))]
(report-refresh {:reloaded [next-koan-file]})
(namaste))))
(println))
:refreshed)
(def refresh! (freshener files-to-keep-fresh report-refresh))
(def scheduler (ScheduledThreadPoolExecutor. 1))
(defn setup-freshener []
(.scheduleWithFixedDelay scheduler refresh! 0 500 TimeUnit/MILLISECONDS)
(.awaitTermination scheduler Long/MAX_VALUE TimeUnit/SECONDS))
(defn run []
(require-version (parse-required-version))
(setup-freshener))

@ -0,0 +1,34 @@
(ns runner.freshness
(:use [fresh.core :only [clj-files-in freshener]]
[clojure.java.io :only [file]]
[runner.koans :only [among-paths?
namaste
next-koan-path
ordered-koans
ordered-koan-paths
tests-pass?]])
(:import [java.util.concurrent ScheduledThreadPoolExecutor TimeUnit]))
(defn files-to-keep-fresh []
(clj-files-in (file "src" "koans")))
(defn report-refresh [report]
(when-let [refreshed-files (seq (:reloaded report))]
(let [these-koans (filter
(among-paths? refreshed-files)
(ordered-koan-paths))]
(println "Refreshing:" these-koans)
(when (every? tests-pass? these-koans)
(if-let [next-koan-file (file (next-koan-path (last these-koans)))]
(report-refresh {:reloaded [next-koan-file]})
(namaste))))
(println))
:refreshed)
(def refresh! (freshener files-to-keep-fresh report-refresh))
(def scheduler (ScheduledThreadPoolExecutor. 1))
(defn setup-freshener []
(.scheduleWithFixedDelay scheduler refresh! 0 500 TimeUnit/MILLISECONDS)
(.awaitTermination scheduler Long/MAX_VALUE TimeUnit/SECONDS))

@ -0,0 +1,45 @@
(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"])
(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 __ ___]])
(load-file file-path))
(defn namaste []
(println "\nYou have achieved clojure enlightenment. Namaste."))
Loading…
Cancel
Save