Make main! optional under roc test - #10830
Draft
rtfeldman wants to merge 1 commit into
Draft
Conversation
`roc test` runs only the top-level `expect`s in a file, so the root file needs no entrypoint. A headerless file that is neither a type module nor a default app is now compiled as a plain module under `roc test` instead of being rejected for having no `main!`. The root module of a `roc test` build gets the same validation that `--main` entry modules already used, threaded through as an explicit `Can.Validation` mode rather than a bool.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
It is common to have a
.rocfile that exists purely for tests — a bunch of top-levelexpects meant to be run withroc test foo.roc, which is how Exercism programs are laid out, for example. Until now such a file still had to definemain! = |_| Ok({}), even though nothing ever calls it. Beyond being a papercut, that carries a real hazard: the file looks runnable, so a CI script that saysroc foo.rocorroc build foo.rocby mistake can appear to succeed without ever having run the tests.roc testnow requires no entrypoint at all: a headerless file that is neither a type module nor a default app is compiled as a plain module, and itsexpects run as usual.The
main!requirement only ever came from canonicalization. A headerless file starts out as a candidate type module; if it has a valid one-argumentmain!it becomes a default app, and otherwisevalidateForCheckingdemands either a nominal type matching the file name or amain!, reportingdefault_app_missing_mainortype_module_missing_matching_type. Nothing in theroc testpipeline itself wants amain!— the expects are collected as compile-time roots on their own — so the diagnostic was the entire obstacle, and it maderoc testexit non-zero even while printing that every test passed.The fix reuses the validation that
--mainentry modules already got, where a headerless file that resolves to neither shape simply becomes a plain module with its top-level types exposed. That mode was selected by avalidate_as_explicit_rootsbool threaded fromBuildEnvthrough the coordinator tocanonicalizeModuleWithSiblings; it is now an explicitCan.Validationenum (.checking/.explicit_roots) owning the dispatch, which also lets the playground drop its private duplicate of the same two-case enum.roc testsets it on the build's root module via the newBuildEnv.setRootValidation.roc check,roc build, androc <file>are deliberately untouched and still reject an entrypoint-less file, so the mistaken-CI-invocation case stays loud. Type modules,module-header files, apps with a platform, and default apps with a realmain!all behave exactly as before underroc test.