-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds audio test reporter via "say" command when SPEAK_TEST_RESULTS is…
… set (#8)
- Loading branch information
1 parent
7061174
commit f1c1079
Showing
3 changed files
with
40 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
(ns mb.hawk.speak | ||
(:require [clojure.java.shell :as sh])) | ||
|
||
(defmulti handle-event! | ||
"Handles a test event by speaking(!?) it if appropriate" | ||
:type) | ||
|
||
(defn- enabled? [] (some? (System/getenv "SPEAK_TEST_RESULTS"))) | ||
|
||
(defmethod handle-event! :default [_] nil) | ||
|
||
(defmethod handle-event! :summary | ||
[{:keys [error fail]}] | ||
(when (enabled?) | ||
(apply sh/sh "say" | ||
(if (zero? (+ error fail)) | ||
"all tests passed" | ||
"tests failed") | ||
(for [[n s] [[error "error"] | ||
[fail "failure"]] | ||
:when (pos? n)] | ||
(str n " " s (when (< 1 n) "s")))))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
(ns mb.hawk.speak-test | ||
(:require [clojure.java.shell :as sh] | ||
[clojure.test :refer :all] | ||
[mb.hawk.speak :as hawk.speak])) | ||
|
||
(deftest speak-results-test | ||
(are [error fail expected] (let [sh-args (atom nil)] | ||
(with-redefs [hawk.speak/enabled? (constantly true) | ||
sh/sh (fn [& args] (reset! sh-args (vec args)))] | ||
(hawk.speak/handle-event! {:type :summary :error error :fail fail}) | ||
(= (into ["say"] expected) @sh-args))) | ||
0 0 ["all tests passed"] | ||
1 0 ["tests failed" "1 error"] | ||
2 0 ["tests failed" "2 errors"] | ||
2 1 ["tests failed" "2 errors" "1 failure"] | ||
0 2 ["tests failed" "2 failures"])) |