Skip to main content

mojo test

Execute unit, integration, and documentation tests.

Synopsis

mojo test [options] <input>
mojo test [options] <input>

Description

Execute the given Mojo tests.

Options

Collection options

--collect-only, --co

Only collect tests, don't execute them.

--filter <REGEX>

A POSIX extended regular expression regex string that will be used to filter test IDs. See https://en.wikibooks.org/wiki/Regular_Expressions/POSIX-Extended_Regular_Expressions for more information.

Test run options

--debug

Launch a debugger session with mojo debug. This is not supported for docstring tests. Most debug flags are supported, including --vscode.

Compilation options

--optimization-level <LEVEL>, -O, --no-optimization (LEVEL=0)

Sets the level of optimization to use at compilation. The value must be a number between 0 and 3. The default is 3.

-I <PATH>

Appends the given path to the list of directories to search for imported Mojo files.

-D <KEY=VALUE>

Defines a named value that can be used from within the Mojo source file being executed. For example, -D foo=42 defines a name foo that, when queried with the sys.param_env module from within the Mojo program, would yield the compile-time value 42.

--debug-level <LEVEL>, -g (LEVEL=full)

Sets the level of debug info to use at compilation. The value must be one of: none (the default value), line-tables, or full. Please note that there are issues when generating debug info for some Mojo programs that have yet to be addressed.

Target options

--target-triple <TRIPLE>

Sets the compilation target triple. Defaults to the host target.

--target-cpu <CPU>

Sets the compilation target CPU. Defaults to the host CPU.

--target-features <FEATURES>

Sets the compilation target CPU features. Defaults to the host features.

--march <ARCHITECTURE>

Sets the architecture for which to generate code.

--mcpu <CPU>

Sets the CPU for which to generate code.

--mtune <TUNE>

Sets the CPU for which to tune code.

Compilation diagnostic options

Controls how the Mojo compiler outputs diagnostics related to compiling and running Mojo source code.

--diagnose-missing-doc-strings

Emits diagnostics for missing or partial doc strings.

--validate-doc-strings

Emits errors for invalid doc strings instead of warnings.

--max-notes-per-diagnostic <INTEGER>

When the Mojo compiler emits diagnostics, it sometimes also prints notes with additional information. This option sets an upper threshold on the number of notes that can be printed with a diagnostic. If not specified, the default maximum is 10.

Debugger options

--X <ARG>

Passes ARG as an argument to the debugger when the debug session is launched using the debugger command-line interface. This option can be specified multiple times. It is ignored when using the RPC mode.

Debug server options

--vscode

Launches the debug session on VS Code via the Mojo extension.

--rpc

Alias for --vscode.

--terminal <TERMINAL>

The type of terminal to use when starting a launch debug session.

  • console (default): the debuggee will be launched in the default environment for the editor. If using VS Code, this will be the Debug Console.
  • dedicated: the debuggee will be launched in a dedicated terminal within the editor.

--port <PORT>

Uses the given PORT to communicate with the RPC debug server. Defaults to trying all ports from 12355 to 12364 inclusive.

--stop-on-entry

Automatically stop after launch.

--init-command <INIT_COMMAND>

Initialization command executed upon debugger startup. Can be specified multiple times.

Experimental compilation options

--sanitize <CHECK>

Turns on runtime checks. The following values are supported: address (detects memory issues), and thread (detects multi-threading issues).

--debug-info-language <LANGUAGE>

Sets the language to emit as part of the debug info. The supported languages are: Mojo, and C. C is the default, and is useful to enable rudimentary debugging and binary introspection in tools that don't understand Mojo.

Common options

--diagnostic-format <FORMAT>

The format in which diagnostics and error messages are printed. Must be one of "text" or "json" ("text" is the default).

--help, -h

Displays help information.