summaryrefslogtreecommitdiffstats
path: root/misc/cgo/stdio/stdio_test.go
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-28 13:18:25 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-28 13:18:25 +0000
commit109be507377fe7f6e8819ac94041d3fdcdf6fd2f (patch)
tree2806a689f8fab4a2ec9fc949830ef270a91d667d /misc/cgo/stdio/stdio_test.go
parentInitial commit. (diff)
downloadgolang-1.19-109be507377fe7f6e8819ac94041d3fdcdf6fd2f.tar.xz
golang-1.19-109be507377fe7f6e8819ac94041d3fdcdf6fd2f.zip
Adding upstream version 1.19.8.upstream/1.19.8upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'misc/cgo/stdio/stdio_test.go')
-rw-r--r--misc/cgo/stdio/stdio_test.go63
1 files changed, 63 insertions, 0 deletions
diff --git a/misc/cgo/stdio/stdio_test.go b/misc/cgo/stdio/stdio_test.go
new file mode 100644
index 0000000..675418f
--- /dev/null
+++ b/misc/cgo/stdio/stdio_test.go
@@ -0,0 +1,63 @@
+// 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"
+ "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 := os.MkdirTemp("", "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)
+ }
+ os.Setenv("PWD", modRoot)
+ if err := os.WriteFile("go.mod", []byte("module cgostdio\n"), 0666); err != nil {
+ log.Panic(err)
+ }
+
+ return m.Run()
+}
+
+func TestTestRun(t *testing.T) {
+ if os.Getenv("GOOS") == "android" {
+ t.Skip("subpackage stdio is not available on android")
+ }
+ 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)
+}