mirror of
https://github.com/clap-rs/clap
synced 2024-11-10 06:44:16 +00:00
test: Verify examples based on feature flags
This commit is contained in:
parent
020d55e832
commit
9c4194a5a1
7 changed files with 42 additions and 29 deletions
|
@ -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
|
||||
|
|
2
Makefile
2
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"
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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
|
||||
```
|
||||
|
|
|
@ -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() {
|
||||
|
|
|
@ -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"))]
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue