usage-test 6.3.0

Test helpers for CLIs built with usage
Documentation

Test helpers for a CLI built with usage.

The parser's observable surface is what a command line parses to, what a user is shown when it does not, and what a shell offers while one is being typed. All three are testable from the static tables the derive already emits. [command!] covers the other half of a CLI test: run the compiled binary and capture what its command handler writes.

What it is not is a second implementation of any of them. Every page here comes from [usage_argv::help::page], the same function parse() renders a help request with, and every failure from [usage_argv::render_failure_plain], the same renderer it prints with — asked for plain text, so an assertion does not turn on whether stderr was a terminal. A harness that renders its own approximation of a help page is a harness whose passing tests mean nothing, so the rule is that nothing in this crate formats a page.

# use usage_argv::spec::Spec;
# fn ex(spec: &'static Spec<'static>) {
use usage_test as test;

// What the tree's help looks like, all of it, in one snapshot.
let pages = test::help_tree(spec, test::Page::Long);

// What a user sees when a command line does not parse.
let words = test::argv(["--nope"]);
let outcome = test::outcome(spec, &words.words(), some_cli_parse_from);
# fn some_cli_parse_from<'v>(
#     argv: &[&'v std::ffi::OsStr],
# ) -> Result<(), usage_argv::Error<'static, 'v>> {
#     Ok(())
# }
# let _ = (pages, outcome);
# }

Enable it as a dev-dependency feature of the facade:

[dev-dependencies]
usage = { package = "usage-rs", version = "6", features = ["test"] }