diff --git a/src/bin/stdio-fixture.rs b/src/bin/stdio-fixture.rs new file mode 100644 index 00000000..bb04cada --- /dev/null +++ b/src/bin/stdio-fixture.rs @@ -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(); +} diff --git a/tests/ui.rs b/tests/ui.rs new file mode 100644 index 00000000..c7cab689 --- /dev/null +++ b/tests/ui.rs @@ -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"); +} diff --git a/tests/ui/V_flag_stdout.toml b/tests/ui/V_flag_stdout.toml new file mode 100644 index 00000000..c1804e60 --- /dev/null +++ b/tests/ui/V_flag_stdout.toml @@ -0,0 +1,7 @@ +bin.name = "stdio-fixture" +args = ["-V"] +status.code = 0 +stdout = """ +stdio-fixture 1.0 +""" +stderr = "" diff --git a/tests/ui/arg_required_else_help_stderr.toml b/tests/ui/arg_required_else_help_stderr.toml new file mode 100644 index 00000000..5ac94784 --- /dev/null +++ b/tests/ui/arg_required_else_help_stderr.toml @@ -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 +""" diff --git a/tests/ui/error_stderr.toml b/tests/ui/error_stderr.toml new file mode 100644 index 00000000..6aea30b8 --- /dev/null +++ b/tests/ui/error_stderr.toml @@ -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 +""" diff --git a/tests/ui/h_flag_stdout.toml b/tests/ui/h_flag_stdout.toml new file mode 100644 index 00000000..66af2e46 --- /dev/null +++ b/tests/ui/h_flag_stdout.toml @@ -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 = "" diff --git a/tests/ui/help_cmd_stdout.toml b/tests/ui/help_cmd_stdout.toml new file mode 100644 index 00000000..881d53ee --- /dev/null +++ b/tests/ui/help_cmd_stdout.toml @@ -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 = "" diff --git a/tests/ui/help_flag_stdout.toml b/tests/ui/help_flag_stdout.toml new file mode 100644 index 00000000..2615875b --- /dev/null +++ b/tests/ui/help_flag_stdout.toml @@ -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 = "" diff --git a/tests/ui/version_flag_stdout.toml b/tests/ui/version_flag_stdout.toml new file mode 100644 index 00000000..060285be --- /dev/null +++ b/tests/ui/version_flag_stdout.toml @@ -0,0 +1,7 @@ +bin.name = "stdio-fixture" +args = ["--version"] +status.code = 0 +stdout = """ +stdio-fixture 1.0 - a2132c +""" +stderr = ""