From 9c4194a5a1d88a9c91149f34393b19f4a530d36c Mon Sep 17 00:00:00 2001 From: Ed Page Date: Tue, 23 Nov 2021 15:59:56 -0600 Subject: [PATCH] test: Verify examples based on feature flags --- Cargo.toml | 6 ++++++ Makefile | 2 +- examples/24a_multicall_busybox.md | 6 +++--- examples/24a_multicall_busybox.rs | 1 - examples/24b_multicall_hostname.md | 24 ++--------------------- examples/24b_multicall_hostname.rs | 1 - tests/examples.rs | 31 +++++++++++++++++++++++++++++- 7 files changed, 42 insertions(+), 29 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 1ac40b97..5ec3a91f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -131,10 +131,16 @@ trycmd = { version = "0.8.0", default-features = false, features = ["color-auto" [[example]] name = "busybox" path = "examples/24a_multicall_busybox.rs" +required-features = ["unstable-multicall"] [[example]] name = "hostname" path = "examples/24b_multicall_hostname.rs" +required-features = ["unstable-multicall"] + +[[example]] +name = "09_cargo_metadata" +required-features = ["cargo"] [profile.test] opt-level = 1 diff --git a/Makefile b/Makefile index a6dac55f..e1b4c344 100644 --- a/Makefile +++ b/Makefile @@ -11,7 +11,7 @@ ifneq (${TOOLCHAIN_TARGET},) endif _FEATURES = minimal default wasm full release -_FEATURES_minimal = --no-default-features --features "std cargo" +_FEATURES_minimal = --no-default-features --features "std" _FEATURES_default = _FEATURES_wasm = --features "yaml regex unstable-replace unstable-multicall unstable-grouped" _FEATURES_full = --features "wrap_help yaml regex unstable-replace unstable-multicall unstable-grouped doc" diff --git a/examples/24a_multicall_busybox.md b/examples/24a_multicall_busybox.md index 7291ff26..029cf7d6 100644 --- a/examples/24a_multicall_busybox.md +++ b/examples/24a_multicall_busybox.md @@ -4,7 +4,7 @@ See the documentation for clap::AppSettings::Multicall for rationale. This example omits every command except true and false, which are the most trivial to implement, -```bash +```bash,ignore $ busybox true ? 0 $ busybox false @@ -14,14 +14,14 @@ $ busybox false But includes the `--install` option as an example of why it can be useful for the main program to take arguments that aren't applet subcommands. -```bash +```bash,ignore $ busybox --install ? failed ... ``` Though users must pass something: -```bash +```bash,ignore $ busybox ? failed busybox diff --git a/examples/24a_multicall_busybox.rs b/examples/24a_multicall_busybox.rs index e5302098..f876bdb4 100644 --- a/examples/24a_multicall_busybox.rs +++ b/examples/24a_multicall_busybox.rs @@ -17,7 +17,6 @@ fn main() { .subcommand(App::new("true").about("does nothing successfully")) .subcommand(App::new("false").about("does nothing unsuccessfully")); - #[cfg(feature = "unstable-multicall")] let app = app.setting(AppSettings::Multicall); let matches = app.get_matches(); if matches.occurrences_of("install") > 0 { diff --git a/examples/24b_multicall_hostname.md b/examples/24b_multicall_hostname.md index 7c5d4df3..47fbe90e 100644 --- a/examples/24b_multicall_hostname.md +++ b/examples/24b_multicall_hostname.md @@ -4,28 +4,8 @@ See the documentation for clap::AppSettings::Multicall for rationale. This example omits the implementation of displaying address config -```bash -$ hostname hostname +```bash,ignore +$ hostname www -$ hostname dnsdomainname -example.com ``` *Note: without the links setup, we can't demonostrate the multicall behavior* - -Though users must pass something: -```bash -$ hostname -? failed -hostname - -USAGE: - hostname[EXE] [SUBCOMMAND] - -OPTIONS: - -h, --help Print help information - -SUBCOMMANDS: - dnsdomainname show domain name part of FQDN - help Print this message or the help of the given subcommand(s) - hostname show hostname part of FQDN -``` diff --git a/examples/24b_multicall_hostname.rs b/examples/24b_multicall_hostname.rs index 3b5219b3..bb46d7ff 100644 --- a/examples/24b_multicall_hostname.rs +++ b/examples/24b_multicall_hostname.rs @@ -6,7 +6,6 @@ fn main() { .subcommand(App::new("hostname").about("show hostname part of FQDN")) .subcommand(App::new("dnsdomainname").about("show domain name part of FQDN")); - #[cfg(feature = "unstable-multicall")] let app = app.setting(AppSettings::Multicall); match app.get_matches().subcommand_name() { diff --git a/tests/examples.rs b/tests/examples.rs index d4373faa..43307e0d 100644 --- a/tests/examples.rs +++ b/tests/examples.rs @@ -3,7 +3,36 @@ #[test] fn example_tests() { let t = trycmd::TestCases::new(); - t.register_bins(trycmd::cargo::compile_examples([]).unwrap()); + let features = [ + #[cfg(feature = "debug")] + "debug", + #[cfg(feature = "doc")] + "doc", + #[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 = "unsable-replace")] + "unsable-replace", + #[cfg(feature = "unsable-multicall")] + "unsable-multicall", + #[cfg(feature = "unsable-grouped")] + "unsable-grouped", + ] + .join(" "); + t.register_bins(trycmd::cargo::compile_examples(["--features", &features]).unwrap()); t.case("examples/*.md"); #[cfg(not(feature = "unstable-multicall"))] {