I find myself sometimes wanting to test effectful functions in roc, but as far as I know expect's should be pure.
── ✗ effectful expect ─────────────── /home/rw/media/repos/roc/plainaipha/pa2html/lib/Gnuplot.roc:27:3
This expect performs an effect while evaluating its condition.
expect {
_ = gnuplot!([])
True
}
Keep expect conditions pure, and test effectful behavior from a function body instead.
So I am suggesting to introduce a new keyword: expect!which allows effectful testing and runs every expect! as it's own small main function . This would be consistent with naming in roc, because of the: !.
One could also introduce a new cli arg, to only run these tests on demand or something, like roc test --with-effectful or roc test-effectful.
In addition something similar to @embedFile, which evaluates a file at compile time and puts it content into the binary would be really helpful. Maybe this could be an keyword e.g. embedFile, imo this would be worth. I do not know if there is any meta programming planned, tho.
What do you think?
We have given some thought to the testing of effectful functions, is there a design doc for this @Richard Feldman?
I don't think there's a doc, but it's definitely planned for after 0.1.0 :smile:
basically we need to introduce a way for platforms to specify "here is how to run an effectful function just for testing purposes" and there are a bunch of design questions in there that need to be sorted out
and I don't want to block 0.1.0 on them
My workaround while waiting for built-in effectful tests in Roc is: https://github.com/niclas-ahden/roc-spec
Good to know that it is planned, nice.
What about embed Files, is this a feature that could be introduced before 0.1.0?
You can embed a file at compile time using import statements
Here is an example https://github.com/lukewilliamboswell/roc-ray/blob/263383ff67f1b2b06e937387b9c4d4e71c7fa292/examples/live_plot/main.roc#L17
Last updated: Sep 24 2026 at 15:59 UTC