mirror of
https://github.com/golang/go
synced 2024-11-06 11:26:12 -07:00
b5a68a9e41
I hope that this will fix the tests on iOS, but 'gomote create' isn't giving me an instance I can test with. (Please patch and test before approving.) Updates #15919 Updates #30228 Change-Id: I1b7cd30d5b127a1ad3243b329fa005d229f69a24 Reviewed-on: https://go-review.googlesource.com/c/163726 Run-TryBot: Bryan C. Mills <bcmills@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Elias Naur <mail@eliasnaur.com>
62 lines
1.4 KiB
Go
62 lines
1.4 KiB
Go
// Copyright 2019 The Go Authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style
|
|
// license that can be found in the LICENSE file.
|
|
|
|
package life_test
|
|
|
|
import (
|
|
"bytes"
|
|
"io/ioutil"
|
|
"log"
|
|
"os"
|
|
"os/exec"
|
|
"path/filepath"
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
func TestMain(m *testing.M) {
|
|
log.SetFlags(log.Lshortfile)
|
|
os.Exit(testMain(m))
|
|
}
|
|
|
|
func testMain(m *testing.M) int {
|
|
GOPATH, err := ioutil.TempDir("", "cgolife")
|
|
if err != nil {
|
|
log.Panic(err)
|
|
}
|
|
defer os.RemoveAll(GOPATH)
|
|
os.Setenv("GOPATH", GOPATH)
|
|
|
|
// Copy testdata into GOPATH/src/cgolife, along with a go.mod file
|
|
// declaring the same path.
|
|
modRoot := filepath.Join(GOPATH, "src", "cgolife")
|
|
if err := overlayDir(modRoot, "testdata"); err != nil {
|
|
log.Panic(err)
|
|
}
|
|
if err := os.Chdir(modRoot); err != nil {
|
|
log.Panic(err)
|
|
}
|
|
os.Setenv("PWD", modRoot)
|
|
if err := ioutil.WriteFile("go.mod", []byte("module cgolife\n"), 0666); err != nil {
|
|
log.Panic(err)
|
|
}
|
|
|
|
return m.Run()
|
|
}
|
|
|
|
func TestTestRun(t *testing.T) {
|
|
out, err := exec.Command("go", "env", "GOROOT").Output()
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
GOROOT := string(bytes.TrimSpace(out))
|
|
|
|
cmd := exec.Command("go", "run", filepath.Join(GOROOT, "test", "run.go"), "-", ".")
|
|
out, err = cmd.CombinedOutput()
|
|
if err != nil {
|
|
t.Fatalf("%s: %s\n%s", strings.Join(cmd.Args, " "), err, out)
|
|
}
|
|
t.Logf("%s:\n%s", strings.Join(cmd.Args, " "), out)
|
|
}
|