From e8c8b79f000515e086012df632f01fc0ec21076b Mon Sep 17 00:00:00 2001 From: Dmitri Shuralyov Date: Wed, 26 Apr 2023 16:41:41 -0400 Subject: cmd/api: remove unused functionality We no longer use the optional parameter to compareAPI. We now always set allowAdd to false. (Except in tests, making them less useful than they could be.) Flags and parsing their value are no more. Remove all the unused functionality and update test cases so they're closer to what the API checker does when it runs for real. Order the features, required, exception variables and fields more consistently. For #43956. Change-Id: Iaa4656a89a3fca3129742165a448d385e55e4a98 Reviewed-on: https://go-review.googlesource.com/c/go/+/489436 Auto-Submit: Dmitri Shuralyov Reviewed-by: Bryan Mills Run-TryBot: Dmitri Shuralyov Reviewed-by: Dmitri Shuralyov TryBot-Result: Gopher Robot --- src/cmd/api/api_test.go | 59 +++++++++++++++++++++++++++++++------------------ 1 file changed, 38 insertions(+), 21 deletions(-) (limited to 'src/cmd/api/api_test.go') diff --git a/src/cmd/api/api_test.go b/src/cmd/api/api_test.go index 5f9aa6d297..142cbb4339 100644 --- a/src/cmd/api/api_test.go +++ b/src/cmd/api/api_test.go @@ -115,16 +115,23 @@ 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 string + features, required, exception []string + ok bool // want + out string // want }{ + { + name: "equal", + features: []string{"A", "B", "C"}, + required: []string{"A", "B", "C"}, + ok: true, + out: "", + }, { name: "feature added", features: []string{"A", "B", "C", "D", "E", "F"}, required: []string{"B", "D"}, - ok: true, + ok: false, out: "+A\n+C\n+E\n+F\n", }, { @@ -134,42 +141,52 @@ func TestCompareAPI(t *testing.T) { 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"}, + required: []string{"A", "B", "C"}, exception: []string{"B"}, ok: true, out: "", }, + + // Test that a feature required on a subset of ports is implicitly satisfied + // by the same feature being implemented on all ports. That is, it shouldn't + // say "pkg syscall (darwin-amd64), type RawSockaddrInet6 struct" is missing. + // See https://go.dev/issue/4303. { - // https://golang.org/issue/4303 - name: "contexts reconverging", + name: "contexts reconverging after api/next/* update", + features: []string{ + "A", + "pkg syscall, type RawSockaddrInet6 struct", + }, required: []string{ "A", - "pkg syscall (darwin-amd64), type RawSockaddrInet6 struct", + "pkg syscall (darwin-amd64), type RawSockaddrInet6 struct", // api/go1.n.txt + "pkg syscall, type RawSockaddrInet6 struct", // api/next/n.txt }, + ok: true, + out: "", + }, + { + name: "contexts reconverging before api/next/* update", features: []string{ "A", "pkg syscall, type RawSockaddrInet6 struct", }, - ok: true, + required: []string{ + "A", + "pkg syscall (darwin-amd64), type RawSockaddrInet6 struct", + }, + ok: false, out: "+pkg syscall, type RawSockaddrInet6 struct\n", }, } for _, tt := range tests { buf := new(strings.Builder) - 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) + gotOK := compareAPI(buf, tt.features, tt.required, 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) -- cgit v1.3