Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Always return test documentation messages as strings #550

Merged
merged 3 commits into from
Oct 14, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 11 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,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)
Copy link
Member

@bbatsov bbatsov Oct 12, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think the ->> reads very well here (because both functions have non-trivial bodies and you're also nesting threadings), so you might want to extract a couple of helper functions or something like this.

(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
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))))))