]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/cgo/internal/testfortran: relax test output
authorCuong Manh Le <cuong.manhle.vn@gmail.com>
Tue, 17 Oct 2023 13:50:30 +0000 (20:50 +0700)
committerGopher Robot <gobot@golang.org>
Wed, 18 Oct 2023 01:29:16 +0000 (01:29 +0000)
Some new linker may emit warning message to standard error, causing
false positive in test result.

Fixing this by testing only stdout output.

Fixes #63588

Change-Id: I272048c41dc1c316f44af2dfc903bb03383baea3
Reviewed-on: https://go-review.googlesource.com/c/go/+/535975
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Bryan Mills <bcmills@google.com>
Auto-Submit: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
src/cmd/cgo/internal/testfortran/fortran_test.go
src/cmd/cgo/internal/testfortran/testdata/testprog/fortran.go

index eaa36ac7f9b0e8e4071f7e7063c51b2057288881..0eae7c5f53d4aa1a78a6b834bd99fd078d4d89be 100644 (file)
@@ -5,7 +5,6 @@
 package fortran
 
 import (
-       "fmt"
        "internal/testenv"
        "os"
        "os/exec"
@@ -75,11 +74,18 @@ func TestFortran(t *testing.T) {
 
        // Finally, run the actual test.
        t.Log("go", "run", "./testdata/testprog")
-       out, err := exec.Command("go", "run", "./testdata/testprog").CombinedOutput()
-       if err == nil && string(out) != "ok\n" {
-               err = fmt.Errorf("expected ok")
+       var stdout, stderr strings.Builder
+       cmd := exec.Command("go", "run", "./testdata/testprog")
+       cmd.Stdout = &stdout
+       cmd.Stderr = &stderr
+       err := cmd.Run()
+       t.Logf("%v", cmd)
+       if stderr.Len() != 0 {
+               t.Logf("stderr:\n%s", stderr.String())
        }
        if err != nil {
-               t.Errorf("%s\nOutput:\n%s", err, string(out))
+               t.Errorf("%v\n%s", err, stdout.String())
+       } else if stdout.String() != "ok\n" {
+               t.Errorf("stdout:\n%s\nwant \"ok\"", stdout.String())
        }
 }
index d8004ceb6de9a6ada02f9ea6bbd4bc4af846b107..e98d76c3e602a8ffd1555d36eb6931c0f437ed24 100644 (file)
@@ -6,7 +6,10 @@ package main
 
 // int the_answer();
 import "C"
-import "os"
+import (
+       "fmt"
+       "os"
+)
 
 func TheAnswer() int {
        return int(C.the_answer())
@@ -14,8 +17,8 @@ func TheAnswer() int {
 
 func main() {
        if a := TheAnswer(); a != 42 {
-               println("Unexpected result for The Answer. Got:", a, " Want: 42")
+               fmt.Fprintln(os.Stderr, "Unexpected result for The Answer. Got:", a, " Want: 42")
                os.Exit(1)
        }
-       println("ok")
+       fmt.Fprintln(os.Stdout, "ok")
 }