Skip to main content

Crate usage_test

Crate usage_test 

Source
Expand description

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_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);

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

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

Macros§

command
Run a binary target from an integration test and capture stdout, stderr, and its exit status.

Structs§

Argv
Words a parse entry point can borrow.
CommandOutput
Output captured from a CLI integration test.
Printed
What a program would have written, where, and what it would have exited with.

Enums§

Outcome
What one command line does to a CLI.
Page
Which page a help request asks for.

Functions§

argv
Argv::new, for a call site that reads better without the type.
help
One command’s help page, found by the words a user would type.
help_tree
Every command’s help page, depth-first, in one string.
outcome
What a CLI would do with one command line.
parse
The parsed struct, or the text a user would have read instead.