Permalink
Browse files

Run examples in overtone.smoke-test

  • Loading branch information...
1 parent f919b64 commit 1f44cde810b761d6e0fbadcb798614d89d767ca6 @neatonk neatonk committed Jan 1, 2013
Showing with 56 additions and 5 deletions.
  1. +1 −0 project.clj
  2. +50 −0 test/overtone/smoke_test.clj
  3. +5 −5 test/test_helper.clj
View
@@ -56,5 +56,6 @@
[clj-glob "1.0.0"]
[org.clojure/core.match "0.2.0-alpha11"]
[seesaw "1.4.2"]]
+ :profiles {:dev {:dependencies [[bultitude "0.2.0"]]}}
:native-path "native"
:jvm-opts ~(jvm-opts))
@@ -1,6 +1,8 @@
(ns overtone.smoke-test
"Simple tests which exercise overtone and make few assertions.
Ensures successful complilation of overtone and its examples."
+ (:require [overtone.config.log :as log]
+ [bultitude.core :as b])
(:use overtone.core
clojure.test
test-helper))
@@ -25,6 +27,54 @@
(demo 0.1 (sin-osc))
(Thread/sleep 100)))
+
+;; Examples
+;;
+;; Create a test for each example ns under `overtone.examples.*` which
+;; loads the ns and invokes the `-main` fn if it exists and logs *out*.
+;;
+;; TODO:
+;; * define a `-main` function for each example
+;; * make sure at-at scheduled functions are canceled or completed
+
+(defn all-example-ns []
+ (b/namespaces-on-classpath :prefix "overtone.examples"))
+
+(defn example-test-fn
+ [example-ns]
+ (fn []
+ (println "\nRunning example:" example-ns)
+ (require example-ns)
+ (when-let [-main (find-var (symbol (str example-ns) "-main"))]
+ ((var-get -main)))))
+
+(defn example-test-name [example-ns]
+ (symbol (str (.replace (str example-ns) "." "-") "-test")))
+
+(defn intern-example-tests []
+ (doseq [example-ns (all-example-ns)]
+ (let [test-name (example-test-name example-ns)
+ test-fn (example-test-fn example-ns)]
+ (doto (intern *ns* test-name test-fn)
+ (alter-meta! assoc :test test-fn)))))
+
+(when *load-tests* (intern-example-tests))
+
+
+(let [ns (the-ns *ns*)]
+ (defn test-ns-hook
+ "Calls test-var on every var interned in this namespace, with
+ fixtures. The order in which the tests are run is randomized to
+ expose any inter-test dependencies that may exist."
+ []
+ (let [once-fixture-fn (join-fixtures (:clojure.test/once-fixtures (meta ns)))
+ each-fixture-fn (join-fixtures (:clojure.test/each-fixtures (meta ns)))]
+ (once-fixture-fn
+ (fn []
+ (doseq [v (shuffle (vals (ns-interns ns)))]
+ (when (:test (meta v))
+ (each-fixture-fn (fn [] (test-var v))))))))))
+
(comment
(run-tests)
)
View
@@ -48,7 +48,6 @@
[ms & body]
`(invoke-timeout (^{:once true} fn [] ~@body) ~ms))
-
(defn wait-while
"Blocks the current thread while `pred` returns true.
@@ -95,10 +94,11 @@
(kill-server))
(defn with-sync-reset
- "Fixture. Ensures that all running synth and inst nodes are stopped
- after invoking 'f'. Blocks the current thread until reset is
- complete. Does NOT affect synthdefs."
- [f] (do (f) stop (sync-event :reset)))
+ "Fixture. Ensures that the server gets reset after each test.
+ Synchronously stops active nodes in the default foundation-group,
+ clears the osc message queue, and kills all scheduled jobs in the
+ player-pool if any."
+ [f] (do (f) (sync-event :reset)))
;; Some quick tests to verify test-helpers...

0 comments on commit 1f44cde

Please sign in to comment.