From 860c2557ab7995e64e5cc0f045ff676f1fcec0a0 Mon Sep 17 00:00:00 2001 From: Cuong Manh Le Date: Wed, 18 Oct 2023 00:26:42 +0700 Subject: [PATCH] cmd/internal/testdir: accept build go1.x build tag While at it, also using "slices" package to simplify code. For #63489 Change-Id: I72b325f6ad379b996c108145885fa71706f6659f Reviewed-on: https://go-review.googlesource.com/c/go/+/536055 Reviewed-by: Ian Lance Taylor Auto-Submit: Cuong Manh Le Reviewed-by: Matthew Dempsky LUCI-TryBot-Result: Go LUCI --- src/cmd/internal/testdir/testdir_test.go | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/cmd/internal/testdir/testdir_test.go b/src/cmd/internal/testdir/testdir_test.go index 92c8f4c093..1b91dbe3ce 100644 --- a/src/cmd/internal/testdir/testdir_test.go +++ b/src/cmd/internal/testdir/testdir_test.go @@ -24,6 +24,7 @@ import ( "path/filepath" "regexp" "runtime" + "slices" "sort" "strconv" "strings" @@ -417,13 +418,12 @@ func (ctxt *context) match(name string) bool { } } + if slices.Contains(build.Default.ReleaseTags, name) { + return true + } + if strings.HasPrefix(name, "goexperiment.") { - for _, tag := range build.Default.ToolTags { - if tag == name { - return true - } - } - return false + return slices.Contains(build.Default.ToolTags, name) } if name == "cgo" && ctxt.cgoEnabled { @@ -1751,6 +1751,9 @@ func TestShouldTest(t *testing.T) { // Test that (!a OR !b) matches anything. assert(shouldTest("// +build !windows !plan9", "windows", "amd64")) + + // Test that //go:build tag match. + assert(shouldTest("//go:build go1.4", "linux", "amd64")) } // overlayDir makes a minimal-overhead copy of srcRoot in which new files may be added. -- 2.50.0