]> Cypherpunks.ru repositories - gostls13.git/commitdiff
test: add support for build tags.
authorRémy Oudompheng <oudomphe@phare.normalesup.org>
Mon, 28 Jan 2013 20:29:45 +0000 (21:29 +0100)
committerRémy Oudompheng <oudomphe@phare.normalesup.org>
Mon, 28 Jan 2013 20:29:45 +0000 (21:29 +0100)
This enables a few tests that were only executed
unconditionnally.

R=rsc, minux.ma, bradfitz
CC=golang-dev
https://golang.org/cl/7103051

test/fixedbugs/bug385_32.go
test/fixedbugs/bug385_64.go
test/run.go
test/sigchld.go
test/testlib

index 5ac4136e7dc56ade92039e23e24daa8019d46823..724ed932623aef4368a201737c2f48dd88fe9edc 100644 (file)
@@ -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
+}
index f8ccb42a9b60a96f6ff81d2202af0c01c95afe23..b5621b21036be611aff05e76b3404d0a6e8e2739 100644 (file)
@@ -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
index fb528fa4ce6f7ccb9739c3d4e80bf3e99cefd66f..bc545df10ba6534b48eed006ce6ffaca0f39c841 100644 (file)
@@ -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"))
+}
index c1cfc2a8d0cc98056650267091dcb879c4228d6b..a60d28deaab3b049ee5e7fb2adacab8d2ce09fb2 100644 (file)
@@ -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
index b58e8831c3dc8284d3edcbc0975260ad98a6ab6b..de138b1d19d2d60fadf1c00a2d5841716b079f2e 100644 (file)
@@ -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
 }