@@ -46,16 +46,17 @@ pub struct VersionInfo {
46
46
47
47
impl std:: fmt:: Display for VersionInfo {
48
48
fn fmt ( & self , f : & mut std:: fmt:: Formatter < ' _ > ) -> std:: fmt:: Result {
49
- if self . commit_hash . is_some ( ) {
49
+ let hash = self . commit_hash . clone ( ) . unwrap_or_default ( ) ;
50
+ let hash_trimmed = hash. trim ( ) ;
51
+
52
+ let date = self . commit_date . clone ( ) . unwrap_or_default ( ) ;
53
+ let date_trimmed = date. trim ( ) ;
54
+
55
+ if ( hash_trimmed. len ( ) + date_trimmed. len ( ) ) > 0 {
50
56
write ! (
51
57
f,
52
58
"{} {}.{}.{} ({} {})" ,
53
- self . crate_name,
54
- self . major,
55
- self . minor,
56
- self . patch,
57
- self . commit_hash. clone( ) . unwrap_or_default( ) . trim( ) ,
58
- self . commit_date. clone( ) . unwrap_or_default( ) . trim( ) ,
59
+ self . crate_name, self . major, self . minor, self . patch, hash_trimmed, date_trimmed,
59
60
) ?;
60
61
} else {
61
62
write ! ( f, "{} {}.{}.{}" , self . crate_name, self . major, self . minor, self . patch) ?;
@@ -121,7 +122,7 @@ mod test {
121
122
let vi = get_version_info ! ( ) ;
122
123
assert_eq ! ( vi. major, 0 ) ;
123
124
assert_eq ! ( vi. minor, 1 ) ;
124
- assert_eq ! ( vi. patch, 0 ) ;
125
+ assert_eq ! ( vi. patch, 1 ) ;
125
126
assert_eq ! ( vi. crate_name, "rustc_tools_util" ) ;
126
127
// hard to make positive tests for these since they will always change
127
128
assert ! ( vi. commit_hash. is_none( ) ) ;
@@ -131,7 +132,7 @@ mod test {
131
132
#[ test]
132
133
fn test_display_local ( ) {
133
134
let vi = get_version_info ! ( ) ;
134
- assert_eq ! ( vi. to_string( ) , "rustc_tools_util 0.1.0 " ) ;
135
+ assert_eq ! ( vi. to_string( ) , "rustc_tools_util 0.1.1 " ) ;
135
136
}
136
137
137
138
#[ test]
@@ -140,7 +141,7 @@ mod test {
140
141
let s = format ! ( "{:?}" , vi) ;
141
142
assert_eq ! (
142
143
s,
143
- "VersionInfo { crate_name: \" rustc_tools_util\" , major: 0, minor: 1, patch: 0 }"
144
+ "VersionInfo { crate_name: \" rustc_tools_util\" , major: 0, minor: 1, patch: 1 }"
144
145
) ;
145
146
}
146
147
0 commit comments