9.3 Using main and test Submodules
Rhombus makes no syntactic distinction between a module that is intended as a library (to import into other modules) and the main module of a program. Sometimes, though, it’s convenient to use the same module for both purposes, but have additional actions taken when a module is run as the main module. When DrRacket, rhombus, or racket runs a Rhombus module, it looks for a submodule named main and loads that module if present.
For example, this module exports a greeting function for use in other modules, but if it is run directly, then it calls greeting and (implicitly) prints the result:
greeting
fun greeting():
"hello"
module main:
greeting()
In addition, DrRacket looks for a test submodule and runs that, too, which makes test useful to hold unit tests that should run while the module is being developed, but not when the module is deployed as a library or main program.
To run tests for "prog.rhm" on the command line, either name the test submodule directly with
The ! is quoted in this example, because ! is a special character in most command-line shells. Your shell and its quoting form may vary.
racket prog.rhm'!'test
or use Racket’s raco test tool as
raco test prog.rhm