Stream: beginners

Topic: For TDD in Roc do I have to reference every module in main?


view this post on Zulip Ashley Davis (Jun 18 2024 at 22:18):

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

view this post on Zulip Luke Boswell (Jun 18 2024 at 22:20):

Can you run roc test on just your new module?

view this post on Zulip Luke Boswell (Jun 18 2024 at 22:20):

If it doesn't import anything then this should work ok

view this post on Zulip Ashley Davis (Jun 18 2024 at 22:21):

Should something like this work:

roc test --linker legacy headings.roc

view this post on Zulip Agus Zubiaga (Jun 18 2024 at 22:22):

Yeah, that should work

view this post on Zulip Ashley Davis (Jun 18 2024 at 22:25):

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.

view this post on Zulip Ashley Davis (Jun 18 2024 at 22:26):

Is there anyway to make roc test just pick up all tests in my project regardless of whether the code is actually used yet?

view this post on Zulip Agus Zubiaga (Jun 18 2024 at 22:27):

That’s interesting. Can you open an issue for it? It might be helpful to see the output of roc check too

view this post on Zulip Ashley Davis (Jun 18 2024 at 22:28):

Nothing comes up from roc check:

0 errors and 0 warnings found in 875 ms

view this post on Zulip Agus Zubiaga (Jun 18 2024 at 22:29):

Is that for the module or the whole app?

view this post on Zulip Brendan Hansknecht (Jun 18 2024 at 22:30):

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.

view this post on Zulip Ashley Davis (Jun 18 2024 at 22:30):

Whole app I guess.

view this post on Zulip Agus Zubiaga (Jun 18 2024 at 22:30):

Try roc check {YourModule}.roc

view this post on Zulip Ashley Davis (Jun 18 2024 at 22:31):

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

view this post on Zulip Ashley Davis (Jun 18 2024 at 22:32):

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

view this post on Zulip Ashley Davis (Jun 18 2024 at 22:33):

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.

view this post on Zulip Luke Boswell (Jun 18 2024 at 22:37):

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

view this post on Zulip Ashley Davis (Jun 18 2024 at 22:43):

Oh good catch thanks.

roc check still crashes though.


Last updated: Jul 06 2025 at 12:14 UTC