Repository: clap-rs/clap
Pull request #1953 (2020-05-30 22:36:53)

Proper debug in ArgGroup
<!--
If your PR closes some issues, please write `Closes #XXXX`
where `XXXX` is the number of the issue you want to fix.
Each issue goes on it's own line.
-->



Patch:
diff --git a/src/build/arg_group.rs b/src/build/arg_group.rs
index a22dfa28..66d98d01 100644
--- a/src/build/arg_group.rs
+++ b/src/build/arg_group.rs
@@ -1,6 +1,3 @@
-// Std
-use std::fmt::{Debug, Formatter, Result};
-
 // Internal
 use crate::util::{Id, Key};
 
@@ -77,7 +74,7 @@ use yaml_rust::Yaml;
 /// [arguments]: ./struct.Arg.html
 /// [conflict]: ./struct.Arg.html#method.conflicts_with
 /// [requirement]: ./struct.Arg.html#method.requires
-#[derive(Default)]
+#[derive(Default, Debug)]
 pub struct ArgGroup<'a> {
     pub(crate) id: Id,
     pub(crate) name: &'a str,
@@ -398,22 +395,6 @@ impl<'a> ArgGroup<'a> {
     }
 }
 
-impl<'a> Debug for ArgGroup<'a> {
-    fn fmt(&self, f: &mut Formatter) -> Result {
-        write!(
-            f,
-            "{{\n\
-             \tname: {:?},\n\
-             \targs: {:?},\n\
-             \trequired: {:?},\n\
-             \trequires: {:?},\n\
-             \tconflicts: {:?},\n\
-             }}",
-            self.name, self.args, self.required, self.requires, self.conflicts
-        )
-    }
-}
-
 impl<'a, 'z> From<&'z ArgGroup<'a>> for ArgGroup<'a> {
     fn from(g: &'z ArgGroup<'a>) -> Self {
         ArgGroup {
@@ -490,7 +471,7 @@ impl<'a> From<&'a Yaml> for ArgGroup<'a> {
 
 #[cfg(test)]
 mod test {
-    use super::{ArgGroup, Id};
+    use super::ArgGroup;
     #[cfg(feature = "yaml")]
     use yaml_rust::YamlLoader;
 
@@ -517,52 +498,6 @@ mod test {
         assert_eq!(g.conflicts, confs);
     }
 
-    #[test]
-    fn test_debug() {
-        let g = ArgGroup::new("test")
-            .arg("a1")
-            .arg("a4")
-            .args(&["a2", "a3"])
-            .required(true)
-            .conflicts_with("c1")
-            .conflicts_with_all(&["c2", "c3"])
-            .conflicts_with("c4")
-            .requires("r1")
-            .requires_all(&["r2", "r3"])
-            .requires("r4");
-
-        let args = vec![
-            Id::from("a1"),
-            Id::from("a4"),
-            Id::from("a2"),
-            Id::from("a3"),
-        ];
-        let reqs = vec![
-            Id::from("r1"),
-            Id::from("r2"),
-            Id::from("r3"),
-            Id::from("r4"),
-        ];
-        let confs = vec![
-            Id::from("c1"),
-            Id::from("c2"),
-            Id::from("c3"),
-            Id::from("c4"),
-        ];
-
-        let debug_str = format!(
-            "{{\n\
-             \tname: \"test\",\n\
-             \targs: {:?},\n\
-             \trequired: {:?},\n\
-             \trequires: {:?},\n\
-             \tconflicts: {:?},\n\
-             }}",
-            args, true, reqs, confs
-        );
-        assert_eq!(&*format!("{:?}", g), &*debug_str);
-    }
-
     #[test]
     fn test_from() {
         let g = ArgGroup::new("test")


Test patch:
diff --git a/tests/unique_args.rs b/tests/unique_args.rs
index 8a416cd2..0b6e0eab 100644
--- a/tests/unique_args.rs
+++ b/tests/unique_args.rs
@@ -1,9 +1,9 @@
-use clap::{App, Arg};
-
 #[cfg(debug_assertions)]
 #[test]
 #[should_panic = "Argument names must be unique, but 'arg1' is in use by more than one argument or group"]
 fn unique_arg_names() {
+    use clap::{App, Arg};
+
     let _ = App::new("some")
         .args(&[Arg::new("arg1").short('a'), Arg::new("arg1").short('b')])
         .try_get_matches();
@@ -13,6 +13,8 @@ fn unique_arg_names() {
 #[test]
 #[should_panic = "Short option names must be unique for each argument, but '-a' is in use by both 'arg1' and 'arg2'"]
 fn unique_arg_shorts() {
+    use clap::{App, Arg};
+
     let _ = App::new("some")
         .args(&[Arg::new("arg1").short('a'), Arg::new("arg2").short('a')])
         .try_get_matches();
@@ -22,6 +24,8 @@ fn unique_arg_shorts() {
 #[test]
 #[should_panic = "Long option names must be unique for each argument, but '--long' is in use by both 'arg1' and 'arg2'"]
 fn unique_arg_longs() {
+    use clap::{App, Arg};
+
     let _ = App::new("some")
         .args(&[Arg::new("arg1").long("long"), Arg::new("arg2").long("long")])
         .try_get_matches();