Avoid leaking subprocess test temp directories

Co-authored-by: Loyalsoldier <10487845+Loyalsoldier@users.noreply.github.com>
This commit is contained in:
copilot-swe-agent[bot] 2026-08-05 14:57:45 +00:00 committed by GitHub
parent 99bc33355c
commit 3347d40b92
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 8 additions and 8 deletions

View File

@ -12,7 +12,7 @@ import (
"google.golang.org/protobuf/proto"
)
// mainExitEnv marks the re-executed test binary that has to run main().
// mainExitEnv stores the missing input path for the re-executed test binary.
const mainExitEnv = "DATDUMP_TEST_MAIN_EXIT"
func TestLoadGeosite(t *testing.T) {
@ -244,13 +244,13 @@ func TestMainExportsLists(t *testing.T) {
// TestMainExitsOnError re-executes the test binary, because main() terminates
// the process when the export fails.
func TestMainExitsOnError(t *testing.T) {
if os.Getenv(mainExitEnv) == "1" {
os.Args = []string{"datdump", "--inputdata=" + filepath.Join(t.TempDir(), "missing.dat")}
if missingPath := os.Getenv(mainExitEnv); missingPath != "" {
os.Args = []string{"datdump", "--inputdata=" + missingPath}
main()
return
}
cmd := exec.Command(os.Args[0], "-test.run=^TestMainExitsOnError$")
cmd.Env = append(os.Environ(), mainExitEnv+"=1")
cmd.Env = append(os.Environ(), mainExitEnv+"="+filepath.Join(t.TempDir(), "missing.dat"))
out, err := cmd.CombinedOutput()
var exitErr *exec.ExitError
if !errors.As(err, &exitErr) || exitErr.ExitCode() != 1 {

View File

@ -14,7 +14,7 @@ import (
"google.golang.org/protobuf/proto"
)
// mainExitEnv marks the re-executed test binary that has to run main().
// mainExitEnv stores the missing data path for the re-executed test binary.
const mainExitEnv = "DLC_TEST_MAIN_EXIT"
// datList is a list and its rules read back from a generated dat file.
@ -667,13 +667,13 @@ func TestMainGeneratesDat(t *testing.T) {
// TestMainExitsOnError re-executes the test binary, because main() terminates
// the process when the generation fails.
func TestMainExitsOnError(t *testing.T) {
if os.Getenv(mainExitEnv) == "1" {
os.Args = []string{"domain-list-community", "--datapath=" + filepath.Join(t.TempDir(), "missing")}
if missingPath := os.Getenv(mainExitEnv); missingPath != "" {
os.Args = []string{"domain-list-community", "--datapath=" + missingPath}
main()
return
}
cmd := exec.Command(os.Args[0], "-test.run=^TestMainExitsOnError$")
cmd.Env = append(os.Environ(), mainExitEnv+"=1")
cmd.Env = append(os.Environ(), mainExitEnv+"="+filepath.Join(t.TempDir(), "missing"))
out, err := cmd.CombinedOutput()
var exitErr *exec.ExitError
if !errors.As(err, &exitErr) || exitErr.ExitCode() != 1 {