mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
misc/cgo/stdio: fix tests in module mode
Updates #30228 Change-Id: I4d213c6fe68c47ccb877f13b55128e035f76a26b Reviewed-on: https://go-review.googlesource.com/c/163421 Run-TryBot: Bryan C. Mills <bcmills@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
This commit is contained in:
parent
eb2d1cdd1b
commit
c6611b2f7e
12 changed files with 145 additions and 4 deletions
60
misc/cgo/stdio/stdio_test.go
Normal file
60
misc/cgo/stdio/stdio_test.go
Normal file
|
|
@ -0,0 +1,60 @@
|
|||
// 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 stdio_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("", "cgostdio")
|
||||
if err != nil {
|
||||
log.Panic(err)
|
||||
}
|
||||
defer os.RemoveAll(GOPATH)
|
||||
os.Setenv("GOPATH", GOPATH)
|
||||
|
||||
// Copy testdata into GOPATH/src/cgostdio, along with a go.mod file
|
||||
// declaring the same path.
|
||||
modRoot := filepath.Join(GOPATH, "src", "cgostdio")
|
||||
if err := overlayDir(modRoot, "testdata"); err != nil {
|
||||
log.Panic(err)
|
||||
}
|
||||
if err := os.Chdir(modRoot); err != nil {
|
||||
log.Panic(err)
|
||||
}
|
||||
if err := ioutil.WriteFile("go.mod", []byte("module cgostdio\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)
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue