cursive icon indicating copy to clipboard operation
cursive copied to clipboard

Option to print test-output to REPL window

Open thheller opened this issue 10 years ago • 6 comments

My test-workflow consists of running tests via a REPL, usually via Run tests under caret in REPL followed by several Re-Run last test action in REPL. Often I'm not editing another source file (ie. not the file containing the tests) while doing so.

Currently there is no way to tell which assertions failed since Cursive will show those in the editor window and the REPL output usually looks something like this:

Loading test/shadow/cljs/build_test.clj... done
Running shadow.cljs.build-test/test-parse-ns
Ran 1 test containing 7 assertions.
3 failures, 0 errors.

I have to switch to the editor window for the test file to actually see what went wrong. It would be great if there was a way to get the "normal" test output into the REPL window.

This is a normal nREPL connection for Clojure with clojure.test, no CLJS involved.

thheller avatar Dec 07 '15 09:12 thheller

is there any way to achieve this? having to search for the failed tests, hover over them, and wait for the popup windows to appear is frustrating. I would love to have the test output in the REPL window itself.

lucasdf avatar Mar 22 '20 02:03 lucasdf

This is my pain point as well.

shinichy avatar Jul 02 '21 21:07 shinichy

I hope it's not rude to comment once every few years on an issue to show that it's still desired. I have the same workflow and I'd really like this option as well.

michalmela avatar Jul 11 '23 16:07 michalmela

FWIW I sort of built my own testing setup bypassing the built-in Cursive support entirely. Its just a tiny helper namespace and 2 custom REPL commands.

The first command is to select a given test, works exactly like "test under caret".

(require 'shadow.test.repl)
(shadow.test.repl/run-test
  {:file-name "~file-name"
   :file-path "~file-path"
   :file-ns '~file-namespace
   :test-var #'~current-test-var})

The second is to re-run the previously selected test.

(shadow.test.repl/re-run)

For both check the "Sync all files" and "Print results to REPL" options.

The helper namespace is tiny.

(ns shadow.test.repl
  (:require
    [clojure.test :as ct :refer (deftest is)]))

(defonce last-test-ref (atom nil))

(defn run-test [{:keys [test-var] :as info}]
  (reset! last-test-ref test-var)
  (test-var))

(defn re-run []
  (let [test-var @last-test-ref]
    (if-not test-var
      (println "No test-var selected.")
      (ct/test-var test-var))))

It also comes with shadow-cljs. The source is here:

https://github.com/thheller/shadow-cljs/blob/master/src/main/shadow/test/repl.clj

I just replaced my keybindings for the default test running actions with those custom commands and got my desired output in the REPL. It isn't perfect and could be made prettier but it works for me.

thheller avatar Jul 12 '23 07:07 thheller

I still wish we had this feature.

bonkydog avatar Aug 22 '24 22:08 bonkydog