Skip to content

Improve temporary file management in gopherjs test. #1081

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 30, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions tool.go
Original file line number Diff line number Diff line change
Expand Up @@ -432,18 +432,19 @@ func main() {
return err
}
} else {
outfile, err = ioutil.TempFile(currentDirectory, "test.")
outfile, err = os.CreateTemp(currentDirectory, pkg.Package.Name+"_test.*.js")
if err != nil {
return err
}
outfile.Close() // Release file handle early, we only need the name.
}
defer func() {
outfile.Close()
cleanupTemp := func() {
if *outputFilename == "" {
os.Remove(outfile.Name())
os.Remove(outfile.Name() + ".map")
}
}()
}
defer cleanupTemp() // Safety net in case cleanup after execution doesn't happen.

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

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

cleanupTemp() // Eagerly cleanup temporary compiled files after execution.

if testOut != nil {
io.Copy(os.Stdout, testOut)
}
Expand Down