Skip to content

Commit 181b9e0

Browse files
tesujiepage
authored andcommitted
test: Ensure optional_value runs
1 parent 0724b7b commit 181b9e0

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

tests/macros.rs

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -277,9 +277,11 @@ mod arg {
277277
}
278278

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

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

302-
let mut help = Vec::new();
303-
cmd.write_help(&mut help).unwrap();
304-
snapbox::assert_eq(
305-
snapbox::str![["\
304+
let help = cmd.render_help().to_string();
305+
snapbox::assert_data_eq!(
306+
help,
307+
snapbox::str![[r#"
306308
Usage: test [OPTIONS]
307309
308310
Options:
309311
-p [<NUM>]
310-
-h, --help Print help information
311-
"]],
312-
help,
312+
-h, --help Print help
313+
314+
"#]]
313315
);
314316
}
315317
}

0 commit comments

Comments
 (0)