Skip to content
CryoCryo home
Stdlibtest

test_child

import std::test::test_child; · source

Types

TestChild

type struct TestChild {}

Some tests need a real child process: one in its own process group that receives an interrupt, or one whose exit status or output is the thing under test. Mark a function in the test file ![test_child] instead of ![test]. It has a test's shape, () -> Result<(), TestError>, but the runner never runs it as a test and --list does not show it.

A test starts it by its fully-qualified name with TestChild::command, which returns a Command that runs this test binary as that test child; the test configures it and spawns it like any other command. The child runs that one function and exits 0 when it returns Ok, 1 when it returns Err (the error's message on stderr), and through the panic's own exit when it panics. The per-test timeout applies to the child as well. A name no test child has makes the child print an error and exit 2.

import std::fmt;
import std::process::command::{ Command, Output };
import std::test::*;

![test_child]
function prints_ready() -> Result<(), TestError> {
    fmt::print("ready");
    return Result::Ok(());
}

![test]
function a_test_child_runs_by_name_and_exits_zero() -> Result<(), TestError> {
    const command: Command = TestChild::command(Str::new("MyApp::Tests::Math::prints_ready"))?;
    const output: Output = command.output()?;
    return expect_equal(output.status().exit_code(), Option::Some(0));
}

command fails only when the running executable's path cannot be read.

Static functions

static command(name: Str) -> Result<Command, TestError>;

A command that runs this test binary as the test child name, the child function's fully-qualified name (Tests::Signals::waits_for_break). A name no test child has makes the child print an error and exit 2. Fails only when the running executable's path cannot be read.