The language reference says this about top level expect:
When one fails, the report shows the failing expression, along with the values of any top-level names it referenced.
I get output telling me which excpect test failed, but it doesn't show me any debug representation of the values it failed with. For example:
double = |n| n * 2
# failing test
expect double(21) == 43
The output just shows me that line, but it doesn't say what the value of double(21) In other languages, I would expect to see something like 42 == 43, so I can see _why_ my test is failing.
I can sort of get around it by writing tests like so, but this feels pretty tedious:
expect {
got = norm("../../A/B")
res = got == "../../A/B"
if !res {
dbg got
}
res
}
Is there a better way, or perhaps I am missing something? Or is this just a known limitation of the expect statement?
Hi @Daniel,
The docs are indeed incorrect, the nice version of this feature is planned for after 0.1. I will correct the docs.
You can improve the workaround like this:
expect {
got = norm("../../A/B")
dbg got
got == "../../A/B"
}
Thanks for the reply. Since this pattern seems pretty common, can I write some helper function which does the dbg statement, that I can use like expect check_eq(norm("../../A/B", "../../A/B")? I'm not sure how expect plays with that sort of thing.
Ah, another question. I noticed that expect requires the expression to be pure. Is there any way to test effectful functions?
Yes, you can :)
This should do it:
check = |received, expected| {
ok = received == expected
if !ok {
dbg { expected, received }
}
ok
}
This is too much typing.
Are transparent dbg statements planned?
Daniel said:
Ah, another question. I noticed that
expectrequires the expression to be pure. Is there any way to test effectful functions?
The nice way to do this is also planned for after 0.1 unfortunately, let me see if I can find a good example showing the current workaround.
Are transparent
dbgstatements planned?
Currently a dbg results in {}, so it has to be its own statement. However, if it would return the printed value, it could be dropped into the expression, without introducing a new variable and (sometimes) a block.
We used to have that, I'm not sure about the plans @Richard Feldman
Why was it removed? Is it a missing reimplementation from the rewrite? Or was there some other reason for removing it?
Yeah missing reimplementation I think
yeah it'll be something for after 0.1.0
the way we were doing it before wouldn't work in the new compiler
so it needs to be implemented from scratch
which is fine, just not something I think we should try to slip under the wire for 0.1.0
let me see if I can find a good example showing the current workaround.
https://github.com/exercism/roc/blob/main/exercises/practice/paasio/paasio-test.roc
Last updated: Nov 26 2026 at 20:35 UTC