Stream: ideas

Topic: Pretty expect


view this post on Zulip Joshua Warner (Dec 07 2022 at 19:56):

How hard would it be to do effectively the same thing as rust's pretty_assertions library, but with Roc's expect. I'm currently running this - and it'd be _really_ nice if I could get a diff of what's wrong:

── EXPECT FAILED ─────────────────────────────────────────────── generator.roc ─

This expectation failed:

150│>  expect (render (Items [Text "{", Indent (Line (Text "foo")), Text "}"])) ==
151│>      """
152│>      {
153│>          foo
154│>      }
155│>      """

view this post on Zulip Folkert de Vries (Dec 07 2022 at 20:00):

if you bind both sides of the expect to a variable then at least it'll print out the value

view this post on Zulip Folkert de Vries (Dec 07 2022 at 20:00):

assuming this is toplevel, that would be

expect
    x = (render (Items [Text "{", Indent (Line (Text "foo")), Text "}"]))

    expect x ==
        """
        {
            foo
        }
        """

view this post on Zulip Joshua Warner (Dec 07 2022 at 20:10):

Aha, yep, that works (minus the extra expect on line 4)

view this post on Zulip Joshua Warner (Dec 07 2022 at 20:11):

FWIW, I tried this:

expect
    dbg (render (Line (Text "foo")))
    1 == 1

... which then hits unreachable code:

thread '<unnamed>' panicked at 'internal error: entered unreachable code: I think this is unreachable', crates/compiler/mono/src/ir.rs:4503:23

view this post on Zulip Richard Feldman (Dec 07 2022 at 20:28):

yeah there's a lot of room for improvement here! I'd like to eventually get into things like nicer diffs, but I think short-term the bigger deal is fixing bugs around expect and dbg :big_smile:


Last updated: Jun 16 2026 at 16:19 UTC