Skip to content

Commit 85c5e2f

Browse files
committed
Start testing that we clear system/global scopes for fixtures
1 parent 3cf9694 commit 85c5e2f

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

tests/tools/src/lib.rs

+36
Original file line numberDiff line numberDiff line change
@@ -868,6 +868,8 @@ impl<'a> Drop for Env<'a> {
868868
#[cfg(test)]
869869
mod tests {
870870
use super::*;
871+
use std::fs::File;
872+
use std::io::Write;
871873

872874
#[test]
873875
fn parse_version() {
@@ -882,4 +884,38 @@ mod tests {
882884
fn parse_version_with_trailing_newline() {
883885
assert_eq!(git_version_from_bytes(b"git version 2.37.2\n").unwrap(), (2, 37, 2));
884886
}
887+
888+
fn check_configure_clears_scope(scope_option: &str) {
889+
let temp = tempfile::TempDir::new().expect("can create temp dir");
890+
#[cfg(windows)]
891+
let names = ["-"];
892+
#[cfg(not(windows))]
893+
let names = ["-", ":"];
894+
for name in names {
895+
File::create(temp.path().join(name))
896+
.expect("can create file")
897+
.write_all(b"[foo]\n\tbar = baz\n")
898+
.expect("can write contents");
899+
}
900+
let mut cmd = std::process::Command::new("git");
901+
let args = ["config", scope_option, "foo.bar"].map(String::from);
902+
configure_command(&mut cmd, &args, temp.path());
903+
let output = cmd.output().expect("can run git");
904+
let stdout = output.stdout.to_str().expect("valid UTF-8");
905+
let status = output.status.code().expect("terminated normally");
906+
assert_eq!(stdout, "", "should be no config variable to display");
907+
assert_eq!(status, 1, "exit status should indicate config variable is absent");
908+
909+
temp.close().expect("Test bug: Should be able to delete everything");
910+
}
911+
912+
#[test]
913+
fn configure_command_clears_system_scope() {
914+
check_configure_clears_scope("--system");
915+
}
916+
917+
#[test]
918+
fn configure_command_clears_global_scope() {
919+
check_configure_clears_scope("--global");
920+
}
885921
}

0 commit comments

Comments
 (0)