]> Cypherpunks repositories - gostls13.git/commitdiff
test,internal/testdir: don't set GOOS/GOARCH
authorAustin Clements <austin@google.com>
Mon, 8 May 2023 14:47:45 +0000 (10:47 -0400)
committerAustin Clements <austin@google.com>
Fri, 12 May 2023 12:34:59 +0000 (12:34 +0000)
The test directory driver currently sets the GOOS/GOARCH environment
variables if they aren't set. This appears to be in service of a
single test, test/env.go, which was introduced in September 2008 along
with os.Getenv. It's not entirely clear what that test is even trying
to check, since runtime.GOOS isn't necessarily the same as $GOOS. We
keep the test around because golang.org/x/tools/go/ssa/interp uses it
as a test case, but we simplify the test and eliminate the need for
the driver to set GOOS/GOARCH.

Change-Id: I5acc0093b557c95d1f0a526d031210256a68222d
Reviewed-on: https://go-review.googlesource.com/c/go/+/493601
Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Austin Clements <austin@google.com>
Reviewed-by: Bryan Mills <bcmills@google.com>
src/internal/testdir/testdir_test.go
test/env.go

index 864b0723849bc6fa37b776a37f787599b63005c8..8ad2353e9fcd844c039722699ec9c0ffbc0f6743 100644 (file)
@@ -571,14 +571,6 @@ func (t test) run() error {
                t.Fatal(err)
        }
 
-       // A few tests (of things like the environment) require these to be set.
-       if os.Getenv("GOOS") == "" {
-               os.Setenv("GOOS", runtime.GOOS)
-       }
-       if os.Getenv("GOARCH") == "" {
-               os.Setenv("GOARCH", runtime.GOARCH)
-       }
-
        var (
                runInDir        = tempDir
                tempDirIsGOPATH = false
index 972374679ac83d387bb97dfe3f0a714e14ba3830..1590f1e06bb1a83d0cfb7b5f137598d2d25db782 100644 (file)
@@ -4,8 +4,8 @@
 // Use of this source code is governed by a BSD-style
 // license that can be found in the LICENSE file.
 
-// Test that the Go environment variables are present and accessible through
-// package os and package runtime.
+// Test that environment variables are accessible through
+// package os.
 
 package main
 
@@ -15,9 +15,12 @@ import (
 )
 
 func main() {
-       ga := os.Getenv("GOARCH")
-       if ga != runtime.GOARCH {
-               print("$GOARCH=", ga, "!= runtime.GOARCH=", runtime.GOARCH, "\n")
+       ga := os.Getenv("PATH")
+       if runtime.GOOS == "plan9" {
+               ga = os.Getenv("path")
+       }
+       if ga == "" {
+               print("PATH is empty\n")
                os.Exit(1)
        }
        xxx := os.Getenv("DOES_NOT_EXIST")