mirror of https://github.com/golang/go.git
cmd/internal/testdir: parse past gofmt'd //go:build lines
Also gofmt a test file to make sure the parser works. Fixes #62267. Change-Id: I9b9f12b06bae7df626231000879b5ed7df3cd9ba Reviewed-on: https://go-review.googlesource.com/c/go/+/522635 Reviewed-by: Ian Lance Taylor <iant@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Auto-Submit: Bryan Mills <bcmills@google.com> Run-TryBot: Bryan Mills <bcmills@google.com>
This commit is contained in:
parent
65c133506f
commit
5374c1aaf5
|
|
@ -477,16 +477,20 @@ func (t test) run() error {
|
||||||
}
|
}
|
||||||
src := string(srcBytes)
|
src := string(srcBytes)
|
||||||
|
|
||||||
// Execution recipe stops at first blank line.
|
// Execution recipe is contained in a comment in
|
||||||
action, _, ok := strings.Cut(src, "\n\n")
|
// the first non-empty line that is not a build constraint.
|
||||||
if !ok {
|
var action string
|
||||||
t.Fatalf("double newline ending execution recipe not found in GOROOT/test/%s", t.goFileName())
|
for actionSrc := src; action == "" && actionSrc != ""; {
|
||||||
|
var line string
|
||||||
|
line, actionSrc, _ = strings.Cut(actionSrc, "\n")
|
||||||
|
if constraint.IsGoBuild(line) || constraint.IsPlusBuild(line) {
|
||||||
|
continue
|
||||||
}
|
}
|
||||||
if firstLine, rest, ok := strings.Cut(action, "\n"); ok && strings.Contains(firstLine, "+build") {
|
action = strings.TrimSpace(strings.TrimPrefix(line, "//"))
|
||||||
// skip first line
|
}
|
||||||
action = rest
|
if action == "" {
|
||||||
|
t.Fatalf("execution recipe not found in GOROOT/test/%s", t.goFileName())
|
||||||
}
|
}
|
||||||
action = strings.TrimPrefix(action, "//")
|
|
||||||
|
|
||||||
// Check for build constraints only up to the actual code.
|
// Check for build constraints only up to the actual code.
|
||||||
header, _, ok := strings.Cut(src, "\npackage")
|
header, _, ok := strings.Cut(src, "\npackage")
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,6 @@
|
||||||
|
//go:build linux && !ppc64 && gc && cgo
|
||||||
// +build linux,!ppc64,gc,cgo
|
// +build linux,!ppc64,gc,cgo
|
||||||
|
|
||||||
// run
|
// run
|
||||||
|
|
||||||
// Copyright 2015 The Go Authors. All rights reserved.
|
// Copyright 2015 The Go Authors. All rights reserved.
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue