mirror of
https://github.com/golang/go
synced 2024-11-05 15:56:12 -07:00
apidiff: represent a Report as a list of Changes
Modify the Report representation to be a list of Change values, instead of two string slices. This will enable adding more information to each change, like source location. Change-Id: Ia7389d7bc552479ea5e06efd7fdefe004058e66f Reviewed-on: https://go-review.googlesource.com/c/tools/+/172777 Run-TryBot: Jay Conrod <jayconrod@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Jay Conrod <jayconrod@google.com>
This commit is contained in:
parent
c6b416e8a4
commit
fe54fb3517
@ -24,10 +24,14 @@ import (
|
|||||||
func Changes(old, new *types.Package) Report {
|
func Changes(old, new *types.Package) Report {
|
||||||
d := newDiffer(old, new)
|
d := newDiffer(old, new)
|
||||||
d.checkPackage()
|
d.checkPackage()
|
||||||
return Report{
|
r := Report{}
|
||||||
Incompatible: d.incompatibles.collect(),
|
for _, m := range d.incompatibles.collect() {
|
||||||
Compatible: d.compatibles.collect(),
|
r.Changes = append(r.Changes, Change{Message: m, Compatible: false})
|
||||||
}
|
}
|
||||||
|
for _, m := range d.compatibles.collect() {
|
||||||
|
r.Changes = append(r.Changes, Change{Message: m, Compatible: true})
|
||||||
|
}
|
||||||
|
return r
|
||||||
}
|
}
|
||||||
|
|
||||||
type differ struct {
|
type differ struct {
|
||||||
|
@ -37,11 +37,13 @@ func TestChanges(t *testing.T) {
|
|||||||
|
|
||||||
report := Changes(oldpkg.Types, newpkg.Types)
|
report := Changes(oldpkg.Types, newpkg.Types)
|
||||||
|
|
||||||
if !reflect.DeepEqual(report.Incompatible, wanti) {
|
got := report.messages(false)
|
||||||
t.Errorf("incompatibles: got %v\nwant %v\n", report.Incompatible, wanti)
|
if !reflect.DeepEqual(got, wanti) {
|
||||||
|
t.Errorf("incompatibles: got %v\nwant %v\n", got, wanti)
|
||||||
}
|
}
|
||||||
if !reflect.DeepEqual(report.Compatible, wantc) {
|
got = report.messages(true)
|
||||||
t.Errorf("compatibles: got %v\nwant %v\n", report.Compatible, wantc)
|
if !reflect.DeepEqual(got, wantc) {
|
||||||
|
t.Errorf("compatibles: got %v\nwant %v\n", got, wantc)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -8,7 +8,23 @@ import (
|
|||||||
|
|
||||||
// Report describes the changes detected by Changes.
|
// Report describes the changes detected by Changes.
|
||||||
type Report struct {
|
type Report struct {
|
||||||
Incompatible, Compatible []string
|
Changes []Change
|
||||||
|
}
|
||||||
|
|
||||||
|
// A Change describes a single API change.
|
||||||
|
type Change struct {
|
||||||
|
Message string
|
||||||
|
Compatible bool
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r Report) messages(compatible bool) []string {
|
||||||
|
var msgs []string
|
||||||
|
for _, c := range r.Changes {
|
||||||
|
if c.Compatible == compatible {
|
||||||
|
msgs = append(msgs, c.Message)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return msgs
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r Report) String() string {
|
func (r Report) String() string {
|
||||||
@ -28,13 +44,13 @@ func (r Report) Text(w io.Writer) error {
|
|||||||
|
|
||||||
func (r Report) TextIncompatible(w io.Writer, withHeader bool) error {
|
func (r Report) TextIncompatible(w io.Writer, withHeader bool) error {
|
||||||
if withHeader {
|
if withHeader {
|
||||||
return r.writeMessages(w, "Incompatible changes:", r.Incompatible)
|
return r.writeMessages(w, "Incompatible changes:", r.messages(false))
|
||||||
}
|
}
|
||||||
return r.writeMessages(w, "", r.Incompatible)
|
return r.writeMessages(w, "", r.messages(false))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r Report) TextCompatible(w io.Writer) error {
|
func (r Report) TextCompatible(w io.Writer) error {
|
||||||
return r.writeMessages(w, "Compatible changes:", r.Compatible)
|
return r.writeMessages(w, "Compatible changes:", r.messages(true))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r Report) writeMessages(w io.Writer, header string, msgs []string) error {
|
func (r Report) writeMessages(w io.Writer, header string, msgs []string) error {
|
||||||
|
Loading…
Reference in New Issue
Block a user