Skip to content

Commit

Permalink
Fix failure building build_version_with_env test outside of Git
Browse files Browse the repository at this point in the history
If we're building tests from an unpacked crate instead of a Git repo, we
won't have a commit hash.
  • Loading branch information
bgilbert authored and MitMaro committed Jul 4, 2024
1 parent bf9348b commit bdab383
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion src/version.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,23 @@ mod tests {
#[test]
#[serial_test::serial]
fn build_version_with_env() {
let maybe_git_hash = option_env!("GIRT_BUILD_GIT_HASH");
assert_eq!(
std::process::Command::new("git")
.args(["rev-parse", "--is-inside-work-tree"])
.output()
.map(|out| out.status.success())
.unwrap_or(false),
maybe_git_hash.is_some()
);

let version = build_version();
let expected_meta = format!("({} {})", env!("GIRT_BUILD_GIT_HASH"), env!("GIRT_BUILD_DATE"));
let expected_meta = if let Some(git_hash) = maybe_git_hash {
format!("({} {})", git_hash, env!("GIRT_BUILD_DATE"))
}
else {
format!("({})", env!("GIRT_BUILD_DATE"))
};
assert!(version.starts_with("interactive-rebase-tool"));
assert!(version.ends_with(expected_meta.as_str()));
}
Expand Down

0 comments on commit bdab383

Please sign in to comment.