From 181b9e0d9434a5aa7d9e9ef3bd76b3ad1a05d06f Mon Sep 17 00:00:00 2001 From: Lzu Tao Date: Wed, 26 Jun 2024 01:18:15 +0700 Subject: [PATCH] test: Ensure optional_value runs --- tests/macros.rs | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/tests/macros.rs b/tests/macros.rs index 4c3e4c68ead..cb1ed801565 100644 --- a/tests/macros.rs +++ b/tests/macros.rs @@ -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()); @@ -299,17 +301,17 @@ mod arg { assert!(m.contains_id("port")); assert_eq!(m.get_one::("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 [] - -h, --help Print help information -"]], - help, + -h, --help Print help + +"#]] ); } }