]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/api: make the test more robust
authorShenghou Ma <minux@golang.org>
Wed, 8 Apr 2015 08:27:58 +0000 (04:27 -0400)
committerMinux Ma <minux@golang.org>
Wed, 8 Apr 2015 08:46:42 +0000 (08:46 +0000)
Previously, the TestCompareAPI test would fail if runtime.Version()
is "dev", or, more importantly, "go1.5"; because compareAPI depends
on runtime.Version and -allow_new flag. Move that logic out make
its test more robust.

Change-Id: I8f40daa1838b8acd26adac8848762d95315053b0
Reviewed-on: https://go-review.googlesource.com/8622
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
src/cmd/api/goapi.go
src/cmd/api/goapi_test.go

index c42416db9e9f28de15aa5f39c7fad2ccdbd1d341..7b2c643e11756411873ae22f4bb107ef65c3b1da 100644 (file)
@@ -202,7 +202,8 @@ func main() {
        }
        optional := fileFeatures(*nextFile)
        exception := fileFeatures(*exceptFile)
-       fail = !compareAPI(bw, features, required, optional, exception)
+       fail = !compareAPI(bw, features, required, optional, exception,
+               *allowNew && strings.Contains(runtime.Version(), "devel"))
 }
 
 // export emits the exported package features.
@@ -238,7 +239,7 @@ func featureWithoutContext(f string) string {
        return spaceParensRx.ReplaceAllString(f, "")
 }
 
-func compareAPI(w io.Writer, features, required, optional, exception []string) (ok bool) {
+func compareAPI(w io.Writer, features, required, optional, exception []string, allowAdd bool) (ok bool) {
        ok = true
 
        optionalSet := set(optional)
@@ -280,7 +281,7 @@ func compareAPI(w io.Writer, features, required, optional, exception []string) (
                                delete(optionalSet, newFeature)
                        } else {
                                fmt.Fprintf(w, "+%s\n", newFeature)
-                               if !*allowNew || !strings.Contains(runtime.Version(), "devel") {
+                               if !allowAdd {
                                        ok = false // we're in lock-down mode for next release
                                }
                        }
index 9f5b0c8bb4cc3695a67dc1cf7d6e1dd25364c28f..00c45c3bcdefde8e4fee3984bff23f8cdc50cd15 100644 (file)
@@ -131,7 +131,7 @@ func TestCompareAPI(t *testing.T) {
        }
        for _, tt := range tests {
                buf := new(bytes.Buffer)
-               gotok := compareAPI(buf, tt.features, tt.required, tt.optional, tt.exception)
+               gotok := compareAPI(buf, tt.features, tt.required, tt.optional, tt.exception, true)
                if gotok != tt.ok {
                        t.Errorf("%s: ok = %v; want %v", tt.name, gotok, tt.ok)
                }