I've been doing TDD of my first Roc function.
To get roc test
to find my expectations I had to reference my new module from the main script.
When I added the module I got a warning (when running my tests) saying the module isn't being used.
It's not being used yet because I'm in the process of TDDing it.
How do others approach TDD in Roc? Should roc test
pick up all expectations even if they are for code that isn't being used yet? Or do I just have to add every module I'm testing to the main code file and suffer the warnings while I'm TDDing?
Cheers
Ash
Can you run roc test on just your new module?
If it doesn't import anything then this should work ok
Should something like this work:
roc test --linker legacy headings.roc
Yeah, that should work
I'm getting a crash doing that:
> roc test --linker legacy headings.roc
thread 'main' panicked at crates/compiler/load_internal/src/file.rs:364:85:
called `Option::unwrap()` on a `None` value
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
Running under WSL2/Linux under Windows. It's a nightly build from a couple of days ago.
Is there anyway to make roc test
just pick up all tests in my project regardless of whether the code is actually used yet?
That’s interesting. Can you open an issue for it? It might be helpful to see the output of roc check
too
Nothing comes up from roc check
:
0 errors and 0 warnings found in 875 ms
Is that for the module or the whole app?
Just for reference, I have done tdd in roc before with this:
find . -name "*.roc" | entr -ccr roc test /_
Will run roc test on any roc file when it changes. That said, it won't automatically index new files. Just those that already exist.
Whole app I guess.
Try roc check {YourModule}.roc
Ok wow that's a bit different.
> roc check headings.roc
An internal compiler expectation was broken.
This is definitely a compiler bug.
Please file an issue here: https://github.com/roc-lang/roc/issues/new/choose
thread 'main' panicked at crates/compiler/load_internal/src/file.rs:3556:29:
Outstanding references to the derived module
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
I've pushed the code already. I'm working on a chapter of the Roc "book of examples":
https://github.com/ashleydavis/book-of-examples/tree/main/gallery/roc
In my next session I'll try an updated build and then maybe log an issue.
Pls let me know if there's any resources already out to help me understand how to TDD in Roc.
List.len(headingA)
looks like incorrect syntax. In roc we dont need brackets, so I think this should be if List.len headingA == List.len headingB then
Oh good catch thanks.
roc check
still crashes though.
Last updated: Jul 06 2025 at 12:14 UTC