test: check for build constraints only upto the first blank line

The main issue is that the misc/cgo/{stdio,life} tests are silently
getting skipped when invoked from run.bash.

run.go should ignore any build tags after the first blank line in
source file. It already checks for test actions only upto the first
blank line. Build tags must be specified in the same block.

See http://golang.org/cl/3675 for background.

Change-Id: Id8abf000119e3335f7250d8ef34aac7811fc9dff
Reviewed-on: https://go-review.googlesource.com/3812
Reviewed-by: Minux Ma <minux@golang.org>
This commit is contained in:
Rahul Chaudhry 2015-02-03 10:52:18 -08:00 committed by Minux Ma
parent d81cc374be
commit 8581d48c15
3 changed files with 4 additions and 8 deletions

View file

@ -1,6 +1,5 @@
// run
// +build !nacl
// run
// Copyright 2011 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style

View file

@ -1,6 +1,5 @@
// run
// +build !nacl
// run
// Copyright 2014 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style

View file

@ -325,9 +325,6 @@ type context struct {
// shouldTest looks for build tags in a source file and returns
// whether the file should be used according to the tags.
func shouldTest(src string, goos, goarch string) (ok bool, whyNot string) {
if idx := strings.Index(src, "\npackage"); idx >= 0 {
src = src[:idx]
}
for _, line := range strings.Split(src, "\n") {
line = strings.TrimSpace(line)
if strings.HasPrefix(line, "//") {
@ -417,7 +414,8 @@ func (t *test) run() {
t.err = errors.New("double newline not found")
return
}
if ok, why := shouldTest(t.src, goos, goarch); !ok {
// Check for build constraints only upto the first blank line.
if ok, why := shouldTest(t.src[:pos], goos, goarch); !ok {
t.action = "skip"
if *showSkips {
fmt.Printf("%-20s %-20s: %s\n", t.action, t.goFileName(), why)