]> Cypherpunks repositories - gostls13.git/commitdiff
os, syscall: don't consider stderr output as part of hostname
authorDmitri Shuralyov <dmitshur@golang.org>
Mon, 9 May 2022 03:04:28 +0000 (23:04 -0400)
committerGopher Robot <gobot@golang.org>
Mon, 9 May 2022 18:06:51 +0000 (18:06 +0000)
A successful invocation of the hostname command prints the hostname
to stdout and exits with code 0. No part of the hostname is printed
to stderr, so don't consider it.

This avoids false positive failures in environments where hostname
prints some extraneous information (such as performance warnings)
to stderr, and makes the test a bit more robust.

Fixes #52781.

Change-Id: I46aa6fbf95b6616bacf9c2b5e412b0851b230744
Reviewed-on: https://go-review.googlesource.com/c/go/+/405014
Auto-Submit: Dmitri Shuralyov <dmitshur@golang.org>
Run-TryBot: Dmitri Shuralyov <dmitshur@golang.org>
Reviewed-by: Bryan Mills <bcmills@google.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
Reviewed-by: Jason Donenfeld <Jason@zx2c4.com>
TryBot-Result: Gopher Robot <gobot@golang.org>

src/os/os_test.go
src/syscall/syscall_windows_test.go

index df00f165daeca0b7059855708690e17e1d03d2c8..8e2b4f3aaa82626e9242d6b4b6dacbd30246d6fe 100644 (file)
@@ -1736,7 +1736,7 @@ func runBinHostname(t *testing.T) string {
 
 func testWindowsHostname(t *testing.T, hostname string) {
        cmd := osexec.Command("hostname")
-       out, err := cmd.CombinedOutput()
+       out, err := cmd.Output()
        if err != nil {
                t.Fatalf("Failed to execute hostname command: %v %s", err, out)
        }
index 194c87805cdd750c1d60b21b4ee623e6aa1bb270..87f6580bdc553b903a3b24c761d4e57680ec006c 100644 (file)
@@ -130,7 +130,7 @@ int main(int argc, char *argv[])
        if err != nil {
                t.Fatalf("failed to build c executable: %s\n%s", err, out)
        }
-       out, err = exec.Command(exe).CombinedOutput()
+       out, err = exec.Command(exe).Output()
        if err != nil {
                t.Fatalf("c program execution failed: %v: %v", err, string(out))
        }