A simple and powerful testing toolkit for MoonBit CLI applications and Script
Dependencies
| Decision | Rule |
|---|---|
| Write a command | Commands do not run through a shell. Environment variables and wildcards in arguments remain literal. |
| Select output to assert | By default, only stdout and the program's exit code are asserted. To assert stderr, include both @STDOUT and @STDERR markers. |
| Select a backend | Scripts and remote packages always use Wasm. --target selects the backend for local packages. |
| Resolve paths | Local modules are read from moon.mod directly in the startup directory. Scripts and relative file arguments use the block's working directory: the document directory by default, or its #cwd directory. |
| Run or preview | test, update, and update --dry-run execute code with your permissions, without a sandbox or temporary workspace isolation. The default 60000 ms case timeout includes builds, remote fetching, execution, and output capture. |
| Review an update | Passing cases are processed too; expectations and fences may be normalized. An execution error blocks all expectation updates in that document; other documents can still update. |
| Interpret exit codes | Mooncram's exit code is independent of the tested program's expected code. Dry-run can report mismatches and return 0; use test for CI. |
git clone https://github.com/moonbit-community/mooncram.git
cd mooncram
moon update
moon run . -- test README.md$ moonx ./examples/hello.mbtx "Moon Bit"
Hello, Moon Bit!1 cases, 0 failed, 0 errorsmoon install https://github.com/moonbit-community/mooncram
mooncram --helptests/
├── hello.mbtx
└── hello.mdfn main {
println("Hello, MoonBit!")
}# Greeting
The script greets the user.
```mooncram
$ moonx ./hello.mbtx
Hello, MoonBit!
```mooncram test tests/hello.md```mooncram
$ moonx ./hello.mbtx "Moon Bit"
Hello, Moon Bit!
``````mooncram user/acme
$ moonx user/acme/cmd/acme --version
acme 1.0.0
``````mooncram
$ moonx moonbit-community/mooncram@0.0.3 --version
0.0.3
``````mooncram user/acme
$ moonx user/acme/cmd/acme --unknown
@STDOUT (empty)
@STDERR
error: unknown option --unknown
[2]
``````mooncram user/acme
$ moonx user/acme/cmd/acme --version
acme * (glob)
$ moonx user/acme/cmd/acme --version
acme [0-9]+\.[0-9]+\.[0-9]+ (regex)
```| Suffix | What it checks |
|---|---|
| None | The exact output line |
| (glob) | A whole-line pattern with *, ?, or character sets such as [a-z] |
| (regex) | A regular expression matching the whole line |
| (escaped) | An exact line written as a JSON string, such as "a\tb" |
| (no-eol) | The last output line has no terminating newline; may follow another suffix |
import { "moonbitlang/core/env" }
fn main {
let name = @env.get_env_var("NAME").unwrap_or("World")
println("Hello, \{name}!")
}```mooncram
$ NAME='Moon Bit' moonx ./environment.mbtx
Hello, Moon Bit!
$ NAME=World moonx ./environment.mbtx
Hello, World!
``````mooncram
#cwd(../examples)
$ moonx ./hello.mbtx "Moon Bit"
Hello, Moon Bit!
``````mooncram user/acme
$ moonx ./input.mbtx | moonx user/acme/cmd/acme --uppercase
HELLO, MOONBIT!
```mooncram update tests --dry-run
mooncram update tests
mooncram test testsmooncram check testsmooncram check [paths...] [--color auto|always|never]
mooncram test [paths...] [--target wasm|native] [--timeout-ms N]
mooncram update [paths...] [--target wasm|native] [--timeout-ms N] [--dry-run]
mooncram docs --list
mooncram docs <document-name>
mooncram --help
mooncram --version| Status | Meaning |
|---|---|
| 0 | Documentation, check, test, or update completed successfully |
| 1 | An output or exit-code assertion failed in test |
| 2 | Invalid arguments, a parsing/build/execution error, or no cases found |
moon test
moon test --target native
moon run . -- test README.md README_CN.md
node e2etests/integration.mjs
moon info && moon fmtInstall
Download zipA simple and powerful testing toolkit for MoonBit CLI applications and Script
Dependencies