Skip to content
CryoCryo home
Stdlibtest

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

PropertyTypeNotes
filterStringSubstring filter: empty means "match everything".
exactboolean
include_ignoredboolean
list_onlyboolean
quietboolean
formatTestFormat
format_explicitbooleanTrue if the user explicitly passed --format=.... Used to decide whether env-var or cryoconfig defaults can override.
colorColorMode
color_explicitboolean
color_activebooleanResolved 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_secsu32Per-test wall-clock limit in seconds. The child arms alarm() with this value before running; 0 disables the watchdog.
timeout_explicitbooleanTrue if --timeout= was passed explicitly (suppresses the CRYO_TEST_TIMEOUT env default).
jobsu32Number 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_explicitbooleanTrue if --jobs=/-j was passed explicitly (suppresses the CRYO_TEST_JOBS env default).
capturebooleanCapture 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_outputbooleanShow captured output for passing tests too, not just failures. Set by --show-output. No effect when capture is off.
child_idxi64Re-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

VariantNotes
PassTest 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.
SkippedTest 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;

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;