all: use new testing features of Go 1.14 and 1.15
This simplifies the tests a bit.
Этот коммит содержится в:
родитель
25c7bfd404
коммит
59d53182bb
7 изменённых файлов: 10 добавлений и 39 удалений
11
main_test.go
11
main_test.go
|
@ -210,16 +210,7 @@ func runTestWithConfig(name, target string, t *testing.T, options compileopts.Op
|
|||
}
|
||||
|
||||
// Create a temporary directory for test output files.
|
||||
tmpdir, err := ioutil.TempDir("", "tinygo-test")
|
||||
if err != nil {
|
||||
t.Fatal("could not create temporary directory:", err)
|
||||
}
|
||||
defer func() {
|
||||
rerr := os.RemoveAll(tmpdir)
|
||||
if rerr != nil {
|
||||
t.Errorf("failed to remove temporary directory %q: %s", tmpdir, rerr.Error())
|
||||
}
|
||||
}()
|
||||
tmpdir := t.TempDir()
|
||||
|
||||
// Determine whether we're on a system that supports environment variables
|
||||
// and command line parameters (operating systems, WASI) or not (baremetal,
|
||||
|
|
|
@ -11,8 +11,7 @@ func TestChan(t *testing.T) {
|
|||
|
||||
t.Parallel()
|
||||
|
||||
wasmTmpDir, server, cleanup := startServer(t)
|
||||
defer cleanup()
|
||||
wasmTmpDir, server := startServer(t)
|
||||
|
||||
err := run("tinygo build -o " + wasmTmpDir + "/chan.wasm -target wasm testdata/chan.go")
|
||||
if err != nil {
|
||||
|
|
|
@ -11,8 +11,7 @@ func TestEvent(t *testing.T) {
|
|||
|
||||
t.Parallel()
|
||||
|
||||
wasmTmpDir, server, cleanup := startServer(t)
|
||||
defer cleanup()
|
||||
wasmTmpDir, server := startServer(t)
|
||||
|
||||
err := run("tinygo build -o " + wasmTmpDir + "/event.wasm -target wasm testdata/event.go")
|
||||
if err != nil {
|
||||
|
|
|
@ -11,8 +11,7 @@ func TestFmt(t *testing.T) {
|
|||
|
||||
t.Parallel()
|
||||
|
||||
wasmTmpDir, server, cleanup := startServer(t)
|
||||
defer cleanup()
|
||||
wasmTmpDir, server := startServer(t)
|
||||
|
||||
err := run("tinygo build -o " + wasmTmpDir + "/fmt.wasm -target wasm testdata/fmt.go")
|
||||
if err != nil {
|
||||
|
|
|
@ -11,8 +11,7 @@ func TestFmtprint(t *testing.T) {
|
|||
|
||||
t.Parallel()
|
||||
|
||||
wasmTmpDir, server, cleanup := startServer(t)
|
||||
defer cleanup()
|
||||
wasmTmpDir, server := startServer(t)
|
||||
|
||||
err := run("tinygo build -o " + wasmTmpDir + "/fmtprint.wasm -target wasm testdata/fmtprint.go")
|
||||
if err != nil {
|
||||
|
|
|
@ -11,8 +11,7 @@ func TestLog(t *testing.T) {
|
|||
|
||||
t.Parallel()
|
||||
|
||||
wasmTmpDir, server, cleanup := startServer(t)
|
||||
defer cleanup()
|
||||
wasmTmpDir, server := startServer(t)
|
||||
|
||||
err := run("tinygo build -o " + wasmTmpDir + "/log.wasm -target wasm testdata/log.go")
|
||||
if err != nil {
|
||||
|
|
|
@ -4,11 +4,9 @@ import (
|
|||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"os"
|
||||
"os/exec"
|
||||
"regexp"
|
||||
"strings"
|
||||
|
@ -47,12 +45,8 @@ func chromectx(timeout time.Duration) (context.Context, context.CancelFunc) {
|
|||
return ctx, cancel
|
||||
}
|
||||
|
||||
func startServer(t *testing.T) (string, *httptest.Server, func()) {
|
||||
// In Go 1.15, all this can be replaced by t.TempDir()
|
||||
tmpDir, err := ioutil.TempDir("", "wasm_test")
|
||||
if err != nil {
|
||||
t.Fatalf("unable to create temp dir: %v", err)
|
||||
}
|
||||
func startServer(t *testing.T) (string, *httptest.Server) {
|
||||
tmpDir := t.TempDir()
|
||||
|
||||
fsh := http.FileServer(http.Dir(tmpDir))
|
||||
h := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
|
@ -124,18 +118,9 @@ if (wasmSupported) {
|
|||
|
||||
server := httptest.NewServer(h)
|
||||
t.Logf("Started server at %q for dir: %s", server.URL, tmpDir)
|
||||
t.Cleanup(server.Close)
|
||||
|
||||
// In Go 1.14+, this can be replaced by t.Cleanup()
|
||||
cleanup := func() {
|
||||
err := os.RemoveAll(tmpDir)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
server.Close()
|
||||
}
|
||||
|
||||
return tmpDir, server, cleanup
|
||||
return tmpDir, server
|
||||
}
|
||||
|
||||
// waitLog blocks until the log output equals the text provided (ignoring whitespace before and after)
|
||||
|
|
Загрузка…
Создание таблицы
Сослаться в новой задаче