mirror of
https://github.com/clap-rs/clap
synced 2024-12-14 06:42:33 +00:00
Merge pull request #3652 from epage/stdio
test(output): Ensure correct streams
This commit is contained in:
commit
3fa690e888
9 changed files with 165 additions and 0 deletions
14
src/bin/stdio-fixture.rs
Normal file
14
src/bin/stdio-fixture.rs
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
fn main() {
|
||||||
|
let cmd = clap::Command::new("stdio-fixture")
|
||||||
|
.version("1.0")
|
||||||
|
.long_version("1.0 - a2132c")
|
||||||
|
.arg_required_else_help(true)
|
||||||
|
.subcommand(clap::Command::new("more"))
|
||||||
|
.arg(
|
||||||
|
clap::Arg::new("verbose")
|
||||||
|
.long("--verbose")
|
||||||
|
.help("log")
|
||||||
|
.long_help("more log"),
|
||||||
|
);
|
||||||
|
cmd.get_matches();
|
||||||
|
}
|
33
tests/ui.rs
Normal file
33
tests/ui.rs
Normal file
|
@ -0,0 +1,33 @@
|
||||||
|
#![cfg(not(tarpaulin))]
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn ui_tests() {
|
||||||
|
let t = trycmd::TestCases::new();
|
||||||
|
let features = [
|
||||||
|
#[cfg(feature = "std")]
|
||||||
|
"std",
|
||||||
|
#[cfg(feature = "derive")]
|
||||||
|
"derive",
|
||||||
|
#[cfg(feature = "cargo")]
|
||||||
|
"cargo",
|
||||||
|
#[cfg(feature = "color")]
|
||||||
|
"color",
|
||||||
|
#[cfg(feature = "env")]
|
||||||
|
"env",
|
||||||
|
#[cfg(feature = "suggestions")]
|
||||||
|
"suggestions",
|
||||||
|
#[cfg(feature = "unicode")]
|
||||||
|
"unicode",
|
||||||
|
#[cfg(feature = "wrap_help")]
|
||||||
|
"wrap_help",
|
||||||
|
#[cfg(feature = "unstable-replace")]
|
||||||
|
"unstable-replace",
|
||||||
|
#[cfg(feature = "unstable-multicall")]
|
||||||
|
"unstable-multicall",
|
||||||
|
#[cfg(feature = "unstable-grouped")]
|
||||||
|
"unstable-grouped",
|
||||||
|
]
|
||||||
|
.join(" ");
|
||||||
|
t.register_bins(trycmd::cargo::compile_examples(["--features", &features]).unwrap());
|
||||||
|
t.case("tests/ui/*.toml");
|
||||||
|
}
|
7
tests/ui/V_flag_stdout.toml
Normal file
7
tests/ui/V_flag_stdout.toml
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
bin.name = "stdio-fixture"
|
||||||
|
args = ["-V"]
|
||||||
|
status.code = 0
|
||||||
|
stdout = """
|
||||||
|
stdio-fixture 1.0
|
||||||
|
"""
|
||||||
|
stderr = ""
|
19
tests/ui/arg_required_else_help_stderr.toml
Normal file
19
tests/ui/arg_required_else_help_stderr.toml
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
bin.name = "stdio-fixture"
|
||||||
|
args = []
|
||||||
|
status.code = 2
|
||||||
|
stdout = ""
|
||||||
|
stderr = """
|
||||||
|
stdio-fixture 1.0
|
||||||
|
|
||||||
|
USAGE:
|
||||||
|
stdio-fixture[EXE] [OPTIONS] [SUBCOMMAND]
|
||||||
|
|
||||||
|
OPTIONS:
|
||||||
|
-h, --help Print help information
|
||||||
|
-V, --version Print version information
|
||||||
|
--verbose log
|
||||||
|
|
||||||
|
SUBCOMMANDS:
|
||||||
|
help Print this message or the help of the given subcommand(s)
|
||||||
|
more
|
||||||
|
"""
|
14
tests/ui/error_stderr.toml
Normal file
14
tests/ui/error_stderr.toml
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
bin.name = "stdio-fixture"
|
||||||
|
args = ["--unknown-argument"]
|
||||||
|
status.code = 2
|
||||||
|
stdout = ""
|
||||||
|
stderr = """
|
||||||
|
error: Found argument '--unknown-argument' which wasn't expected, or isn't valid in this context
|
||||||
|
|
||||||
|
\tIf you tried to supply `--unknown-argument` as a value rather than a flag, use `-- --unknown-argument`
|
||||||
|
|
||||||
|
USAGE:
|
||||||
|
stdio-fixture[EXE] [OPTIONS] [SUBCOMMAND]
|
||||||
|
|
||||||
|
For more information try --help
|
||||||
|
"""
|
19
tests/ui/h_flag_stdout.toml
Normal file
19
tests/ui/h_flag_stdout.toml
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
bin.name = "stdio-fixture"
|
||||||
|
args = ["-h"]
|
||||||
|
status.code = 0
|
||||||
|
stdout = """
|
||||||
|
stdio-fixture 1.0
|
||||||
|
|
||||||
|
USAGE:
|
||||||
|
stdio-fixture[EXE] [OPTIONS] [SUBCOMMAND]
|
||||||
|
|
||||||
|
OPTIONS:
|
||||||
|
-h, --help Print help information
|
||||||
|
-V, --version Print version information
|
||||||
|
--verbose log
|
||||||
|
|
||||||
|
SUBCOMMANDS:
|
||||||
|
help Print this message or the help of the given subcommand(s)
|
||||||
|
more
|
||||||
|
"""
|
||||||
|
stderr = ""
|
26
tests/ui/help_cmd_stdout.toml
Normal file
26
tests/ui/help_cmd_stdout.toml
Normal file
|
@ -0,0 +1,26 @@
|
||||||
|
bin.name = "stdio-fixture"
|
||||||
|
args = ["help"]
|
||||||
|
status.code = 0
|
||||||
|
stdout = """
|
||||||
|
stdio-fixture 1.0
|
||||||
|
|
||||||
|
USAGE:
|
||||||
|
stdio-fixture[EXE] [OPTIONS] [SUBCOMMAND]
|
||||||
|
|
||||||
|
OPTIONS:
|
||||||
|
-h, --help
|
||||||
|
Print help information
|
||||||
|
|
||||||
|
-V, --version
|
||||||
|
Print version information
|
||||||
|
|
||||||
|
--verbose
|
||||||
|
more log
|
||||||
|
|
||||||
|
SUBCOMMANDS:
|
||||||
|
help
|
||||||
|
Print this message or the help of the given subcommand(s)
|
||||||
|
more
|
||||||
|
|
||||||
|
"""
|
||||||
|
stderr = ""
|
26
tests/ui/help_flag_stdout.toml
Normal file
26
tests/ui/help_flag_stdout.toml
Normal file
|
@ -0,0 +1,26 @@
|
||||||
|
bin.name = "stdio-fixture"
|
||||||
|
args = ["--help"]
|
||||||
|
status.code = 0
|
||||||
|
stdout = """
|
||||||
|
stdio-fixture 1.0
|
||||||
|
|
||||||
|
USAGE:
|
||||||
|
stdio-fixture[EXE] [OPTIONS] [SUBCOMMAND]
|
||||||
|
|
||||||
|
OPTIONS:
|
||||||
|
-h, --help
|
||||||
|
Print help information
|
||||||
|
|
||||||
|
-V, --version
|
||||||
|
Print version information
|
||||||
|
|
||||||
|
--verbose
|
||||||
|
more log
|
||||||
|
|
||||||
|
SUBCOMMANDS:
|
||||||
|
help
|
||||||
|
Print this message or the help of the given subcommand(s)
|
||||||
|
more
|
||||||
|
|
||||||
|
"""
|
||||||
|
stderr = ""
|
7
tests/ui/version_flag_stdout.toml
Normal file
7
tests/ui/version_flag_stdout.toml
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
bin.name = "stdio-fixture"
|
||||||
|
args = ["--version"]
|
||||||
|
status.code = 0
|
||||||
|
stdout = """
|
||||||
|
stdio-fixture 1.0 - a2132c
|
||||||
|
"""
|
||||||
|
stderr = ""
|
Loading…
Reference in a new issue