1
+ #![ feature( test) ]
1
2
#![ feature( tool_lints) ]
2
3
3
4
use std:: env;
@@ -8,6 +9,7 @@ macro_rules! get_version_info {
8
9
let major = env!( "CARGO_PKG_VERSION_MAJOR" ) . parse:: <u8 >( ) . unwrap( ) ;
9
10
let minor = env!( "CARGO_PKG_VERSION_MINOR" ) . parse:: <u8 >( ) . unwrap( ) ;
10
11
let patch = env!( "CARGO_PKG_VERSION_PATCH" ) . parse:: <u16 >( ) . unwrap( ) ;
12
+ let crate_name = String :: from( env!( "CARGO_PKG_NAME" ) ) ;
11
13
12
14
let host_compiler = $crate:: get_channel( ) ;
13
15
let commit_hash = option_env!( "GIT_HASH" ) . map( |s| s. to_string( ) ) ;
@@ -20,6 +22,7 @@ macro_rules! get_version_info {
20
22
host_compiler,
21
23
commit_hash,
22
24
commit_date,
25
+ crate_name,
23
26
}
24
27
} } ;
25
28
}
@@ -32,6 +35,7 @@ pub struct VersionInfo {
32
35
pub host_compiler : Option < String > ,
33
36
pub commit_hash : Option < String > ,
34
37
pub commit_date : Option < String > ,
38
+ pub crate_name : String ,
35
39
}
36
40
37
41
impl std:: fmt:: Display for VersionInfo {
@@ -40,7 +44,8 @@ impl std::fmt::Display for VersionInfo {
40
44
Some ( _) => {
41
45
write ! (
42
46
f,
43
- "clippy {}.{}.{} ({} {})" ,
47
+ "{} {}.{}.{} ({} {})" ,
48
+ self . crate_name,
44
49
self . major,
45
50
self . minor,
46
51
self . patch,
@@ -49,7 +54,7 @@ impl std::fmt::Display for VersionInfo {
49
54
) ?;
50
55
} ,
51
56
None => {
52
- write ! ( f, "clippy {}.{}.{}" , self . major, self . minor, self . patch) ?;
57
+ write ! ( f, "{} {}.{}.{}" , self . crate_name , self . major, self . minor, self . patch) ?;
53
58
} ,
54
59
} ;
55
60
Ok ( ( ) )
@@ -80,3 +85,28 @@ pub fn get_commit_date() -> Option<String> {
80
85
. ok ( )
81
86
. and_then ( |r| String :: from_utf8 ( r. stdout ) . ok ( ) )
82
87
}
88
+
89
+ #[ cfg( test) ]
90
+ mod test {
91
+ use super :: * ;
92
+
93
+ #[ test]
94
+ fn test_struct_local ( ) {
95
+ let vi = get_version_info ! ( ) ;
96
+ assert_eq ! ( vi. major, 0 ) ;
97
+ assert_eq ! ( vi. minor, 1 ) ;
98
+ assert_eq ! ( vi. patch, 0 ) ;
99
+ assert_eq ! ( vi. crate_name, "rustc_tools_util" ) ;
100
+ // hard to make positive tests for these since they will always change
101
+ assert ! ( vi. commit_hash. is_none( ) ) ;
102
+ assert ! ( vi. commit_date. is_none( ) ) ;
103
+ }
104
+
105
+ #[ test]
106
+ fn test_display_local ( ) {
107
+ let vi = get_version_info ! ( ) ;
108
+ let fmt = format ! ( "{}" , vi) ;
109
+ assert_eq ! ( fmt, "rustc_tools_util 0.1.0" ) ;
110
+ }
111
+
112
+ }
0 commit comments