Stream: beginners

Topic: Expects in type definition not running with `roc test`


view this post on Zulip Hannes (Aug 10 2026 at 07:57):

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 :)

view this post on Zulip Luke Boswell (Aug 10 2026 at 08:01):

I dont think it's been discussed before.

view this post on Zulip Luke Boswell (Aug 10 2026 at 08:01):

They run for top-level, but I'm not sure if we've considered nested inside a type module like this

view this post on Zulip Luke Boswell (Aug 10 2026 at 08:02):

They also run inside an expression, but this use case is different

view this post on Zulip Richard Feldman (Aug 10 2026 at 10:45):

yeah I think we should be running these - can you open an issue with type=bug?

view this post on Zulip Aurélien Geron (Aug 10 2026 at 11:03):

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.

view this post on Zulip Hannes (Aug 11 2026 at 07:38):

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