Skip to main content

Module testing

Module testing 

Source
Expand description

Testing utilities for click-rs applications.

This module provides utilities for testing CLI applications built with click-rs. The main component is CliRunner, which allows invoking commands with captured output for assertions.

§Reference

Based on Python Click’s testing.py.

§Example

use click::testing::CliRunner;
use click::command::Command;

let cmd = Command::new("hello")
    .callback(|_ctx| {
        // Your command logic here
        Ok(())
    })
    .build();

let runner = CliRunner::new();
let result = runner.invoke(&cmd, &[]);

assert_eq!(result.exit_code, 0);
assert!(result.is_success());

Structs§

CliRunner
A test runner for CLI applications.
EchoingStdin
A wrapper that echoes input to output as it’s read.
InvokeResult
The result of invoking a command through CliRunner.
IsolatedFilesystem
A temporary filesystem context for isolated testing.

Functions§

make_test_context
Create a mock context for testing.