From 202db3e09c27eb950abc498a2854b7e8ee7536b6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20Kr=C3=BCger?= Date: Fri, 7 Sep 2018 18:03:03 +0200 Subject: [PATCH 1/2] rustc_tools_util: don't hardcode crate name --- rustc_tools_util/src/lib.rs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/rustc_tools_util/src/lib.rs b/rustc_tools_util/src/lib.rs index 20b598346..b2ec96122 100644 --- a/rustc_tools_util/src/lib.rs +++ b/rustc_tools_util/src/lib.rs @@ -8,6 +8,7 @@ macro_rules! get_version_info { let major = env!("CARGO_PKG_VERSION_MAJOR").parse::().unwrap(); let minor = env!("CARGO_PKG_VERSION_MINOR").parse::().unwrap(); let patch = env!("CARGO_PKG_VERSION_PATCH").parse::().unwrap(); + let crate_name = String::from(env!("CARGO_PKG_NAME")); let host_compiler = $crate::get_channel(); let commit_hash = option_env!("GIT_HASH").map(|s| s.to_string()); @@ -20,6 +21,7 @@ macro_rules! get_version_info { host_compiler, commit_hash, commit_date, + crate_name, } }}; } @@ -32,6 +34,7 @@ pub struct VersionInfo { pub host_compiler: Option, pub commit_hash: Option, pub commit_date: Option, + pub crate_name: String, } impl std::fmt::Display for VersionInfo { @@ -40,7 +43,8 @@ impl std::fmt::Display for VersionInfo { Some(_) => { write!( f, - "clippy {}.{}.{} ({} {})", + "{} {}.{}.{} ({} {})", + self.crate_name, self.major, self.minor, self.patch, @@ -49,7 +53,7 @@ impl std::fmt::Display for VersionInfo { )?; }, None => { - write!(f, "clippy {}.{}.{}", self.major, self.minor, self.patch)?; + write!(f, "{} {}.{}.{}", self.crate_name, self.major, self.minor, self.patch)?; }, }; Ok(()) From a14155088bc3cb7fa8dee3484e37a3212265ed8c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20Kr=C3=BCger?= Date: Fri, 7 Sep 2018 19:06:02 +0200 Subject: [PATCH 2/2] rustc_tools_util: add test --- ci/base-tests.sh | 1 + rustc_tools_util/src/lib.rs | 26 ++++++++++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/ci/base-tests.sh b/ci/base-tests.sh index 94a810e4e..0d0a370fe 100755 --- a/ci/base-tests.sh +++ b/ci/base-tests.sh @@ -8,6 +8,7 @@ remark -f *.md > /dev/null cargo build --features debugging cargo test --features debugging cd clippy_lints && cargo test && cd .. +cd rustc_tools_util && cargo test && cd .. mkdir -p ~/rust/cargo/bin cp target/debug/cargo-clippy ~/rust/cargo/bin/cargo-clippy cp target/debug/clippy-driver ~/rust/cargo/bin/clippy-driver diff --git a/rustc_tools_util/src/lib.rs b/rustc_tools_util/src/lib.rs index b2ec96122..aad9ee88f 100644 --- a/rustc_tools_util/src/lib.rs +++ b/rustc_tools_util/src/lib.rs @@ -1,3 +1,4 @@ +#![feature(test)] #![feature(tool_lints)] use std::env; @@ -84,3 +85,28 @@ pub fn get_commit_date() -> Option { .ok() .and_then(|r| String::from_utf8(r.stdout).ok()) } + +#[cfg(test)] +mod test { + use super::*; + + #[test] + fn test_struct_local() { + let vi = get_version_info!(); + assert_eq!(vi.major, 0); + assert_eq!(vi.minor, 1); + assert_eq!(vi.patch, 0); + assert_eq!(vi.crate_name, "rustc_tools_util"); + // hard to make positive tests for these since they will always change + assert!(vi.commit_hash.is_none()); + assert!(vi.commit_date.is_none()); + } + + #[test] + fn test_display_local() { + let vi = get_version_info!(); + let fmt = format!("{}", vi); + assert_eq!(fmt, "rustc_tools_util 0.1.0"); + } + +}