test: Verify examples based on feature flags

This commit is contained in:
Ed Page 2021-11-23 15:59:56 -06:00
parent 020d55e832
commit 9c4194a5a1
7 changed files with 42 additions and 29 deletions

View file

@ -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

View file

@ -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"

View file

@ -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

View file

@ -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 {

View file

@ -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
```

View file

@ -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() {

View file

@ -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"))]
{