From 43050ecfe9572f7bf5e0ece962e7f462aeddb9ff Mon Sep 17 00:00:00 2001 From: j178 <10510431+j178@users.noreply.github.com> Date: Sat, 23 Nov 2024 21:25:40 +0800 Subject: [PATCH 1/2] Improve tests --- .config/nextest.toml | 2 +- tests/common/mod.rs | 16 ---------------- 2 files changed, 1 insertion(+), 17 deletions(-) diff --git a/.config/nextest.toml b/.config/nextest.toml index 9f515aa..0f76185 100644 --- a/.config/nextest.toml +++ b/.config/nextest.toml @@ -5,6 +5,6 @@ uv = { max-threads = 1} # due to concurrent uv cache writes. # Configure these tests to run sequentially. [[profile.default.overrides]] -filter = 'test(run_basic) | test(local_need_install)' +filter = 'binary(run) and test(/run_basic|local_need_install/)' platform = 'cfg(windows)' test-group = 'uv' diff --git a/tests/common/mod.rs b/tests/common/mod.rs index b9cac21..f9cf369 100644 --- a/tests/common/mod.rs +++ b/tests/common/mod.rs @@ -184,22 +184,6 @@ impl TestContext { .current_dir(&self.temp_dir) .assert() .success(); - - Command::new("git") - .arg("config") - .current_dir(&self.temp_dir) - .arg("user.name") - .arg("Test User") - .assert() - .success(); - - Command::new("git") - .arg("config") - .current_dir(&self.temp_dir) - .arg("user.email") - .arg("test@example.com") - .assert() - .success(); } /// Run `git add` in the temporary directory. From f8d0e85f07e63e25d2d404adf7c80ba71f1ee6d0 Mon Sep 17 00:00:00 2001 From: j178 <10510431+j178@users.noreply.github.com> Date: Sat, 23 Nov 2024 21:31:15 +0800 Subject: [PATCH 2/2] Fix --- tests/common/mod.rs | 22 ++++++++++++++++++++-- tests/hook_impl.rs | 2 +- tests/run.rs | 1 + 3 files changed, 22 insertions(+), 3 deletions(-) diff --git a/tests/common/mod.rs b/tests/common/mod.rs index f9cf369..6cd9d5f 100644 --- a/tests/common/mod.rs +++ b/tests/common/mod.rs @@ -186,7 +186,25 @@ impl TestContext { .success(); } - /// Run `git add` in the temporary directory. + /// Configure git user and email. + pub fn configure_git_author(&self) { + Command::new("git") + .arg("config") + .arg("user.name") + .arg("Pre-Commit Test") + .current_dir(&self.temp_dir) + .assert() + .success(); + Command::new("git") + .arg("config") + .arg("user.email") + .arg("test@pre-commit-rs.dev") + .current_dir(&self.temp_dir) + .assert() + .success(); + } + + /// Run `git add`. pub fn git_add(&self, path: impl AsRef) { Command::new("git") .arg("add") @@ -196,7 +214,7 @@ impl TestContext { .success(); } - /// Run `git commit` in the temporary directory. + /// Run `git commit`. pub fn git_commit(&self, message: &str) { Command::new("git") .arg("commit") diff --git a/tests/hook_impl.rs b/tests/hook_impl.rs index f4a4596..77f468b 100644 --- a/tests/hook_impl.rs +++ b/tests/hook_impl.rs @@ -25,7 +25,7 @@ fn hook_impl() { "}); context.git_add("."); - + context.configure_git_author(); let mut commit = Command::new("git"); commit .arg("commit") diff --git a/tests/run.rs b/tests/run.rs index 38c2948..1f79a26 100644 --- a/tests/run.rs +++ b/tests/run.rs @@ -728,6 +728,7 @@ fn merge_conflicts() -> Result<()> { let cwd = context.workdir(); cwd.child("file.txt").write_str("Hello, world!")?; context.git_add("."); + context.configure_git_author(); context.git_commit("Initial commit"); Command::new("git")