diff options
| author | Bryan C. Mills <bcmills@google.com> | 2023-08-24 13:16:48 -0400 |
|---|---|---|
| committer | Gopher Robot <gobot@golang.org> | 2023-08-24 17:52:48 +0000 |
| commit | 5374c1aaf53a2212ca6a27eedc936fa917c5d077 (patch) | |
| tree | 9f6b256cb93dd040f289d9bf5588cb67ffa5dc3e /src | |
| parent | 65c133506f42c3e4180c0444970b224228244afc (diff) | |
| download | go-5374c1aaf53a2212ca6a27eedc936fa917c5d077.tar.xz | |
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>
Diffstat (limited to 'src')
| -rw-r--r-- | src/cmd/internal/testdir/testdir_test.go | 20 |
1 files changed, 12 insertions, 8 deletions
diff --git a/src/cmd/internal/testdir/testdir_test.go b/src/cmd/internal/testdir/testdir_test.go index bd7785900c..92c8f4c093 100644 --- a/src/cmd/internal/testdir/testdir_test.go +++ b/src/cmd/internal/testdir/testdir_test.go @@ -477,16 +477,20 @@ func (t test) run() error { } src := string(srcBytes) - // Execution recipe stops at first blank line. - action, _, ok := strings.Cut(src, "\n\n") - if !ok { - t.Fatalf("double newline ending execution recipe not found in GOROOT/test/%s", t.goFileName()) + // Execution recipe is contained in a comment in + // the first non-empty line that is not a build constraint. + var action string + for actionSrc := src; action == "" && actionSrc != ""; { + var line string + line, actionSrc, _ = strings.Cut(actionSrc, "\n") + if constraint.IsGoBuild(line) || constraint.IsPlusBuild(line) { + continue + } + action = strings.TrimSpace(strings.TrimPrefix(line, "//")) } - if firstLine, rest, ok := strings.Cut(action, "\n"); ok && strings.Contains(firstLine, "+build") { - // 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. header, _, ok := strings.Cut(src, "\npackage") |
