When running tests under wasmtime, provide a fresh TMPDIR.

Also fix a couple os tests that wrote to current directory to write to os.TempDir() instead.

After this, os tests pass in wasi, so add them to the list run by "make tinygo-test-wasi".
This commit is contained in:
Dan Kegel
2022-01-01 13:30:53 -08:00
committed by Ron Evans
parent e046b23773
commit ec97313239
3 changed files with 11 additions and 3 deletions
+8
View File
@@ -254,6 +254,14 @@ func runPackageTest(config *compileopts.Config, stdout, stderr io.Writer, result
// Run in an emulator.
args := append(config.Target.Emulator[1:], result.Binary)
if config.Target.Emulator[0] == "wasmtime" {
// create a new temp directory just for this run, announce it to os.TempDir() via TMPDIR
tmpdir, err := ioutil.TempDir("", "tinygotmp")
if err != nil {
return false, &commandError{"failed to create temporary directory", "tinygotmp", err}
}
args = append(args, "--dir="+tmpdir, "--env=TMPDIR="+tmpdir)
// TODO: add option to not delete temp dir for debugging?
defer os.RemoveAll(tmpdir)
// allow reading from current directory: --dir=.
// mark end of wasmtime arguments and start of program ones: --
args = append(args, "--dir=.", "--")