From 891641670c4ddb65027eed1a7dee3cf07200552c Mon Sep 17 00:00:00 2001 From: Martin von Zweigbergk Date: Sat, 5 Mar 2022 18:35:19 -0800 Subject: [PATCH] tests: don't propagate environment variables to tests We don't want variables from the developer's environment to affect tests. You can make tests fail if you set `XDG_CONFIG_HOME` such that `$XDG_CONFIG_HOME/jj/config.toml` exists and has e.g. an email set. The fix is to not propagate any environment variables. Thanks for @arxanas for pointing this out in #104. We still need to set `$HOME` to prevent configs from being read from the process owner's home directory (because that's what `dirs::config_dir()` seems to fall back to if `$HOME` is not set). By the way, I suspect we'd still not immune to configs from the developers home directory on Windows, because that doesn't seem to be controlled by `$HOME`. --- src/testutils.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/testutils.rs b/src/testutils.rs index b9a66fff4..63f086642 100644 --- a/src/testutils.rs +++ b/src/testutils.rs @@ -45,6 +45,7 @@ impl TestEnvironment { let mut cmd = assert_cmd::Command::cargo_bin("jj").unwrap(); cmd.current_dir(current_dir); cmd.args(args); + cmd.env_clear(); cmd.env("HOME", self.home_dir.to_str().unwrap()); let timestamp = chrono::DateTime::parse_from_rfc3339("2001-02-03T04:05:06+07:00").unwrap(); let mut command_number = self.command_number.borrow_mut();