runner
import std::test::runner; · source
Types
RunOptions
type struct RunOptions {
filter: String;
exact: boolean;
include_ignored: boolean;
list_only: boolean;
quiet: boolean;
format: TestFormat;
format_explicit: boolean;
color: ColorMode;
color_explicit: boolean;
color_active: boolean;
timeout_secs: u32;
timeout_explicit: boolean;
jobs: u32;
jobs_explicit: boolean;
capture: boolean;
show_output: boolean;
child_idx: i64;
static default() -> RunOptions;
}
The parsed command line: a name filter and whether it must match exactly, include_ignored, list_only, quiet, per-test timeout_secs, parallel jobs, and whether to capture or show_output. default() is what an empty command line parses to.
Properties
| Property | Type | Notes |
|---|---|---|
filter | String | Substring filter: empty means "match everything". |
exact | boolean | |
include_ignored | boolean | |
list_only | boolean | |
quiet | boolean | |
format | TestFormat | |
format_explicit | boolean | True if the user explicitly passed --format=.... Used to decide whether env-var or cryoconfig defaults can override. |
color | ColorMode | |
color_explicit | boolean | |
color_active | boolean | Resolved once at the start of run_all: did color plus the TTY check land on "emit escapes". Reporters consult this flag rather than re-evaluating the policy on each test. |
timeout_secs | u32 | Per-test wall-clock limit in seconds. The child arms alarm() with this value before running; 0 disables the watchdog. |
timeout_explicit | boolean | True if --timeout= was passed explicitly (suppresses the CRYO_TEST_TIMEOUT env default). |
jobs | u32 | Number of worker threads to drive tests in parallel. 0 means "auto" -> resolved to the online CPU count at the start of run_all. 1 forces the classic sequential path. Each worker still runs every test in its own child process, so parallelism does not weaken crash / should_panic isolation. |
jobs_explicit | boolean | True if --jobs=/-j was passed explicitly (suppresses the CRYO_TEST_JOBS env default). |
capture | boolean | Capture each test's stdout+stderr into a per-test buffer instead of letting it stream to the terminal. On (the default) the buffer is replayed only for failing tests, so a green parallel run stays clean. --nocapture (or CRYO_TEST_NOCAPTURE) turns this off: the child inherits the parent's stdio and writes live, the pre-capture behaviour. |
show_output | boolean | Show captured output for passing tests too, not just failures. Set by --show-output. No effect when capture is off. |
child_idx | i64 | Re-exec child selector: >= 0 means "run only descriptors[child_idx] and exit 0/1, no header/loop". Set by the internal --test-runner-child=<n> flag the Windows runner passes when it CreateProcess-re-execs the test binary once per test (Windows has no fork, so each test runs in a fresh process selected by index). |
Constructors
static default() -> RunOptions;
TestFormat and ColorMode
type enum TestFormat {
Plain;
Pretty;
Compact;
}
type enum ColorMode {
Auto;
Always;
Never;
}
TestFormat
Variants
| Variant |
|---|
Plain |
Pretty |
Compact |
ColorMode
Variants
| Variant |
|---|
Auto |
Always |
Never |
TestOutcome
type enum TestOutcome {
Pass;
Fail(i32, i32, boolean);
Skipped;
DidNotPanic;
Timeout(u32);
RunnerError(i32);
}
What a forked child's exit is classified into: Fail carries the exit code, the terminating signal, and whether it was a signal; DidNotPanic is a ![should_panic] test that returned normally; Timeout carries the limit it exceeded; RunnerError is the runner's own failure to fork or reap.
Variants
| Variant | Notes |
|---|---|
Pass | Test passed: child exited 0 (or signaled, when should_panic is set). |
Fail(i32, i32, boolean) | Test ran but failed: child returned Err (exit != 0) or panicked unexpectedly. Exit-code and signal carried through so the summary can show the cause. |
Skipped | Test was marked ![ignore] and the user did not pass --ignored. |
DidNotPanic | ![should_panic] was set but the test exited 0; that is itself a failure. |
Timeout(u32) | The test exceeded the per-test wall-clock limit and was killed by the alarm() watchdog (SIGALRM). Always a failure, even under ![should_panic]. Carries the configured limit in seconds. |
RunnerError(i32) | Couldn't fork() or waitpid(); runner-internal error. |
Trait implementations
implement trait Drop for struct RunOptions
For the toolchain side — discovery, forking, and reporting — see Testing in the language reference.
Free Functions
function run_all(argc: i32, argv: u8**, descriptors: TestDescriptor*, count: u64) -> i32;
function run_all(argc: i32, argv: u8**, descriptors: TestDescriptor*, count: u64) -> i32;Run every test in descriptors that matches argc/argv filtering, printing a line per test. Returns 0 if every selected test passed; 1 otherwise.
run_all is the entry point the compiler-synthesized test main calls. It parses the CLI arguments into a RunOptions, forks per test — in parallel across jobs workers, fed through an mpsc channel — and prints results in the chosen format.
The descriptors it receives are TestDescriptors, one per discovered test.
TestOutcome is what a forked child's exit is classified into: Fail carries the exit code, the terminating signal, and whether it was a signal; DidNotPanic is a ![should_panic] test that returned normally; Timeout carries the limit it exceeded.
Constants
const RULE_HEAVY: string = "================================================================================";
const RULE_THIN: string = "--------------------------------------------------------------------------------";
const ANSI_GREEN: string = "\x1B[32m";
const ANSI_RED: string = "\x1B[31m";
const ANSI_YELLOW: string = "\x1B[33m";
const ANSI_DIM: string = "\x1B[2m";
const ANSI_BOLD: string = "\x1B[1m";
const ANSI_RESET: string = "\x1B[0m";
const STALL_REPORT_SECS: u64 = 10;
const STALL_POLL_MS: u64 = 50;
const STALL_REPORT_MS: u64 = 10000;type struct Name { ... }
type enum Name { ... }
type trait Name { ... }
type union Name { ... }Begins a type declaration; the keyword that follows says which kind. On its own, type Name = Existing; declares an alias.
type struct Name {
field: Type;
method(&this) -> Ret { ... }
}A value type with named fields and optional methods. Structs live on the stack and are passed by value. Fields are public by default and may carry = default values; methods take their receiver as &this, mut &this, or this.
type struct RunOptions {
filter: String;
exact: boolean;
include_ignored: boolean;
list_only: boolean;
quiet: boolean;
format: TestFormat;
format_explicit: boolean;
color: ColorMode;
color_explicit: boolean;
color_active: boolean;
// … 7 more
}RunOptions.filter: StringSubstring filter: empty means "match everything".
type struct String<A = GlobalAlloc> {
buffer: RawBuffer<u8, A>;
length: u64;
}String: owned, heap-allocated, length-typed UTF-8.
std::collections::stringRunOptions.exact: booleanRunOptions.include_ignored: booleanRunOptions.list_only: booleanRunOptions.quiet: booleanRunOptions.format: TestFormattype enum TestFormat {
Plain;
Pretty;
Compact;
}RunOptions.format_explicit: booleanTrue if the user explicitly passed --format=.... Used to decide whether env-var or cryoconfig defaults can override.
RunOptions.color: ColorModetype enum ColorMode {
Auto;
Always;
Never;
}RunOptions.color_explicit: booleanRunOptions.color_active: booleanResolved once at the start of run_all: did color plus the TTY check land on "emit escapes". Reporters consult this flag rather than re-evaluating the policy on each test.
RunOptions.timeout_secs: u32Per-test wall-clock limit in seconds. The child arms alarm() with this value before running; 0 disables the watchdog.
RunOptions.timeout_explicit: booleanTrue if --timeout= was passed explicitly (suppresses the CRYO_TEST_TIMEOUT env default).
RunOptions.jobs: u32Number of worker threads to drive tests in parallel. 0 means "auto" -> resolved to the online CPU count at the start of run_all. 1 forces the classic sequential path. Each worker still runs every test in its own child process, so parallelism does not weaken crash / should_panic isolation.
RunOptions.jobs_explicit: booleanTrue if --jobs=/-j was passed explicitly (suppresses the CRYO_TEST_JOBS env default).
RunOptions.capture: booleanCapture each test's stdout+stderr into a per-test buffer instead of letting it stream to the terminal. On (the default) the buffer is replayed only for failing tests, so a green parallel run stays clean.
RunOptions.show_output: booleanShow captured output for *passing* tests too, not just failures. Set by --show-output. No effect when capture is off.
RunOptions.child_idx: i64Re-exec child selector: >= 0 means "run only descriptors[child_idx] and exit 0/1, no header/loop". Set by the internal --test-runner-child=<n> flag the Windows runner passes when it CreateProcess-re-execs the test binary once per test (Windows has no fork, so each test runs in a fresh process selected by index).
static name(param: Type) -> Ret { ... }A method that belongs to the type rather than an instance, called as Type::name(..). For structs, static new(..) returning a struct literal is the idiomatic constructor.
static RunOptions::default() -> RunOptionstype struct RunOptions {
filter: String;
exact: boolean;
include_ignored: boolean;
list_only: boolean;
quiet: boolean;
format: TestFormat;
format_explicit: boolean;
color: ColorMode;
color_explicit: boolean;
color_active: boolean;
// … 7 more
}type enum Name {
Unit,
Payload(T),
Named { x: i32 },
}An algebraic data type. Variants may be bare or carry a tuple or struct payload, and a match on an enum must cover every variant. Name::Variant names a variant; methods are added with implement enum Name { ... }.
type enum TestFormat {
Plain;
Pretty;
Compact;
}TestFormat::PlainTestFormat::PrettyTestFormat::Compacttype enum ColorMode {
Auto;
Always;
Never;
}ColorMode::AutoColorMode::AlwaysColorMode::Nevertype enum TestOutcome {
Pass;
Fail(i32, i32, boolean);
Skipped;
DidNotPanic;
Timeout(u32);
RunnerError(i32);
}TestOutcome::PassTest passed: child exited 0 (or signaled, when should_panic is set).
TestOutcome::Fail(i32, i32, boolean)Test ran but failed: child returned Err (exit != 0) or panicked unexpectedly. Exit-code and signal carried through so the summary can show the cause.
TestOutcome::SkippedTest was marked ![ignore] and the user did not pass --ignored.
TestOutcome::DidNotPanic![should_panic] was set but the test exited 0; that is itself a failure.
TestOutcome::Timeout(u32)The test exceeded the per-test wall-clock limit and was killed by the alarm() watchdog (SIGALRM). Always a failure, even under ![should_panic]. Carries the configured limit in seconds.
TestOutcome::RunnerError(i32)Couldn't fork() or waitpid(); runner-internal error.
const NAME: Type = value;At module level, a true compile-time constant, conventionally SCREAMING_SNAKE_CASE. (mut at module level declares mutable global state instead.)
const RULE_HEAVY: string = "================================================================================";primitive stringNUL-terminated raw string (u8*), matching the C ABI. Length-typed text is Str / String.
const RULE_THIN: string = "--------------------------------------------------------------------------------";const ANSI_GREEN: string = "\x1B[32m";const ANSI_RED: string = "\x1B[31m";const ANSI_YELLOW: string = "\x1B[33m";const ANSI_DIM: string = "\x1B[2m";const ANSI_BOLD: string = "\x1B[1m";const ANSI_RESET: string = "\x1B[0m";const STALL_REPORT_SECS: u64 = 10;const STALL_POLL_MS: u64 = 50;const STALL_REPORT_MS: u64 = 10000;import a::b;
import a::b::{ X, Y };
import a::b as c;
import a::b::*;Brings a module, or selected items from it, into scope. One path per declaration: use the brace form for several items, as to alias, and * for everything public (prefer the brace form; wildcards invite name collisions).
RunOptions.exact: booleanRunOptions.include_ignored: booleanRunOptions.list_only: booleanRunOptions.quiet: booleanRunOptions.timeout_secs: u32Per-test wall-clock limit in seconds. The child arms alarm() with this value before running; 0 disables the watchdog.
RunOptions.jobs: u32Number of worker threads to drive tests in parallel. 0 means "auto" -> resolved to the online CPU count at the start of run_all. 1 forces the classic sequential path. Each worker still runs every test in its own child process, so parallelism does not weaken crash / should_panic isolation.
RunOptions.capture: booleanCapture each test's stdout+stderr into a per-test buffer instead of letting it stream to the terminal. On (the default) the buffer is replayed only for failing tests, so a green parallel run stays clean.
std::test::runnerRunOptions.show_output: booleanShow captured output for *passing* tests too, not just failures. Set by --show-output. No effect when capture is off.
static RunOptions::default() -> RunOptionsRunOptions.format: TestFormatRunOptions.format_explicit: booleanTrue if the user explicitly passed --format=.... Used to decide whether env-var or cryoconfig defaults can override.
RunOptions.color: ColorModeRunOptions.color_explicit: booleanRunOptions.color_active: booleanResolved once at the start of run_all: did color plus the TTY check land on "emit escapes". Reporters consult this flag rather than re-evaluating the policy on each test.
function run_all(argc: i32, argv: u8**, descriptors: TestDescriptor*, count: u64) -> i32Run every test in descriptors that matches argc/argv filtering, printing a line per test. Returns 0 if every selected test passed; 1 otherwise.
extern "C" function alarm(seconds: u32) -> u32RunOptions.timeout_explicit: booleanTrue if --timeout= was passed explicitly (suppresses the CRYO_TEST_TIMEOUT env default).
RunOptions.jobs_explicit: booleanTrue if --jobs=/-j was passed explicitly (suppresses the CRYO_TEST_JOBS env default).
RunOptions.child_idx: i64Re-exec child selector: >= 0 means "run only descriptors[child_idx] and exit 0/1, no header/loop". Set by the internal --test-runner-child=<n> flag the Windows runner passes when it CreateProcess-re-execs the test binary once per test (Windows has no fork, so each test runs in a fresh process selected by index).
TestFormat::PlainTestFormat::PrettyTestFormat::CompactColorMode::AutoColorMode::AlwaysColorMode::NeverTestOutcome::Fail(i32, i32, boolean)Test ran but failed: child returned Err (exit != 0) or panicked unexpectedly. Exit-code and signal carried through so the summary can show the cause.
TestOutcome::DidNotPanic![should_panic] was set but the test exited 0; that is itself a failure.
TestOutcome::Timeout(u32)The test exceeded the per-test wall-clock limit and was killed by the alarm() watchdog (SIGALRM). Always a failure, even under ![should_panic]. Carries the configured limit in seconds.
TestOutcome::PassTest passed: child exited 0 (or signaled, when should_panic is set).
Result::Err(E)extern "C" function fork() -> i32extern "C" function waitpid(pid: i32, wstatus: i32*, options: i32) -> i32implement struct Name { ... }
implement trait Trait for Type { ... }
implement u64 { ... }Adds methods to a type outside its declaration. implement struct T (or enum, or a bare primitive) opens an inherent block; implement trait Tr for T supplies a trait's methods for one type. Resolution is at compile time - no dynamic dispatch.
implement trait Trait for Type { ... }Introduces a trait implementation: the block supplies, for one concrete type, the method bodies the trait requires.
language referenceimplement trait Trait for Type { ... }Names the type a trait implementation is for. The block that follows supplies the bodies the trait requires.
language referencefunction name<T>(param: Type) -> Ret { ... }Declares a function. Parameters are written name: Type and are never inferred; the return type follows -> and defaults to void. Declaration order does not matter: every signature is collected before any body is checked, so functions may call each other freely and recurse.
function run_all(argc: i32, argv: u8**, descriptors: TestDescriptor*, count: u64) -> i32Run every test in descriptors that matches argc/argv filtering, printing a line per test. Returns 0 if every selected test passed; 1 otherwise.
(parameter) argc: i32(parameter) argv: u8**(parameter) descriptors: TestDescriptor*type struct TestDescriptor {
name: Str;
ignored: boolean;
should_panic: boolean;
}One discovered ![test] function plus its sibling-directive flags.
(parameter) count: u64WorkerCtx.descriptors: TestDescriptor*type enum TestOutcome {
Pass;
Fail(i32, i32, boolean);
Skipped;
DidNotPanic;
Timeout(u32);
RunnerError(i32);
}