aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/api/goapi_test.go
diff options
context:
space:
mode:
authorBrad Fitzpatrick <bradfitz@golang.org>2012-10-30 11:23:44 +0100
committerBrad Fitzpatrick <bradfitz@golang.org>2012-10-30 11:23:44 +0100
commite53a2c40b119509356edcffc1655331c9beb6df5 (patch)
tree3be19db6ac36b2b7c736c57fe2ea4b9186c82124 /src/cmd/api/goapi_test.go
parent1d61c9bb3e41947ab66732d0346b821d5062554c (diff)
downloadgo-e53a2c40b119509356edcffc1655331c9beb6df5.tar.xz
cmd/api: add more tests
Feature extraction was tested before, but not the final diffs. This CL breaks function main into a smaller main + testable compareAPI. No functional changes. R=golang-dev, adg CC=golang-dev https://golang.org/cl/6820057
Diffstat (limited to 'src/cmd/api/goapi_test.go')
-rw-r--r--src/cmd/api/goapi_test.go51
1 files changed, 51 insertions, 0 deletions
diff --git a/src/cmd/api/goapi_test.go b/src/cmd/api/goapi_test.go
index c7cc601b1a..b4fccdfd4e 100644
--- a/src/cmd/api/goapi_test.go
+++ b/src/cmd/api/goapi_test.go
@@ -5,6 +5,7 @@
package main
import (
+ "bytes"
"flag"
"fmt"
"io/ioutil"
@@ -73,3 +74,53 @@ func TestGolden(t *testing.T) {
}
}
}
+
+func TestCompareAPI(t *testing.T) {
+ tests := []struct {
+ name string
+ features, required, optional, exception []string
+ ok bool // want
+ out string // want
+ }{
+ {
+ name: "feature added",
+ features: []string{"C", "A", "B"},
+ required: []string{"A", "C"},
+ ok: true,
+ out: "+B\n",
+ },
+ {
+ name: "feature removed",
+ features: []string{"C", "A"},
+ required: []string{"A", "B", "C"},
+ ok: false,
+ out: "-B\n",
+ },
+ {
+ name: "feature added then removed",
+ features: []string{"A", "C"},
+ optional: []string{"B"},
+ required: []string{"A", "C"},
+ ok: true,
+ out: "±B\n",
+ },
+ {
+ name: "exception removal",
+ required: []string{"A", "B", "C"},
+ features: []string{"A", "C"},
+ exception: []string{"B"},
+ ok: true,
+ out: "~B\n",
+ },
+ }
+ for _, tt := range tests {
+ buf := new(bytes.Buffer)
+ gotok := compareAPI(buf, tt.features, tt.required, tt.optional, tt.exception)
+ if gotok != tt.ok {
+ t.Errorf("%s: ok = %v; want %v", tt.name, gotok, tt.ok)
+ }
+ if got := buf.String(); got != tt.out {
+ t.Errorf("%s: output differs\nGOT:\n%s\nWANT:\n%s", tt.name, got, tt.out)
+ }
+ }
+}