cmd/cgo/internal/testfortran: relax test output

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>
This commit is contained in:
Cuong Manh Le 2023-10-17 20:50:30 +07:00 committed by Gopher Robot
parent 416bc85f61
commit fb726698b7
2 changed files with 17 additions and 8 deletions

View 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())
}
}

View 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")
}