4 ms·
I've only dabbled in Clojure and REPL-driven development, but is there a way of easily converting a REPL sessions into a suite of tests? Coming from more of te
by joe_fishfish 6y ago
I've only dabbled in Clojure and REPL-driven development, but is there a way of easily converting a REPL sessions into a suite of tests?
Coming from more of test-driven development background, I found that tinkering in the REPL was similar to what I would usually do with unit tests, but without the ability to easily build up a test suite that would prevent regressions in future.
- LandR 6y agoNot that I'm aware off, so I use both. I'll start by writing a bunch of tests and have a test runner that runs all my tests everytime I change my source code and displays the results. It's fast, I have one project that runs ~1400 asserts and on each save it shows the results less than 2 seconds later. THen I write the code in my IDE source editor and use a keyboard shortcut to send it to the REPL as I'm working. I wouldn't ever write code directly in the REPL. By the time I've got it working in the REPL I normally then see that all my tests are passing.
- diggan 6y agoDepends on how you use your REPL. I run the REPL in the background and connect vim (via conjure plugin) to the REPL, so I still type out my code into my editor, into files and buffers, and only save them to disk when I'm happy with the code. So usually I end up mostly living within (comment) blocks around the functions I'm interacting with, and when I'm happy with it, move the code into the correct test namespace, which is a matter of just moving the code around and changing references to namespaces.
- slifin 6y agoFrom my understanding https://github.com/cognitect-labs/transcriptor https://github.com/cognitect-labs/transcriptor does this
- CraigJPerry 6y agoI’m a beginner clojurian but i’ve noticed some devs put a repl folder in their source tree, e.g. stuart sierra’s component project has a dev sub folder https://github.com/stuartsierra/component/tree/master https://github.com/stuartsierra/component/tree/master with repl examples in addition to the tests. I missed a trick in life, i started getting into Clojure in 2020 but about 5 years ago i used to sit 1 row of desks away from Stuart Sierra in Stirling and I don’t think i ever properly spoke to him save for hello or so. It was a funny setup in that operation, i had to fight for my small team to even have office space at the time!
- diggan 6y agoGood callout! Adding "dev" files for facilitating REPL development is one way, adding something called "rich comments" is another one (that I tend to gravitate towards) where you have comment blocks (actual code, not commented code) in the same ns as the actual functions, exploring the usage of the functions. Was recently on the HN frontpage as well, https://betweentwoparens.com/rich-comment-blocks https://betweentwoparens.com/rich-comment-blocks - https://news.ycombinator.com/item?id=24718478 https://news.ycombinator.com/item?id=24718478
- Scarbutt 6y ago* but is there a way of easily converting a REPL sessions into a suite of tests?* Yes, it's called discipline ;) In Clojure(or JS for example) you have to rely more on being disciplined around tests and documentation than with a statically typed language.