This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-10-27
Channels
- # announcements (10)
- # beginners (95)
- # biff (2)
- # calva (33)
- # cherry (1)
- # clj-kondo (16)
- # clojure (96)
- # clojure-australia (1)
- # clojure-china (1)
- # clojure-europe (42)
- # clojure-filipino (1)
- # clojure-france (2)
- # clojure-hk (1)
- # clojure-indonesia (1)
- # clojure-japan (1)
- # clojure-korea (1)
- # clojure-my (1)
- # clojure-nl (1)
- # clojure-norway (24)
- # clojure-sg (11)
- # clojure-taiwan (1)
- # clojure-uk (1)
- # clojurescript (21)
- # cursive (22)
- # data-science (3)
- # events (7)
- # fulcro (3)
- # graalvm (4)
- # gratitude (6)
- # helix (11)
- # honeysql (7)
- # hoplon (1)
- # introduce-yourself (1)
- # jobs (2)
- # jobs-discuss (16)
- # lsp (15)
- # malli (14)
- # nbb (73)
- # practicalli (3)
- # reagent (8)
- # reitit (5)
- # releases (1)
- # ring (5)
- # rum (3)
- # sci (17)
- # scittle (7)
- # shadow-cljs (22)
- # tools-deps (26)
- # xtdb (9)
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.
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.
@U6GFE9HS7 Actually, something similar was discussed a while ago, with a nice solution: https://clojurians.slack.com/archives/C0744GXCJ/p1644978986077219
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
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.
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.
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
...
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.
also works with https://github.com/AvisoNovate/pretty
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.
It鈥檚 also true that multi-line patterns are hard in IntelliJ (which is annoying for e.g. printed error objects)
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)
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)
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.
Looks like https://clojure.atlassian.net/jira/software/c/projects/CLJ/issues/?jql=project%20%3D%20%22CLJ%22%20AND%20text%20~%20%22deftest%22%20AND%20statuscategory%20%3D%20%22New%22%20ORDER%20BY%20created%20DESC - if this is something that is visible outside of kaocha it might be worth raising it on ask.clojure
this one is slightly related though: https://clojure.atlassian.net/browse/CLJ-2639