Skip to content

Commit d5b61df

Browse files
committed
Test that the system/global scopes are really cleared
Rather than just not having the configuration variable we add. - Keep testing the current failure mode where the unusually named `never_path` files can actually exist. - Also test for paths for those scopes' configuration files, coming from the environment. - Test that the output of showing the full scope's contents is empty, of all values. Note that this includes the system scope but not all scopes higher than the global scope: the "unknown" scope associated with an Apple Git configuration is deliberately not asserted to be cleared here. (`gix-testtools` possibly intentionally does not clear that scope for fixture scripts.)
1 parent 85c5e2f commit d5b61df

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

tests/tools/src/lib.rs

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -885,24 +885,29 @@ mod tests {
885885
assert_eq!(git_version_from_bytes(b"git version 2.37.2\n").unwrap(), (2, 37, 2));
886886
}
887887

888-
fn check_configure_clears_scope(scope_option: &str) {
888+
fn check_configure_clears_scope(scope_env_var: &str, scope_option: &str) {
889889
let temp = tempfile::TempDir::new().expect("can create temp dir");
890+
890891
#[cfg(windows)]
891-
let names = ["-"];
892+
let names = ["config", "-"];
892893
#[cfg(not(windows))]
893-
let names = ["-", ":"];
894+
let names = ["config", "-", ":"];
894895
for name in names {
895-
File::create(temp.path().join(name))
896+
File::create_new(temp.path().join(name))
896897
.expect("can create file")
897898
.write_all(b"[foo]\n\tbar = baz\n")
898899
.expect("can write contents");
899900
}
901+
900902
let mut cmd = std::process::Command::new("git");
901-
let args = ["config", scope_option, "foo.bar"].map(String::from);
903+
cmd.env(scope_env_var, "config"); // configure_command() should override it.
904+
let args = ["config", "-l", "--show-origin", scope_option].map(String::from);
902905
configure_command(&mut cmd, &args, temp.path());
906+
903907
let output = cmd.output().expect("can run git");
904908
let stdout = output.stdout.to_str().expect("valid UTF-8");
905909
let status = output.status.code().expect("terminated normally");
910+
906911
assert_eq!(stdout, "", "should be no config variable to display");
907912
assert_eq!(status, 1, "exit status should indicate config variable is absent");
908913

@@ -911,11 +916,11 @@ mod tests {
911916

912917
#[test]
913918
fn configure_command_clears_system_scope() {
914-
check_configure_clears_scope("--system");
919+
check_configure_clears_scope("GIT_CONFIG_SYSTEM", "--system");
915920
}
916921

917922
#[test]
918923
fn configure_command_clears_global_scope() {
919-
check_configure_clears_scope("--global");
924+
check_configure_clears_scope("GIT_CONFIG_GLOBAL", "--global");
920925
}
921926
}

0 commit comments

Comments
 (0)