Stream: beginners

Topic: How to see values from failing top-level `expect` statements


view this post on Zulip Daniel (Nov 06 2026 at 18:20):

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?

view this post on Zulip Anton (Nov 06 2026 at 18:49):

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"
}

view this post on Zulip Daniel (Nov 06 2026 at 19:00):

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.

view this post on Zulip Daniel (Nov 06 2026 at 19:01):

Ah, another question. I noticed that expect requires the expression to be pure. Is there any way to test effectful functions?

view this post on Zulip Anton (Nov 06 2026 at 19:08):

Yes, you can :)
This should do it:

check = |received, expected| {
    ok = received == expected
    if !ok {
        dbg { expected, received }
    }
    ok
}

view this post on Zulip notramo (Nov 06 2026 at 19:09):

This is too much typing.

view this post on Zulip notramo (Nov 06 2026 at 19:09):

Are transparent dbg statements planned?

view this post on Zulip Anton (Nov 06 2026 at 19:09):

Daniel said:

Ah, another question. I noticed that expect requires 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.

view this post on Zulip notramo (Nov 06 2026 at 19:10):

Are transparent dbg statements 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.

view this post on Zulip Anton (Nov 06 2026 at 19:11):

We used to have that, I'm not sure about the plans @Richard Feldman

view this post on Zulip notramo (Nov 06 2026 at 19:15):

Why was it removed? Is it a missing reimplementation from the rewrite? Or was there some other reason for removing it?

view this post on Zulip Anton (Nov 06 2026 at 19:15):

Yeah missing reimplementation I think

view this post on Zulip Richard Feldman (Nov 06 2026 at 19:16):

yeah it'll be something for after 0.1.0

view this post on Zulip Richard Feldman (Nov 06 2026 at 19:16):

the way we were doing it before wouldn't work in the new compiler

view this post on Zulip Richard Feldman (Nov 06 2026 at 19:17):

so it needs to be implemented from scratch

view this post on Zulip Richard Feldman (Nov 06 2026 at 19:17):

which is fine, just not something I think we should try to slip under the wire for 0.1.0

view this post on Zulip Anton (Nov 06 2026 at 19:18):

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