Stream: ideas

Topic: Make `main!` optional when using `roc test`


view this post on Zulip Aurélien Geron (Aug 16 2026 at 23:32):

It's common to have a foo.roc file meant for tests only (e.g., that's how all Exercism programs work). This program contains a bunch of expect statements, and it is used exclusively with roc test foo.roc. However, the compiler requires adding main! = |_| Ok({}), even though it is unused. This is a slight inconvenience, but more importantly there's a risk that users (e.g., CI scripts) might use roc foo.roc or roc build foo.roc by mistake, wrongly concluding that the tests pass when in fact they haven't even run.

This is why I propose that main! be optional when using roc test.

view this post on Zulip Aurélien Geron (Aug 16 2026 at 23:33):

It also makes some code examples a bit cleaner.

view this post on Zulip Richard Feldman (Aug 17 2026 at 00:19):

oh that's a good idea!

view this post on Zulip Richard Feldman (Aug 17 2026 at 00:19):

I can't think of any downsides :thumbs_up:

view this post on Zulip Richard Feldman (Aug 17 2026 at 00:24):

I'll make a PR

view this post on Zulip Richard Feldman (Aug 17 2026 at 12:57):

ok this now works on main!

view this post on Zulip Matthieu Pizenberg (Aug 17 2026 at 15:03):

(pun intended?)

view this post on Zulip Aurélien Geron (Aug 18 2026 at 07:30):

It looks like roc test works fine without a main! function when using the echo platform, but not with other platforms, or when using libraries?

For example, roc test fails on this code:

app [main!] {
    pf: platform "https://github.com/roc-lang/basic-cli/releases/download/0.22.0/F1JVZPYfWP71s8vk6tHcV1Qx1Ef6CZkwswGoCn8VHZmL.tar.zst",
    unicode: "https://github.com/roc-lang/unicode/releases/download/4.0.0/3DGC3M4b2pxaRLg4i8cmxWkm2E2WbCPCLntQzf2mkbUV.tar.zst",
}

import unicode.Grapheme

expect Grapheme.owned("café") == ["c", "a", "f", "é"]

But it works if you add main! = |_| Ok({}).

view this post on Zulip Richard Feldman (Aug 18 2026 at 11:25):

ah yep, that's a quick fix too - I'll make a pr

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

Thanks @Richard Feldman . Not sure whether it's closely related or not, but it would be great to be able to use libraries with the echo platform, for example:

app [main!] {
    unicode: "https://github.com/roc-lang/unicode/releases/download/4.0.0/3DGC3M4b2pxaRLg4i8cmxWkm2E2WbCPCLntQzf2mkbUV.tar.zst",
}

import unicode.Grapheme

main! = |_| {
    echo!(Grapheme.owned("café") |> Str.inspect)
    Ok({})
}

Or even (combining both features):

app [] {
    unicode: "https://github.com/roc-lang/unicode/releases/download/4.0.0/3DGC3M4b2pxaRLg4i8cmxWkm2E2WbCPCLntQzf2mkbUV.tar.zst",
}

import unicode.Grapheme

expect Grapheme.owned("café") == ["c", "a", "f", "é"]

view this post on Zulip Richard Feldman (Aug 20 2026 at 03:27):

@Aurélien Geron that's unrelated, but definitely seems reasonable to add :thumbs_up:

view this post on Zulip Richard Feldman (Aug 20 2026 at 03:27):

do you need it for Exercism?

view this post on Zulip Richard Feldman (Aug 20 2026 at 03:27):

also, main! is no longer necessary for roc test as of https://github.com/roc-lang/roc/pull/10855

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

Thanks @Richard Feldman . Yes, it would be nice for Exercism, as the platform is almost never actually used, so it would remove one dependency. Also, I think it would be useful for code examples, especially in packages.


Last updated: Sep 03 2026 at 15:16 UTC