1 // Copyright 2019 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
17 func TestMain(m *testing.M) {
18 log.SetFlags(log.Lshortfile)
22 func testMain(m *testing.M) int {
23 GOPATH, err := os.MkdirTemp("", "cgostdio")
27 defer os.RemoveAll(GOPATH)
28 os.Setenv("GOPATH", GOPATH)
30 // Copy testdata into GOPATH/src/cgostdio, along with a go.mod file
31 // declaring the same path.
32 modRoot := filepath.Join(GOPATH, "src", "cgostdio")
33 if err := overlayDir(modRoot, "testdata"); err != nil {
36 if err := os.Chdir(modRoot); err != nil {
39 os.Setenv("PWD", modRoot)
40 if err := os.WriteFile("go.mod", []byte("module cgostdio\n"), 0666); err != nil {
47 func TestTestRun(t *testing.T) {
48 if os.Getenv("GOOS") == "android" {
49 t.Skip("subpackage stdio is not available on android")
51 out, err := exec.Command("go", "env", "GOROOT").Output()
55 GOROOT := string(bytes.TrimSpace(out))
57 cmd := exec.Command("go", "run", filepath.Join(GOROOT, "test", "run.go"), "-", ".")
58 out, err = cmd.CombinedOutput()
60 t.Fatalf("%s: %s\n%s", strings.Join(cmd.Args, " "), err, out)
62 t.Logf("%s:\n%s", strings.Join(cmd.Args, " "), out)