From b1ba87b2a37500a23c7f6dc33418e72d05ab7f61 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christoph=20R=C3=BC=C3=9Fler?= Date: Mon, 14 Oct 2024 20:02:22 +0200 Subject: [PATCH 1/4] Add test for AsyncLog respecting GIT_DIR --- asyncgit/src/revlog.rs | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/asyncgit/src/revlog.rs b/asyncgit/src/revlog.rs index 0a2a2d3680..13a1631808 100644 --- a/asyncgit/src/revlog.rs +++ b/asyncgit/src/revlog.rs @@ -331,6 +331,7 @@ mod tests { use std::time::Duration; use crossbeam_channel::unbounded; + use tempfile::TempDir; use crate::sync::tests::{debug_cmd_print, repo_init}; use crate::sync::RepoPath; @@ -368,4 +369,36 @@ mod tests { assert!(result.is_ok()); } + + #[test] + fn test_env_variables() { + let (_td, repo) = repo_init().unwrap(); + let git_dir = repo.path(); + + let (tx_git, _rx_git) = unbounded(); + + let empty_dir = TempDir::new().unwrap(); + let empty_path: RepoPath = + empty_dir.path().to_str().unwrap().into(); + + let arc_current = Arc::new(Mutex::new(AsyncLogResult { + commits: Vec::new(), + duration: Duration::default(), + })); + let arc_background = Arc::new(AtomicBool::new(false)); + + std::env::set_var("GIT_DIR", git_dir); + + let result = AsyncLog::fetch_helper_without_filter( + // We pass an empty path, thus testing whether `GIT_DIR`, set above, is taken into account. + &empty_path, + &arc_current, + &arc_background, + &tx_git, + ); + + std::env::remove_var("GIT_DIR"); + + assert!(result.is_ok()); + } } From d43eee0d33db9a090aec51346cac5a150f578349 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christoph=20R=C3=BC=C3=9Fler?= Date: Tue, 15 Oct 2024 08:45:11 +0200 Subject: [PATCH 2/4] Mark test as serial --- asyncgit/src/revlog.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/asyncgit/src/revlog.rs b/asyncgit/src/revlog.rs index 13a1631808..af18432385 100644 --- a/asyncgit/src/revlog.rs +++ b/asyncgit/src/revlog.rs @@ -331,6 +331,7 @@ mod tests { use std::time::Duration; use crossbeam_channel::unbounded; + use serial_test::serial; use tempfile::TempDir; use crate::sync::tests::{debug_cmd_print, repo_init}; @@ -371,6 +372,7 @@ mod tests { } #[test] + #[serial] fn test_env_variables() { let (_td, repo) = repo_init().unwrap(); let git_dir = repo.path(); From 00e504ee0b6b44116edf66ac5218e3ee39e8e763 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christoph=20R=C3=BC=C3=9Fler?= Date: Mon, 28 Oct 2024 18:58:13 +0100 Subject: [PATCH 3/4] Mark additional test as serial --- asyncgit/src/revlog.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/asyncgit/src/revlog.rs b/asyncgit/src/revlog.rs index af18432385..cf3b78021a 100644 --- a/asyncgit/src/revlog.rs +++ b/asyncgit/src/revlog.rs @@ -341,6 +341,7 @@ mod tests { use super::AsyncLogResult; #[test] + #[serial] fn test_smoke_in_subdir() { let (_td, repo) = repo_init().unwrap(); let root = repo.path().parent().unwrap(); From fef175a6969587a10bdbc4e244bb2553441bcb59 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christoph=20R=C3=BC=C3=9Fler?= Date: Mon, 28 Oct 2024 18:58:49 +0100 Subject: [PATCH 4/4] Unwrap result to get more info in error case --- asyncgit/src/revlog.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/asyncgit/src/revlog.rs b/asyncgit/src/revlog.rs index cf3b78021a..38febb84a4 100644 --- a/asyncgit/src/revlog.rs +++ b/asyncgit/src/revlog.rs @@ -369,7 +369,7 @@ mod tests { &tx_git, ); - assert!(result.is_ok()); + assert_eq!(result.unwrap(), ()); } #[test] @@ -402,6 +402,6 @@ mod tests { std::env::remove_var("GIT_DIR"); - assert!(result.is_ok()); + assert_eq!(result.unwrap(), ()); } }