forc-test

Run the Sway unit tests for the current project.

NOTE: This feature is not yet implemented. Track progress at the following link: https://github.com/FuelLabs/sway/issues/1832

NOTE: Previously this command was used to support Rust integration testing, however the provided behaviour served no benefit over running cargo test directly. The proposal to change the behaviour to support unit testing can be found at the following link: https://github.com/FuelLabs/sway/issues/1833

Sway unit tests are functions decorated with the #[test] attribute. Each test is compiled as a unique entry point for a single program and has access to the namespace of the module in which it is declared.

Unit tests decorated with the #[test(script)] attribute that are declared within contract projects may also call directly into their associated contract's ABI.

Upon successful compilation, test scripts are executed to their completion. A test is considered a failure in the case that a revert (rvrt) instruction is encountered during execution. Otherwise, it is considered a success.

USAGE:

forc test [OPTIONS] [FILTER]

ARGS:

<FILTER> When specified, only tests containing the given string will be executed

OPTIONS:

--build-profile <BUILD_PROFILE>

Name of the build profile to use. If it is not specified, forc will use debug build profile

-g, --debug-outfile <DEBUG_OUTFILE>

If set, outputs source file mapping in JSON format

-h, --help

Print help information

-L, --log-level <LOG_LEVEL>

Set the log level

--locked

Requires that the Forc.lock file is up-to-date. If the lock file is missing, or it needs to be updated, Forc will exit with an error

--minify-json-abi

By default the JSON for ABIs is formatted for human readability. By using this option JSON output will be "minified", i.e. all on one line without whitespace

--minify-json-storage-slots

By default the JSON for initial storage slots is formatted for human readability. By using this option JSON output will be "minified", i.e. all on one line without whitespace

-o <BINARY_OUTFILE>

If set, outputs a binary file representing the script bytes

--offline

Offline mode, prevents Forc from using the network when managing dependencies. Meaning it will only try to use previously downloaded dependencies

--output-directory <OUTPUT_DIRECTORY>

The directory in which the sway compiler output artifacts are placed.

By default, this is <project-root>/out.

-p, --path <PATH>

Path to the project, if not specified, current working directory will be used

--print-ast

Print the generated Sway AST (Abstract Syntax Tree)

--print-finalized-asm

Print the finalized ASM.

This is the state of the ASM with registers allocated and optimisations applied.

--print-intermediate-asm

Print the generated ASM.

This is the state of the ASM prior to performing register allocation and other ASM optimisations.

--print-ir

Print the generated Sway IR (Intermediate Representation)

--release

Use release build plan. If a custom release plan is not specified, it is implicitly added to the manifest file.

If --build-profile is also provided, forc omits this flag and uses provided build-profile.

-s, --silent

Silence all output

-t, --terse

Terse mode. Limited warning and error output

--time-phases

Output the time elapsed over each part of the compilation process

--unstable

Enable the incomplete, unstable unit testing support. Warning: May create a black hole!

This is purely for Sway devs to test the unit testing functionality until it stabilises, and will be removed upon stabilisation of the command.

-v, --verbose

Use verbose output