Stream: beginners

Topic: testing with expect


view this post on Zulip Rick Hull (Jan 20 2026 at 18:24):

here is how I run tests, via just test https://gist.github.com/rickhull/ad4af8984a40d538ea1e1999af613492

This is the within-block usage of expect, not a "unit test" (as I understand these terms). Is this the right way to do the accounting, or am I misusing or under-utilizing Roc / expect features?

view this post on Zulip Anton (Jan 20 2026 at 18:26):

We have typically been using top level expects defined in the same file as the source for testing.

view this post on Zulip Rick Hull (Jan 20 2026 at 18:32):

then you would issue roc test right? how do you perform a comprehensive run across multiple files?

view this post on Zulip Anton (Jan 20 2026 at 18:34):

then you would issue roc test right?

Yes

how do you perform a comprehensive run across multiple files?

In the past with a bash script although I would like (as a new feature) the roc binary to auto-discover all tests in a project.

view this post on Zulip Rick Hull (Jan 20 2026 at 18:36):

you could allow roc test PATH where PATH is like a subdir. for a dir, recursive search all .roc files?

view this post on Zulip Anton (Jan 20 2026 at 18:37):

Sounds good to me :)

view this post on Zulip Rick Hull (Jan 20 2026 at 20:19):

because I am doing platform development, and host functions are impure, then I cannot use toplevel expect for these functions right? i think I need the justfile runner

view this post on Zulip Rick Hull (Jan 20 2026 at 20:26):

it's a little confusing about the different expect behaviors in different contexts (toplevel vs not, pure vs impure, roc test vs roc). I wonder if there is a way to unify the behaviors.

@Richard Feldman said:

the number one rule of expect is that it never affects control flow in any way
no matter where it is used
it is a harmless report
maybe a better way to think of it is "debug print that an expectation was false, and then mark this test as 'must fail' when it finishes running"

view this post on Zulip Luke Boswell (Jan 20 2026 at 20:58):

Keep in mind that it's possible that things aren't yet implemented, or if they are it's a first pass and needs polish. I have been slow rolling the platform development and fixings bugs as I find them. Almost everything I've worked on has had a few significant bugs, and most of my time was spent trying to understand what the behaviour should be so I could properly isolate and describe the bug. If you find any issues it would be helpful to investigate, it's probably not you but just something is broken.

view this post on Zulip Rick Hull (Jan 20 2026 at 21:01):

Thanks Luke; to answer my own question a bit, I keep all my "host functions" in platform/Host.roc, though it's not necessary to do it this way. I have now isolated all my impure function testing to test/host.roc, which only calls functions from platform/Host.roc; thus I don't need a "test runner" at this point as I only have a single test/*.roc file

I migrated all other test/*.roc tests to "unit tests" at the toplevel within the source-file-under-test

view this post on Zulip Rick Hull (Jan 20 2026 at 21:25):

roc test DIR: https://github.com/roc-lang/roc/issues/9057


Last updated: Feb 20 2026 at 12:27 UTC