Skip to content

Commit

Permalink
Always return test documentation messages as strings (#550)
Browse files Browse the repository at this point in the history
  • Loading branch information
mallt authored and bbatsov committed Oct 14, 2018
1 parent b2c0b92 commit c5f97a2
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 10 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@

* [#546](https://github.com/clojure-emacs/cider-nrepl/pull/546): Added support for matcher-combinators to the test middleware.

### Changes

* [#550](https://github.com/clojure-emacs/cider-nrepl/pull/550): Always return test documentation messages as strings.

## 0.18.0 (2018-08-06)

### New features
Expand Down
20 changes: 14 additions & 6 deletions src/cider/nrepl/middleware/test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
[orchard.namespace :as ns]
[orchard.query :as query]
[clojure.pprint :as pp]
[clojure.test :as test]))
[clojure.test :as test]
[clojure.walk :as walk]))

(if (find-ns 'clojure.tools.nrepl)
(require
Expand Down Expand Up @@ -291,11 +292,18 @@
(with-interruptible-eval
msg
(try
(let [report (test-var-query
(-> var-query
(assoc-in [:ns-query :has-tests?] true)
(assoc :test? true)
(util.coerce/var-query)))]
(let [stringify-msg (fn [report]
(walk/postwalk (fn [x] (if (and (map? x)
(contains? x :message))
(update x :message str)
x))
report))
report (-> var-query
(assoc-in [:ns-query :has-tests?] true)
(assoc :test? true)
(util.coerce/var-query)
test-var-query
stringify-msg)]
(reset! results (:results report))
(t/send transport (response-for msg (u/transform-value report))))
(catch clojure.lang.ExceptionInfo e
Expand Down
3 changes: 3 additions & 0 deletions test/clj/cider/nrepl/middleware/test_filter_tests.clj
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,6 @@

(deftest yet-an-other-test
(is true "yet an other"))

(deftest test-with-map-as-message
(is true {:key "val"}))
19 changes: 15 additions & 4 deletions test/clj/cider/nrepl/middleware/test_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@
:exclude ["integration"]})
tests (keys (:cider.nrepl.middleware.test-filter-tests results))]
(is ((set (keys results)) :cider.nrepl.middleware.test-filter-tests) "ns that contains smoke is present")
(is (= 2 (count tests)) "only one test was run")
(is (= #{:a-puff-of-smoke-test :yet-an-other-test} (set tests)) "only the test marked 'smoke' was run")))
(is (= 3 (count tests)) "only one test was run")
(is (= #{:a-puff-of-smoke-test :yet-an-other-test :test-with-map-as-message} (set tests)) "only the test marked 'smoke' was run")))
(testing "marked test is still run if filter is not used"
(let [{:keys [results] :as test-result} (session/message {:op "test"
:ns "cider.nrepl.middleware.test-filter-tests"})
Expand Down Expand Up @@ -86,12 +86,23 @@
:exclude-meta-key ["integration"]}})
tests (keys (:cider.nrepl.middleware.test-filter-tests results))]
(is ((set (keys results)) :cider.nrepl.middleware.test-filter-tests) "ns that contains smoke is present")
(is (= 2 (count tests)) "only one test was run")
(is (= #{:a-puff-of-smoke-test :yet-an-other-test} (set tests)) "only the test marked 'smoke' was run")))
(is (= 3 (count tests)) "only one test was run")
(is (= #{:a-puff-of-smoke-test :yet-an-other-test :test-with-map-as-message} (set tests)) "only the test marked 'smoke' was run")))
(testing "marked test is still run if filter is not used"
(let [{:keys [results] :as test-result} (session/message {:op "test-var-query"
:var-query {:ns-query {:exactly ["cider.nrepl.middleware.test-filter-tests"]}}})
tests (keys (:cider.nrepl.middleware.test-filter-tests results))]
(is ((set (keys results)) :cider.nrepl.middleware.test-filter-tests) "ns that contains smoke is present")
(is (< 1 (count tests)) "more tests were run")
(is ((set tests) :a-puff-of-smoke-test) "smoke test is still present without a filter"))))

(deftest run-test-with-map-as-documentation-message
(testing "documentation message map is returned as string"
(let [{:keys [results] :as test-result} (session/message {:op "test"
:ns "cider.nrepl.middleware.test-filter-tests"
:tests ["test-with-map-as-message"]})]
(is (= (str {:key "val"}) (-> results
:cider.nrepl.middleware.test-filter-tests
:test-with-map-as-message
first
:message))))))

0 comments on commit c5f97a2

Please sign in to comment.