Fork me on GitHub
#cursive
<
2022-10-27
>
cjsauer03:10:49

Is it possible to evaluate a form in the buffer, and have its result replace the form itself? For example, say I have (random-uuid) in the buffer. What I want is for that form to replaced by #uuid"c1ebe545-11a0-46ce-a047-263138a59451" for example.

馃憖 1
cfleming08:10:12

It isn鈥檛 right now, sorry. I have a plan to extend the REPL commands to allow things like this, so you would be able to build commands to do the things you want along these lines. But I haven鈥檛 got to that yet.

cjsauer11:10:58

No worries. Looking forward to the new REPL features.

cfleming21:10:56

@U6GFE9HS7 Actually, something similar was discussed a while ago, with a nice solution: https://clojurians.slack.com/archives/C0744GXCJ/p1644978986077219

cjsauer21:10:29

Oh nice!! That鈥檒l work for now

onetom14:10:43

i've monkey-patched kaocha, so it prints the stack traces for for test failures & errors in a way, that cursive can convert them into links back to the source code. the output of https://github.com/nubank/matcher-combinators failures are also more readable after the expected & actual values are printed starting on a new line, from column 0, so multi-line values are indented correctly. https://gist.github.com/onetom/e39b8cc67d97e9afe3d7b2199024a84b

1
imre15:10:53

This is nice. Have you thought about contributing this to kaocha proper?

imre16:10:29

kaocha is nicely pluggable, I could imagine this possible as a plugin

onetom17:10:20

i thought just enough about it to get it working and that already took more time, than what i should have spent on it right now 馃檪 i saw, that the kaocha.report/print-expr is a multi method of the 1st symbol of the assertion expression (just like clojure.test/assert-expr), so i should have probably just do a (defmethod print-expr 'match? [m] ...) to only affect the matcher-combinator output.

onetom17:10:49

btw, i've tweaked things further a bit and now the expected form is pretty-printed as code, with clojure.pprint/pprint, so u should check out the latest version of the gist.

onetom17:10:59

it would be nicer, if Cursive would have more relaxed rules for recognizing stack trace elements and i shouldn't put that single trace on a newline after FAIL or ERROR...

onetom17:10:35

but not sure how would that affect the performance of the REPL window, if the stack trace pattern would be something like #".* (at|in) ...", instead of the current, presumably #"^ at ...". though, it does recognize the output of https://github.com/mmcgrana/clj-stacktrace too.

cfleming00:10:21

Yes, this is just something I鈥檇 have to add to Cursive. It鈥檚 possible that it could be made generalisable (i.e. using user-defined patterns or something) but I鈥檇 have to investigate that.

cfleming00:10:00

It鈥檚 also true that multi-line patterns are hard in IntelliJ (which is annoying for e.g. printed error objects)

onetom15:10:02

Example of enhanced Kaocha + matcher-combinators + Cursive output:

onetom16:10:19

i've also managed to include the name of the tests, defined by clojure.test/deftest, into the stacktrace output, using this small tweak:

(alter-var-root
  #'clojure.test/deftest
  (constantly
    (fn deftest
      [&form &env name & body]
      (when clojure.test/*load-tests*
        `(defn ~(vary-meta name assoc :test `(fn ~name [] ~@body))
           [] (clojure.test/test-var (var ~name)))))))
it will print
at demo.better_deftest$enhanced_stack_trace_test__600.invokeStatic (better_deftest.clj:19)
    demo.better_deftest/enhanced_stack_trace_test (better_deftest.clj:19)
instead of the default anonymous fn:
at demo.better_deftest$fn__513.invokeStatic (better_deftest.clj:4)
    demo.better_deftest/fn (better_deftest.clj:4)

onetom16:10:12

complete test code to repro this result:

(ns demo.better-deftest
  (:require [clojure.test :refer :all]))

(deftest default-stack-trace-test
  (is (throw (Exception. "BAMM"))))

(clojure.test/run-test default-stack-trace-test)

;;; `clojure.test` improvements
(alter-var-root
  #'clojure.test/deftest
  (constantly
    (fn deftest
      [&form &env name & body]
      (when clojure.test/*load-tests*
        `(defn ~(vary-meta name assoc :test `(fn ~name [] ~@body))
           [] (clojure.test/test-var (var ~name)))))))

(deftest enhanced-stack-trace-test
  (is (throw (Exception. "BAMM"))))

(clojure.test/run-test enhanced-stack-trace-test)

imre17:10:26

I wonder if there's a clj ticket about this

onetom17:10:40

yeah, i thought about that too, but hasn't dug into it yet. im not very confident, whether this change could cause any issues, but our test suite seems to run with it at least.