From 4f46f577bff686734937e287848198aa798906d6 Mon Sep 17 00:00:00 2001 From: tijsmallaerts Date: Fri, 12 Oct 2018 19:32:08 +0200 Subject: [PATCH 1/3] Always return test documentation messages as strings --- src/cider/nrepl/middleware/test.clj | 17 +++++++++++------ .../nrepl/middleware/test_filter_tests.clj | 3 +++ test/clj/cider/nrepl/middleware/test_test.clj | 19 +++++++++++++++---- 3 files changed, 29 insertions(+), 10 deletions(-) diff --git a/src/cider/nrepl/middleware/test.clj b/src/cider/nrepl/middleware/test.clj index 27e423048..7d9cf1ee5 100644 --- a/src/cider/nrepl/middleware/test.clj +++ b/src/cider/nrepl/middleware/test.clj @@ -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 @@ -291,11 +292,15 @@ (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 [report (->> (test-var-query + (-> var-query + (assoc-in [:ns-query :has-tests?] true) + (assoc :test? true) + (util.coerce/var-query))) + (walk/postwalk (fn [x] (if (and (map? x) + (contains? x :message)) + (update x :message str) + x))))] (reset! results (:results report)) (t/send transport (response-for msg (u/transform-value report)))) (catch clojure.lang.ExceptionInfo e diff --git a/test/clj/cider/nrepl/middleware/test_filter_tests.clj b/test/clj/cider/nrepl/middleware/test_filter_tests.clj index 67edb7e18..10e5f3971 100644 --- a/test/clj/cider/nrepl/middleware/test_filter_tests.clj +++ b/test/clj/cider/nrepl/middleware/test_filter_tests.clj @@ -11,3 +11,6 @@ (deftest yet-an-other-test (is true "yet an other")) + +(deftest test-with-map-as-message + (is true {:key "val"})) diff --git a/test/clj/cider/nrepl/middleware/test_test.clj b/test/clj/cider/nrepl/middleware/test_test.clj index 6dcb5aea0..9b0086780 100644 --- a/test/clj/cider/nrepl/middleware/test_test.clj +++ b/test/clj/cider/nrepl/middleware/test_test.clj @@ -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"}) @@ -86,8 +86,8 @@ :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"]}}}) @@ -95,3 +95,14 @@ (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)))))) From 938d1734fe65d3fd4394726ddbc024ed36a9cd5f Mon Sep 17 00:00:00 2001 From: tijsmallaerts Date: Sun, 14 Oct 2018 20:59:32 +0200 Subject: [PATCH 2/3] Extract stringify-msg as a helper function --- src/cider/nrepl/middleware/test.clj | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/src/cider/nrepl/middleware/test.clj b/src/cider/nrepl/middleware/test.clj index 7d9cf1ee5..39c7af79d 100644 --- a/src/cider/nrepl/middleware/test.clj +++ b/src/cider/nrepl/middleware/test.clj @@ -292,15 +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))) - (walk/postwalk (fn [x] (if (and (map? x) - (contains? x :message)) - (update x :message str) - x))))] + (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 From 191852fa0d313c214adc4fede18ecb213025884e Mon Sep 17 00:00:00 2001 From: tijsmallaerts Date: Sun, 14 Oct 2018 21:04:14 +0200 Subject: [PATCH 3/3] Update changelog --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 556748acc..f78020346 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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