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".
Этот коммит содержится в:
Dan Kegel 2022-01-01 13:30:53 -08:00 коммит произвёл Ron Evans
родитель e046b23773
коммит ec97313239
3 изменённых файлов: 11 добавлений и 3 удалений

Просмотреть файл

@ -228,6 +228,7 @@ TEST_PACKAGES_BASE = \
math/cmplx \
net/http/internal/ascii \
net/mail \
os \
path \
reflect \
sync \
@ -243,7 +244,6 @@ TEST_PACKAGES = \
$(TEST_PACKAGES_BASE) \
compress/flate \
compress/zlib \
os \
# Standard library packages that pass tests on wasi
TEST_PACKAGES_WASI = \

Просмотреть файл

@ -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=.", "--")

Просмотреть файл

@ -19,7 +19,7 @@ func randomName() string {
}
func TestMkdir(t *testing.T) {
dir := "TestMkdir" + randomName()
dir := TempDir() + "/TestMkdir" + randomName()
Remove(dir)
err := Mkdir(dir, 0755)
defer Remove(dir)
@ -65,7 +65,7 @@ func writeFile(t *testing.T, fname string, flag int, text string) string {
}
func TestRemove(t *testing.T) {
f := "TestRemove" + randomName()
f := TempDir() + "/TestRemove" + randomName()
err := Remove(f)
if err == nil {