Skip to content

Commit bdab383

Browse files
bgilbertMitMaro
authored andcommitted
Fix failure building build_version_with_env test outside of Git
If we're building tests from an unpacked crate instead of a Git repo, we won't have a commit hash.
1 parent bf9348b commit bdab383

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

src/version.rs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,23 @@ mod tests {
4747
#[test]
4848
#[serial_test::serial]
4949
fn build_version_with_env() {
50+
let maybe_git_hash = option_env!("GIRT_BUILD_GIT_HASH");
51+
assert_eq!(
52+
std::process::Command::new("git")
53+
.args(["rev-parse", "--is-inside-work-tree"])
54+
.output()
55+
.map(|out| out.status.success())
56+
.unwrap_or(false),
57+
maybe_git_hash.is_some()
58+
);
59+
5060
let version = build_version();
51-
let expected_meta = format!("({} {})", env!("GIRT_BUILD_GIT_HASH"), env!("GIRT_BUILD_DATE"));
61+
let expected_meta = if let Some(git_hash) = maybe_git_hash {
62+
format!("({} {})", git_hash, env!("GIRT_BUILD_DATE"))
63+
}
64+
else {
65+
format!("({})", env!("GIRT_BUILD_DATE"))
66+
};
5267
assert!(version.starts_with("interactive-rebase-tool"));
5368
assert!(version.ends_with(expected_meta.as_str()));
5469
}

0 commit comments

Comments
 (0)