Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

examples test

  • Loading branch information...
commit 0e5d21f52f2ad0e50cf8dd85ece4d7cd98a3bed9 1 parent edafea0
Stuart Halloway authored
Showing with 42 additions and 0 deletions.
  1. +3 −0  .gitignore
  2. +39 −0 test/simulant/examples_test.clj
3  .gitignore
View
@@ -6,5 +6,8 @@
/.lein-failures
/checkouts
/.lein-deps-sum
+/.lein-plugins/*
+/.lein-repl-history
+/target/*
39 test/simulant/examples_test.clj
View
@@ -0,0 +1,39 @@
+(ns simulant.examples-test
+ (:require [clojure.java.io :as io]
+ [clojure.pprint :as pprint]))
+
+(defn read-all
+ "Read all forms in f, where f is any resource that can
+ be opened by io/reader"
+ [f]
+ (datomic.Util/readAll (io/reader f)))
+
+(defn examples-seq
+ []
+ (->> (file-seq (io/file "examples/repl"))
+ (filter #(.endsWith (.getName ^java.io.File %) ".clj"))))
+
+(defn transcript
+ "Run all forms, printing a transcript as if forms were
+ individually entered interactively at the REPL."
+ [forms]
+ (binding [*ns* *ns*]
+ (let [temp (gensym)]
+ (println ";; Executing forms in temp namespace: " temp)
+ (in-ns temp)
+ (clojure.core/use 'clojure.core 'clojure.repl 'clojure.pprint)
+ (doseq [f forms]
+ (pprint/pprint f)
+ (print "=> ")
+ (pprint/pprint (eval f))
+ (println))
+ (remove-ns temp)
+ :done)))
+
+(defn -main
+ "Run all the tutorials"
+ [& _]
+ (doseq [file (examples-seq)]
+ (println "\n;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;")
+ (println ";; Transcript for " file)
+ (transcript (read-all (io/reader file)))))
Please sign in to comment.
Something went wrong with that request. Please try again.