about summary refs log tree commit diff
path: root/rustc_tools_util
diff options
context:
space:
mode:
authorMatthias Krüger <matthias.krueger@famsik.de>2018-09-09 23:40:26 +0200
committerMatthias Krüger <matthias.krueger@famsik.de>2018-09-09 23:45:29 +0200
commit61249b360e9aef29413516e07a57d3056648e9b3 (patch)
treefb273bd70cb2e35bed8137961012455d85e3a526 /rustc_tools_util
parent2d3298b8c4df8da4b597b33104e235b0fafbe1e9 (diff)
downloadrust-61249b360e9aef29413516e07a57d3056648e9b3.tar.gz
rust-61249b360e9aef29413516e07a57d3056648e9b3.zip
impl std::fmt::Debug for VersionInfo
For clippy, this would print:
VersionInfo { crate_name: "clippy", major: 0, minor: 0, patch: 212, commit_hash: "084be7ba", commit_date: "2018-09-09" }
Diffstat (limited to 'rustc_tools_util')
-rw-r--r--rustc_tools_util/src/lib.rs37
1 files changed, 35 insertions, 2 deletions
diff --git a/rustc_tools_util/src/lib.rs b/rustc_tools_util/src/lib.rs
index aad9ee88fc7..33e1d979dce 100644
--- a/rustc_tools_util/src/lib.rs
+++ b/rustc_tools_util/src/lib.rs
@@ -61,6 +61,30 @@ impl std::fmt::Display for VersionInfo {
     }
 }
 
+impl std::fmt::Debug for VersionInfo {
+    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
+        write!(
+            f,
+            "VersionInfo {{ crate_name: \"{}\", major: {}, minor: {}, patch: {}",
+            self.crate_name, self.major, self.minor, self.patch,
+        )?;
+        match self.commit_hash {
+            Some(_) => {
+                write!(
+                    f,
+                    ", commit_hash: \"{}\", commit_date: \"{}\" }}",
+                    self.commit_hash.clone().unwrap_or_default().trim(),
+                    self.commit_date.clone().unwrap_or_default().trim()
+                )?;
+            },
+            None => {
+                write!(f, " }}")?;
+            },
+        }
+        Ok(())
+    }
+}
+
 pub fn get_channel() -> Option<String> {
     if let Ok(channel) = env::var("CFG_RELEASE_CHANNEL") {
         Some(channel)
@@ -105,8 +129,17 @@ mod test {
     #[test]
     fn test_display_local() {
         let vi = get_version_info!();
-        let fmt = format!("{}", vi);
-        assert_eq!(fmt, "rustc_tools_util 0.1.0");
+        assert_eq!(vi.to_string(), "rustc_tools_util 0.1.0");
+    }
+
+    #[test]
+    fn test_debug_local() {
+        let vi = get_version_info!();
+        let s = format!("{:?}", vi);
+        assert_eq!(
+            s,
+            "VersionInfo { crate_name: \"rustc_tools_util\", major: 0, minor: 1, patch: 0 }"
+        );
     }
 
 }