aboutsummaryrefslogtreecommitdiff
path: root/src/debug
diff options
context:
space:
mode:
authorJay Conrod <jayconrod@google.com>2021-10-14 14:57:49 -0700
committerJay Conrod <jayconrod@google.com>2021-10-14 23:32:09 +0000
commit9e8ed86813dd49c4160dd4813901e2ac03de5abd (patch)
tree5df12c4e96ec212ac7f3432d936b485bbcf899b1 /src/debug
parentb59467e0365776761c3787a4d541b5e74fe24b24 (diff)
downloadgo-9e8ed86813dd49c4160dd4813901e2ac03de5abd.tar.xz
debug/buildinfo: fix test for build settings
This CL fixes the debug/buildinfo test, which did not expect build settings. For #37475 Change-Id: Ie8c15ec633b4eec6a976120c8db64f116589d98e Reviewed-on: https://go-review.googlesource.com/c/go/+/356012 Trust: Jay Conrod <jayconrod@google.com> Run-TryBot: Jay Conrod <jayconrod@google.com> Reviewed-by: Bryan C. Mills <bcmills@google.com>
Diffstat (limited to 'src/debug')
-rw-r--r--src/debug/buildinfo/buildinfo_test.go28
1 files changed, 23 insertions, 5 deletions
diff --git a/src/debug/buildinfo/buildinfo_test.go b/src/debug/buildinfo/buildinfo_test.go
index ab307d75c2..44d78a6be0 100644
--- a/src/debug/buildinfo/buildinfo_test.go
+++ b/src/debug/buildinfo/buildinfo_test.go
@@ -13,6 +13,7 @@ import (
"os/exec"
"path"
"path/filepath"
+ "regexp"
"runtime"
"strings"
"testing"
@@ -114,6 +115,23 @@ func TestReadFile(t *testing.T) {
}
}
+ goVersionRe := regexp.MustCompile("(?m)^go\t.*\n")
+ buildRe := regexp.MustCompile("(?m)^build\t.*\n")
+ cleanOutputForComparison := func(got string) string {
+ // Remove or replace anything that might depend on the test's environment
+ // so we can check the output afterward with a string comparison.
+ // We'll remove all build lines except the compiler, just to make sure
+ // build lines are included.
+ got = goVersionRe.ReplaceAllString(got, "go\tGOVERSION\n")
+ got = buildRe.ReplaceAllStringFunc(got, func(match string) string {
+ if strings.HasPrefix(match, "build\tcompiler\t") {
+ return match
+ }
+ return ""
+ })
+ return got
+ }
+
cases := []struct {
name string
build func(t *testing.T, goos, goarch string) string
@@ -142,9 +160,10 @@ func TestReadFile(t *testing.T) {
{
name: "valid_modules",
build: buildWithModules,
- want: "go\t$GOVERSION\n" +
+ want: "go\tGOVERSION\n" +
"path\texample.com/m\n" +
- "mod\texample.com/m\t(devel)\t\n",
+ "mod\texample.com/m\t(devel)\t\n" +
+ "build\tcompiler\tgc\n",
},
{
name: "invalid_modules",
@@ -158,7 +177,7 @@ func TestReadFile(t *testing.T) {
{
name: "valid_gopath",
build: buildWithGOPATH,
- want: "go\t$GOVERSION\n",
+ want: "go\tGOVERSION\n",
},
{
name: "invalid_gopath",
@@ -193,8 +212,7 @@ func TestReadFile(t *testing.T) {
t.Fatalf("unexpected success; want error containing %q", tc.wantErr)
} else if got, err := info.MarshalText(); err != nil {
t.Fatalf("unexpected error marshaling BuildInfo: %v", err)
- } else {
- got := strings.ReplaceAll(string(got), runtime.Version(), "$GOVERSION")
+ } else if got := cleanOutputForComparison(string(got)); got != tc.want {
if got != tc.want {
t.Fatalf("got:\n%s\nwant:\n%s", got, tc.want)
}