This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-05-31
Channels
- # announcements (8)
- # babashka (8)
- # beginners (13)
- # biff (1)
- # calva (1)
- # cider (12)
- # clj-kondo (16)
- # cljs-dev (3)
- # cljsrn (14)
- # clojure (18)
- # clojure-austin (2)
- # clojure-czech (3)
- # clojure-europe (54)
- # clojure-germany (5)
- # clojure-nl (1)
- # clojure-norway (2)
- # clojure-spec (4)
- # clojure-survey (2)
- # clojure-uk (1)
- # clojured (15)
- # clojurescript (5)
- # conjure (6)
- # core-async (65)
- # cursive (24)
- # data-science (1)
- # emacs (9)
- # events (3)
- # graphql (5)
- # integrant (6)
- # jobs (2)
- # joyride (62)
- # lsp (5)
- # malli (10)
- # off-topic (20)
- # pathom (57)
- # polylith (18)
- # re-frame (12)
- # remote-jobs (3)
- # rewrite-clj (14)
- # sci (2)
- # shadow-cljs (41)
- # sql (9)
- # tools-deps (68)
At my job, we have a lot of test assertions inside of let blocks:
(let [stuff (do-stuff a b c)
_ (is (= 1 stuff))
_ (is (= 2 (inc stuff)))
other-stuff (do-more-stuff x y z)]
(is (= 3 other-stuff)))
Merely to avoid having to nest let blocks. (Sometimes, the only test assertions are inside of let blocks lol) I think this a code smell and have written up a hook to warn on this. Would you be interested in this as an official lint?lol okay
But maybe other people are interested and then I would be okay with adding an optional linter. I'll keep it in mind. Let's wait for this to come up more often, it's the first time I hear someone perceive this as a problem
Yeah, it's not bad necessarily, it's just not how I think it should be done and I find it hard to work with (because I can't write normal test stuff, I have to be aware of when I'm inside of a let block and add dummy binds _
, etc). Would you like me to open a github issue about this?
FWIW, we have 85 of these in our work codebase. It's a pretty convenient way to provide inline assertions in complex tests.
Yeah, I wouldn't suggest this to be on by default, but it does seem worth having as a toggle for those who care.
Anyone ever tried https://github.com/Engelberg/better-cond for this sort of thing? It’s advertised as being good at both avoiding rightward drift and sprinkling in side effects
@U07M2C8TT I wouldn't consider better-cond as a solution to this particular "problem" -- there's no conditional work going on here.
(my personal feeling is that better-cond is solving the wrong problem: refactor your code, don't add a weird macro to support your bad code 🙂 )
@U04V70XH6 I agree, I’d be skeptical of better-cond in the main codebase, but I feel less hesitant about using a “weird macro” in test code. I’ve never used it, I was just curious if anyone had ever used it in the style where you https://github.com/Engelberg/better-cond#minimizing-rightward-drift
Wow, I think that's horrific... Both versions...
It's screaming for a refactor.
Perhaps, but again, we’re talking about test code, which doesn’t always get the same love. Again, I’m not advocating this style, just asking if it’s worked out for anyone. It’s clear… it wouldn’t work for you!