Skip to content

Commit

Permalink
test: Ensure optional_value runs
Browse files Browse the repository at this point in the history
  • Loading branch information
tesuji authored and epage committed Jun 26, 2024
1 parent 0724b7b commit 181b9e0
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions tests/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -277,9 +277,11 @@ mod arg {
}

#[test]
#[cfg(all(feature = "help", featiure = "usage"))]
#[cfg(all(feature = "help", feature = "usage"))]
fn optional_value() {
let mut cmd = clap::Command::new("test").arg(clap::arg!(port: -p [NUM]));
let mut cmd = clap::Command::new("test")
.args_override_self(true)
.arg(clap::arg!(port: -p [NUM]));

let r = cmd.try_get_matches_from_mut(["test", "-p42"]);
assert!(r.is_ok(), "{}", r.unwrap_err());
Expand All @@ -299,17 +301,17 @@ mod arg {
assert!(m.contains_id("port"));
assert_eq!(m.get_one::<String>("port").unwrap(), "42");

let mut help = Vec::new();
cmd.write_help(&mut help).unwrap();
snapbox::assert_eq(
snapbox::str![["\
let help = cmd.render_help().to_string();
snapbox::assert_data_eq!(
help,
snapbox::str![[r#"
Usage: test [OPTIONS]
Options:
-p [<NUM>]
-h, --help Print help information
"]],
help,
-h, --help Print help
"#]]
);
}
}
Expand Down

0 comments on commit 181b9e0

Please sign in to comment.