diff --git a/crates/prek/build.rs b/crates/prek/build.rs index e73efa16..77145095 100644 --- a/crates/prek/build.rs +++ b/crates/prek/build.rs @@ -30,7 +30,12 @@ fn main() { // The workspace root directory is not available without walking up the tree // https://github.com/rust-lang/cargo/issues/3946 #[allow(clippy::disallowed_methods)] - let workspace_root = Path::new(&std::env::var("CARGO_MANIFEST_DIR").unwrap()).to_path_buf(); + let workspace_root = Path::new(&std::env::var("CARGO_MANIFEST_DIR").unwrap()) + .parent() + .expect("CARGO_MANIFEST_DIR should be nested in workspace") + .parent() + .expect("CARGO_MANIFEST_DIR should be doubly nested in workspace") + .to_path_buf(); commit_info(&workspace_root); } diff --git a/crates/prek/tests/run.rs b/crates/prek/tests/run.rs index 9b54e7b6..96dace7c 100644 --- a/crates/prek/tests/run.rs +++ b/crates/prek/tests/run.rs @@ -2785,3 +2785,25 @@ fn run_with_stdin_closed() { ----- stderr ----- "); } + +/// Test `prek --version` outputs version info. +#[test] +fn version_info() { + let context = TestContext::new(); + let filters = context + .filters() + .into_iter() + .chain([( + r"prek \d+\.\d+\.\d+(-[0-9A-Za-z]+(\.[0-9A-Za-z]+)*)?(\+\d+)? \(\w{9} [\d\-T:\.]+\)", + "prek [CURRENT_VERSION] ([COMMIT] [DATE])", + )]) + .collect::>(); + cmd_snapshot!(filters, context.command().arg("--version"), @r" + success: true + exit_code: 0 + ----- stdout ----- + prek [CURRENT_VERSION] ([COMMIT] [DATE]) + + ----- stderr ----- + "); +}