descriptor
import std::test::descriptor; · source
Types
TestDescriptor
type struct TestDescriptor {
name: Str;
func: () -> Result<(), TestError>;
ignored: boolean;
should_panic: boolean;
}
One record per discovered test: its fully qualified name, the function pointer to call, and the ![ignore] and ![should_panic] flags. The compiler-synthesised test main builds an array of these and hands it to run_all, so the field order is part of the contract between the compiler and the runner - reordering them breaks every test binary.
func returns Result<(), TestError>: an Err is a failure, a panic is a failure unless should_panic is set, and a normal Ok return under should_panic is the DidNotPanic outcome.
Properties
| Property | Type |
|---|---|
name | Str |
ignored | boolean |
should_panic | boolean |
Methods
func: () -> Result<(), TestError>;
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 TestDescriptor {
name: Str;
ignored: boolean;
should_panic: boolean;
}One discovered ![test] function plus its sibling-directive flags.
TestDescriptor.name: Strtype struct Str {
bytes: u8*;
length: u64;
}Str: a borrowed UTF-8 string slice.
std::collections::strTestDescriptor::func: () -> Result<(), TestError>primitive ()The unit type: a value that carries no information, and the empty tuple. Distinct from void, which is the absence of a value - Result<(), E> succeeds with nothing to return. 0 bytes.
type enum TestError {
Failed(String);
Other(String);
}Why a test failed. The runner prints the variant's message verbatim to stderr from the child process before exiting non-zero, so the parent can show the failing message in the test summary.
std::test::errorTestDescriptor.ignored: booleanTestDescriptor.should_panic: booleanimport 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).
TestDescriptor::func: () -> Result<(), TestError>Result::Err(E)TestDescriptor.should_panic: booleanResult::Ok(T)TestOutcome::DidNotPanic![should_panic] was set but the test exited 0; that is itself a failure.
TestDescriptor.name: StrTestDescriptor.ignored: boolean