Are expect statements in type definitions supposed to run with roc test?
For example, this expect is not being run with roc test:
Ascii :: List(Char).{
from_chars : List(Char) -> Ascii
from_chars = |chars| Ascii.(chars)
to_chars : Ascii -> List(Char)
to_chars = |Ascii.(chars)| chars
## Round trip test
expect {
hello_chars = [
Char.from_ascii_byte('h') ?? {
crash "Unreachable"
},
Char.from_ascii_byte('e') ?? {
crash "Unreachable"
},
Char.from_ascii_byte('l') ?? {
crash "Unreachable"
},
Char.from_ascii_byte('l') ?? {
crash "Unreachable"
},
Char.from_ascii_byte('o') ?? {
crash "Unreachable"
},
]
out = Ascii.from_chars(hello_chars).to_chars()
out == hello_chars
}
}
Cheers :)
I dont think it's been discussed before.
They run for top-level, but I'm not sure if we've considered nested inside a type module like this
They also run inside an expression, but this use case is different
yeah I think we should be running these - can you open an issue with type=bug?
On a related topic, it would be great to support nested expect statements:
expect {
a = 2
expect a * 3 == 6
b = a + 3
expect b == 5
c = b * 3
c == 15
}
I've run into these in Exercism exercises where we have a data structure, we run a sequence of modifications, and we want to test the intermediate states. Of course we could separate each test, but it would be much more verbose and really wouldn't make things much cleaner, probably the opposite. The way I worked around that is by implementing an expect_equal function and calling something like expect_equal(a * 3, 6)?. It works but it looks weird.
Oh it looks like we've discussed this before.
Here's the issue, I couldn't tag it as a bug though: https://github.com/roc-lang/roc/issues/10730
Last updated: Aug 12 2026 at 12:35 UTC