Crates.io | md-cli-test |
lib.rs | md-cli-test |
version | 0.1.0 |
created_at | 2025-07-05 09:16:26.000213+00 |
updated_at | 2025-07-05 09:16:26.000213+00 |
description | A helper library for integration testing of CLI apps using markdown files as a source of test cases |
homepage | |
repository | https://github.com/noogen-projects/md-cli-test |
max_upload_size | |
id | 1738847 |
size | 35,585 |
This is a helper library for integration testing of CLI applications in Rust using markdown files as a source of test cases.
Tester
automatically extracts and runs command-line examples from code blocks in .md
specification files, verifying the correctness of CLI application's output. It is especially useful when following a doctest-like approach for CLI examples, helping keep your documentation and tests in sync.
#
) as test section titles ```sh
, ```shell
) as test casescd
, ls
, mkdir
, rm
, echo
, cat
)Markdown file greeting.md
:
# Greeting
```sh
$ my-cli greet Alice
Hello, Alice!
```
Test using this library:
use md_cli_test::Tester;
#[test]
fn greeting_test_cases() {
Tester::new("tests/greeting.md").run().unwrap();
}
In more complex scenarios, you can also use aliase for binary, pass environment variables, and even use cd
, ls
, mkdir
, rm
, echo
, cat
commands.
For example, markdown file new_project.md
for todo-cli
application:
# New project
## New project default
```sh
$ todo new "project A"
Creating `project A` project
```
```sh
$ ls "./project A"
Project.toml
```
```sh
$ cat "./project A/Project.toml"
id = "project A"
name = "project A"
```
```sh
$ todo new "project A"
Creating `project A` project
Error: destination `${current_dir_path}/project A` already exists
```
Integration test file new_project.rs
:
use md_cli_test::Tester;
#[test]
fn new_project_test_cases() {
Tester::new("tests/new_project.md")
// Use `todo` alias instead of real package or binary name
.with_cargo_bin_alias("todo")
// Alias must be matched to a real binary name `todo-cli`
// if it does not match the package name
.with_cargo_bin_name("todo-cli")
// Pass environment variable
.with_env("TODO_CONFIG", "./todo.toml")
.run()
.unwrap();
}
Add to your Cargo.toml
:
[dev-dependencies]
md-cli-test = "0.1"