aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorMatthew Dempsky <mdempsky@google.com>2022-04-11 17:35:24 -0700
committerGopher Robot <gobot@golang.org>2022-04-12 05:46:57 +0000
commit2b31abc5286e4f29f934c4123101feabf0f4aaca (patch)
tree008b687dfe21b9201bcbf5dc24fcdf667a3f5c4b /test
parentf2d9ab263b8c62a81d314feb1e7a7fb424bb9c43 (diff)
downloadgo-2b31abc5286e4f29f934c4123101feabf0f4aaca.tar.gz
go-2b31abc5286e4f29f934c4123101feabf0f4aaca.zip
test: add //go:build support to run.go
gofmt is rewriting +build comments into //go:build anyway, so update the test script to support both. Change-Id: Ia6d950cfaa2fca9f184b8b2d3625a551bff88dde Reviewed-on: https://go-review.googlesource.com/c/go/+/399794 Run-TryBot: Matthew Dempsky <mdempsky@google.com> Auto-Submit: Matthew Dempsky <mdempsky@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@google.com>
Diffstat (limited to 'test')
-rw-r--r--test/run.go51
1 files changed, 13 insertions, 38 deletions
diff --git a/test/run.go b/test/run.go
index 468379b4a98..45cd086fc43 100644
--- a/test/run.go
+++ b/test/run.go
@@ -14,6 +14,7 @@ import (
"flag"
"fmt"
"go/build"
+ "go/build/constraint"
"hash/fnv"
"io"
"io/fs"
@@ -462,40 +463,24 @@ func shouldTest(src string, goos, goarch string) (ok bool, whyNot string) {
return true, ""
}
for _, line := range strings.Split(src, "\n") {
- line = strings.TrimSpace(line)
- if strings.HasPrefix(line, "//") {
- line = line[2:]
- } else {
- continue
- }
- line = strings.TrimSpace(line)
- if len(line) == 0 || line[0] != '+' {
- continue
+ if strings.HasPrefix(line, "package ") {
+ break
}
- gcFlags := os.Getenv("GO_GCFLAGS")
- ctxt := &context{
- GOOS: goos,
- GOARCH: goarch,
- cgoEnabled: cgoEnabled,
- noOptEnv: strings.Contains(gcFlags, "-N") || strings.Contains(gcFlags, "-l"),
- }
-
- words := strings.Fields(line)
- if words[0] == "+build" {
- ok := false
- for _, word := range words[1:] {
- if ctxt.match(word) {
- ok = true
- break
- }
+
+ if expr, err := constraint.Parse(line); err == nil {
+ gcFlags := os.Getenv("GO_GCFLAGS")
+ ctxt := &context{
+ GOOS: goos,
+ GOARCH: goarch,
+ cgoEnabled: cgoEnabled,
+ noOptEnv: strings.Contains(gcFlags, "-N") || strings.Contains(gcFlags, "-l"),
}
- if !ok {
- // no matching tag found.
+
+ if !expr.Eval(ctxt.match) {
return false, line
}
}
}
- // no build tags
return true, ""
}
@@ -503,16 +488,6 @@ func (ctxt *context) match(name string) bool {
if name == "" {
return false
}
- if first, rest, ok := strings.Cut(name, ","); ok {
- // comma-separated list
- return ctxt.match(first) && ctxt.match(rest)
- }
- if strings.HasPrefix(name, "!!") { // bad syntax, reject always
- return false
- }
- if strings.HasPrefix(name, "!") { // negation
- return len(name) > 1 && !ctxt.match(name[1:])
- }
// Tags must be letters, digits, underscores or dots.
// Unlike in Go identifiers, all digits are fine (e.g., "386").