mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-27 01:04:03 +00:00
Auto merge of #3614 - matthiaskrgr:rustc_tool_utils, r=phansch
rustc_tool_utils: fix failure to create proper non-repo version string when used in crates on crates.io, bump version
This commit is contained in:
commit
5277a1fb6c
@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "rustc_tools_util"
|
||||
version = "0.1.0"
|
||||
version = "0.1.1"
|
||||
authors = ["Matthias Krüger <matthias.krueger@famsik.de>"]
|
||||
description = "small helper to generate version information for git packages"
|
||||
repository = "https://github.com/rust-lang/rust-clippy"
|
||||
|
@ -46,16 +46,17 @@ pub struct VersionInfo {
|
||||
|
||||
impl std::fmt::Display for VersionInfo {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
if self.commit_hash.is_some() {
|
||||
let hash = self.commit_hash.clone().unwrap_or_default();
|
||||
let hash_trimmed = hash.trim();
|
||||
|
||||
let date = self.commit_date.clone().unwrap_or_default();
|
||||
let date_trimmed = date.trim();
|
||||
|
||||
if (hash_trimmed.len() + date_trimmed.len()) > 0 {
|
||||
write!(
|
||||
f,
|
||||
"{} {}.{}.{} ({} {})",
|
||||
self.crate_name,
|
||||
self.major,
|
||||
self.minor,
|
||||
self.patch,
|
||||
self.commit_hash.clone().unwrap_or_default().trim(),
|
||||
self.commit_date.clone().unwrap_or_default().trim(),
|
||||
self.crate_name, self.major, self.minor, self.patch, hash_trimmed, date_trimmed,
|
||||
)?;
|
||||
} else {
|
||||
write!(f, "{} {}.{}.{}", self.crate_name, self.major, self.minor, self.patch)?;
|
||||
@ -121,7 +122,7 @@ mod test {
|
||||
let vi = get_version_info!();
|
||||
assert_eq!(vi.major, 0);
|
||||
assert_eq!(vi.minor, 1);
|
||||
assert_eq!(vi.patch, 0);
|
||||
assert_eq!(vi.patch, 1);
|
||||
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());
|
||||
@ -131,7 +132,7 @@ mod test {
|
||||
#[test]
|
||||
fn test_display_local() {
|
||||
let vi = get_version_info!();
|
||||
assert_eq!(vi.to_string(), "rustc_tools_util 0.1.0");
|
||||
assert_eq!(vi.to_string(), "rustc_tools_util 0.1.1");
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -140,7 +141,7 @@ mod test {
|
||||
let s = format!("{:?}", vi);
|
||||
assert_eq!(
|
||||
s,
|
||||
"VersionInfo { crate_name: \"rustc_tools_util\", major: 0, minor: 1, patch: 0 }"
|
||||
"VersionInfo { crate_name: \"rustc_tools_util\", major: 0, minor: 1, patch: 1 }"
|
||||
);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user