rewrite-clj

2021-10-29T18:39:30.033500Z

i’m considering using rewrite-clj to rewrite/rearrange my test suite. it’s currently written in the philosophy of “few deftests, many testing branches”, which makes running specific branches hard. i’m looking to pluck each testing branch out of the deftests and then place them in a new deftest with some name. would this be possible with rewrite-clj?

borkdude 2021-10-29T20:08:16.034300Z

@nbtheduke That is something that I've thought about too: it's better to have more deftests rather than single big tests: it's much easier to invoke them separately.

borkdude 2021-10-29T20:08:26.034700Z

And yes, rewrite-clj is a good tool to do this I think

2021-10-29T20:08:40.035Z

yeah, it’s also an issue when our tests are really long, so some of these files are 4k or 5k lines long lol

vemv 2021-10-29T20:31:16.037800Z

wondering if the rewrite-clj.paredit would be a good fit, I've never used it but the task sounds 'paredit-y' to me two phases: first move all testings to the top-level, then wrap each one with deftest might be more complex than that though depending on the usage patterns If it's a truly one-off thing I might do the last finishing touches with IDE paredit, sounds cheaper than coding sth fine-grained. @nbtheduke

2021-10-29T20:41:27.040200Z

if this was purely string manipulation, i’d probably do it with a thread last that filters to deftest blocks, then group by the deftest name, then plucks each testing block, then mapcats with some sort of “wrap each block in a deftest”, then prints them out

2021-10-29T20:42:55.040900Z

seems like there’s not any sort of sequencing/mapping over zlocs

borkdude 2021-10-29T20:57:37.041600Z

@nbtheduke Sometimes I find it easier to ignore the whole zipper stuff and just work directly with the nodes and :children

2021-10-29T20:58:21.042Z

oh yeah? cool, which part is that?

2021-10-29T20:59:52.042200Z

oh, found the node api

2021-10-29T21:07:06.042600Z

yeah, this is much more my speed. cannot believe all of these cool apis exist

2021-10-29T21:07:11.042800Z

so lucky to work in clojure

lread 2021-10-29T21:09:49.044300Z

I typically first reach for the rewrite-clj zip API myself, but probably only just because that’s what I am used to.

borkdude 2021-10-29T21:10:26.044700Z

You can combine both approach too. It's just awesome ;)

1