Skip to content

Commit e8a8f89

Browse files
authored
Merge pull request #1081 from nevkontakte/master
Improve temporary file management in `gopherjs test`.
2 parents 1e6abe7 + 57cbbe8 commit e8a8f89

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

tool.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -432,18 +432,19 @@ func main() {
432432
return err
433433
}
434434
} else {
435-
outfile, err = ioutil.TempFile(currentDirectory, "test.")
435+
outfile, err = os.CreateTemp(currentDirectory, pkg.Package.Name+"_test.*.js")
436436
if err != nil {
437437
return err
438438
}
439+
outfile.Close() // Release file handle early, we only need the name.
439440
}
440-
defer func() {
441-
outfile.Close()
441+
cleanupTemp := func() {
442442
if *outputFilename == "" {
443443
os.Remove(outfile.Name())
444444
os.Remove(outfile.Name() + ".map")
445445
}
446-
}()
446+
}
447+
defer cleanupTemp() // Safety net in case cleanup after execution doesn't happen.
447448

448449
if err := s.WriteCommandPackage(mainPkgArchive, outfile.Name()); err != nil {
449450
return err
@@ -487,6 +488,8 @@ func main() {
487488

488489
err := runNode(outfile.Name(), args, runTestDir(pkg), options.Quiet, testOut)
489490

491+
cleanupTemp() // Eagerly cleanup temporary compiled files after execution.
492+
490493
if testOut != nil {
491494
io.Copy(os.Stdout, testOut)
492495
}

0 commit comments

Comments
 (0)