xacli-testing

Crates.ioxacli-testing
lib.rsxacli-testing
version0.2.0
created_at2025-11-28 18:09:07.24556+00
updated_at2026-01-15 18:31:02.765458+00
descriptionTesting utilities for XaCLI - keyboard simulation, VHS tape parsing, and output capture
homepage
repositoryhttps://github.com/yufeiminds/xacli
max_upload_size
id1955824
size135,880
Yufei Li (yufeiminds)

documentation

README

Testing Mock

这个模块是实现对 App 运行时的包装,实现以下能力:

假设初始化了一个 App 实例 app

use xacli_core::App;

let app = App::new("myapp");
// ... 初始化该 App
  1. TestingApp: 一个可以被测试的 App 包装器,支持注入命令行参数和捕获输出。
use xacli_testing::TestingApp;

// 创建一个 TestingApp 包装器
let app = TestingApp::new(app);
let t = app
    // 返回 TestSuite 可修改的引用
    .suite("my_test_suite") // 可选,默认值 default
    // 返回 TestCase 可修改的引用
    .test("test case 1")
    .commands(&["command"])
    .args(&["--option", "value"])
    .input_events(vec![]) // 如果需要模拟输入事件
  1. 断言支持: 提供对输出结果的断言功能,可以检查标准输出、标准错误等。
let result = t.assert() // 返回 Assert 断言构建器
    .stdout(predicate::str::contains("XXX"))
    .success(); // 执行测试

let result = t.assert()
    .stderr(predicate::str::contains("Error message"))
    .failure();
  1. 快照测试支持:提供对输出的快照测试功能,可以将当前输出与之前保存的快照进行比较,快照保存在当前 Git 代码库中,支持快照更新。
let result = t.assert()
    .snapshot("snapshot_name.xaclisnap")
    .success();
  1. 测试报告生成
// 单个测试用例的报告
println!("{}", result);

// 整个测试套件的报告
println!("{}", app.report());
Commit count: 0

cargo fmt