Skip to content

Commit

Permalink
Adds audio test reporter via "say" command when SPEAK_TEST_RESULTS is…
Browse files Browse the repository at this point in the history
… set (#8)
  • Loading branch information
john-metabase authored Jun 5, 2023
1 parent 7061174 commit f1c1079
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/mb/hawk/core.clj
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
[mb.hawk.init :as hawk.init]
[mb.hawk.junit :as hawk.junit]
[mb.hawk.parallel :as hawk.parallel]
[mb.hawk.speak :as hawk.speak]
[mb.hawk.util :as u]))

(set! *warn-on-reflection* true)
Expand Down Expand Up @@ -145,6 +146,7 @@
:cli/local eftest.report.progress/report)]
(fn handle-event [event]
(hawk.junit/handle-event! event)
(hawk.speak/handle-event! event)
(stdout-reporter event))))

(def ^:private env-mode
Expand Down
22 changes: 22 additions & 0 deletions src/mb/hawk/speak.clj
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"))))))
16 changes: 16 additions & 0 deletions test/mb/hawk/speak_test.clj
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"]))

0 comments on commit f1c1079

Please sign in to comment.