summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorR?my Oudompheng <oudomphe@phare.normalesup.org>2013-01-28 21:29:45 +0100
committerR?my Oudompheng <oudomphe@phare.normalesup.org>2013-01-28 21:29:45 +0100
commit7ef6780a1d45f7ba4fb61c81ef847c2a3d2e5ac3 (patch)
tree423ce47216f2d876555075ede1426da8b2bd84f5 /test
parent2c2848f5dce77b7a6586a336f216b8fcc2f2a509 (diff)
downloadgo-7ef6780a1d45f7ba4fb61c81ef847c2a3d2e5ac3.tar.gz
test: add support for build tags.
This enables a few tests that were only executed unconditionnally. R=rsc, minux.ma, bradfitz CC=golang-dev https://codereview.appspot.com/7103051
Diffstat (limited to 'test')
-rw-r--r--test/fixedbugs/bug385_32.go8
-rw-r--r--test/fixedbugs/bug385_64.go6
-rw-r--r--test/run.go89
-rw-r--r--test/sigchld.go7
-rw-r--r--test/testlib25
5 files changed, 110 insertions, 25 deletions
diff --git a/test/fixedbugs/bug385_32.go b/test/fixedbugs/bug385_32.go
index 5ac4136e7..724ed9326 100644
--- a/test/fixedbugs/bug385_32.go
+++ b/test/fixedbugs/bug385_32.go
@@ -1,7 +1,5 @@
-// [ $A == 6 ] || errchk $G -e $D/$F.go
-
-// NOTE: This test is not run by 'run.go' and so not run by all.bash.
-// To run this test you must use the ./run shell script.
+// +build 386 arm
+// errorcheck
// Copyright 2011 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
@@ -14,4 +12,4 @@ func main() {
var arr [1000200030]int // ERROR "type .* too large"
arr_bkup := arr
_ = arr_bkup
-} \ No newline at end of file
+}
diff --git a/test/fixedbugs/bug385_64.go b/test/fixedbugs/bug385_64.go
index f8ccb42a9..b5621b210 100644
--- a/test/fixedbugs/bug385_64.go
+++ b/test/fixedbugs/bug385_64.go
@@ -1,7 +1,5 @@
-// [ $A != 6 ] || errchk $G -e $D/$F.go
-
-// NOTE: This test is not run by 'run.go' and so not run by all.bash.
-// To run this test you must use the ./run shell script.
+// +build amd64
+// errorcheck
// Copyright 2011 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
diff --git a/test/run.go b/test/run.go
index fb528fa4c..bc545df10 100644
--- a/test/run.go
+++ b/test/run.go
@@ -299,6 +299,50 @@ func goDirPackages(longdir string) ([][]string, error) {
return pkgs, nil
}
+// 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]
+ }
+ notgoos := "!" + goos
+ notgoarch := "!" + goarch
+ 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
+ }
+ words := strings.Fields(line)
+ if words[0] == "+build" {
+ for _, word := range words {
+ switch word {
+ case goos, goarch:
+ return true, ""
+ case notgoos, notgoarch:
+ continue
+ default:
+ if word[0] == '!' {
+ // NOT something-else
+ return true, ""
+ }
+ }
+ }
+ // no matching tag found.
+ return false, line
+ }
+ }
+ // no build tags.
+ return true, ""
+}
+
+func init() { checkShouldTest() }
+
// run runs a test.
func (t *test) run() {
defer close(t.donec)
@@ -318,7 +362,18 @@ func (t *test) run() {
t.err = errors.New("double newline not found")
return
}
+ if ok, why := shouldTest(t.src, runtime.GOOS, runtime.GOARCH); !ok {
+ t.action = "skip"
+ if *showSkips {
+ fmt.Printf("%-20s %-20s: %s\n", t.action, t.goFileName(), why)
+ }
+ return
+ }
action := t.src[:pos]
+ if nl := strings.Index(action, "\n"); nl >= 0 && strings.Contains(action[:nl], "+build") {
+ // skip first line
+ action = action[nl+1:]
+ }
if strings.HasPrefix(action, "//") {
action = action[2:]
}
@@ -732,17 +787,14 @@ func (t *test) wantedErrors(file, short string) (errs []wantedError) {
}
var skipOkay = map[string]bool{
- "linkx.go": true,
- "sigchld.go": true,
- "sinit.go": true,
- "fixedbugs/bug248.go": true, // combines errorcheckdir and rundir in the same dir.
- "fixedbugs/bug302.go": true, // tests both .$O and .a imports.
- "fixedbugs/bug345.go": true, // needs the appropriate flags in gc invocation.
- "fixedbugs/bug369.go": true, // needs compiler flags.
- "fixedbugs/bug385_32.go": true, // arch-specific errors.
- "fixedbugs/bug385_64.go": true, // arch-specific errors.
- "fixedbugs/bug429.go": true,
- "bugs/bug395.go": true,
+ "linkx.go": true, // like "run" but wants linker flags
+ "sinit.go": true,
+ "fixedbugs/bug248.go": true, // combines errorcheckdir and rundir in the same dir.
+ "fixedbugs/bug302.go": true, // tests both .$O and .a imports.
+ "fixedbugs/bug345.go": true, // needs the appropriate flags in gc invocation.
+ "fixedbugs/bug369.go": true, // needs compiler flags.
+ "fixedbugs/bug429.go": true, // like "run" but program should fail
+ "bugs/bug395.go": true,
}
// defaultRunOutputLimit returns the number of runoutput tests that
@@ -756,3 +808,18 @@ func defaultRunOutputLimit() int {
}
return cpu
}
+
+// checkShouldTest runs canity checks on the shouldTest function.
+func checkShouldTest() {
+ assert := func(ok bool, _ string) {
+ if !ok {
+ panic("fail")
+ }
+ }
+ assertNot := func(ok bool, _ string) { assert(!ok, "") }
+ assert(shouldTest("// +build linux", "linux", "arm"))
+ assert(shouldTest("// +build !windows", "linux", "arm"))
+ assertNot(shouldTest("// +build !windows", "windows", "amd64"))
+ assertNot(shouldTest("// +build arm 386", "linux", "amd64"))
+ assert(shouldTest("// This is a test.", "os", "arch"))
+}
diff --git a/test/sigchld.go b/test/sigchld.go
index c1cfc2a8d..a60d28dea 100644
--- a/test/sigchld.go
+++ b/test/sigchld.go
@@ -1,8 +1,5 @@
-// [ "$GOOS" == windows ] ||
-// ($G $D/$F.go && $L $F.$A && ./$A.out 2>&1 | cmp - $D/$F.out)
-
-// NOTE: This test is not run by 'run.go' and so not run by all.bash.
-// To run this test you must use the ./run shell script.
+// +build !windows
+// cmpout
// Copyright 2009 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
diff --git a/test/testlib b/test/testlib
index b58e8831c..de138b1d1 100644
--- a/test/testlib
+++ b/test/testlib
@@ -16,6 +16,31 @@ pkgs() {
done | sort
}
+# +build aborts execution if the supplied tags don't match,
+# i.e. none of the tags (x or !x) matches GOARCH or GOOS.
++build() {
+ if (( $# == 0 )); then
+ return
+ fi
+ for tag; do
+ case $tag in
+ $GOARCH|$GOOS)
+ #echo >&2 "match $tag in $1"
+ return # don't exclude.
+ ;;
+ '!'$GOARCH|'!'$GOOS)
+ ;;
+ '!'*)
+ # not x where x is neither GOOS nor GOARCH.
+ #echo >&2 "match $tag in $1"
+ return # don't exclude
+ ;;
+ esac
+ done
+ # no match.
+ exit 0
+}
+
compile() {
$G $D/$F.go
}