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.
It also makes some code examples a bit cleaner.
oh that's a good idea!
I can't think of any downsides :thumbs_up:
I'll make a PR
ok this now works on main!
(pun intended?)
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({}).
ah yep, that's a quick fix too - I'll make a pr
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", "é"]
@Aurélien Geron that's unrelated, but definitely seems reasonable to add :thumbs_up:
do you need it for Exercism?
also, main! is no longer necessary for roc test as of https://github.com/roc-lang/roc/pull/10855
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