blob: 86d51fcc1de2712e7b262e0caf1c56342b85167a (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
|
use crate::exit::Exit;
#[cfg(not(feature = "dev"))]
pub(crate) const VERSION: &str = env!("CARGO_PKG_VERSION");
#[cfg(feature = "dev")]
pub(crate) const VERSION: &str = concat!(env!("CARGO_PKG_VERSION"), "-dev");
fn build_version() -> String {
let mut parts = vec![];
if let Some(hash) = option_env!("GIRT_BUILD_GIT_HASH") {
parts.push(String::from(hash));
}
parts.push(String::from(env!("GIRT_BUILD_DATE")));
format!("interactive-rebase-tool {VERSION} ({})", parts.join(" "))
}
pub(crate) fn run() -> Exit {
Exit::from(build_version())
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
#[serial_test::serial]
fn test_run() {
assert!(
run()
.get_message()
.as_ref()
.unwrap()
.starts_with("interactive-rebase-tool")
);
}
#[test]
#[serial_test::serial]
fn build_version_default() {
let version = build_version();
assert!(version.starts_with("interactive-rebase-tool"));
}
#[test]
#[serial_test::serial]
fn build_version_with_env() {
let version = build_version();
let expected_meta = format!("({} {})", env!("GIRT_BUILD_GIT_HASH"), env!("GIRT_BUILD_DATE"));
assert!(version.starts_with("interactive-rebase-tool"));
assert!(version.ends_with(expected_meta.as_str()));
}
}
|