Skip to content

Commit

Permalink
Remove google/go-cmp
Browse files Browse the repository at this point in the history
See google/go-cmp#174

In general its a very heavy library and I'm not convinced
it offers enough.
  • Loading branch information
nhooyr committed Dec 14, 2019
1 parent 1e111e4 commit 6cdf8ea
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 71 deletions.
1 change: 0 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ require (
cloud.google.com/go v0.43.0
github.com/alecthomas/chroma v0.6.6
github.com/fatih/color v1.7.0
github.com/google/go-cmp v0.3.2-0.20190829225427-b1c9c4891a65
github.com/mattn/go-colorable v0.1.2 // indirect
github.com/mattn/go-isatty v0.0.9 // indirect
go.opencensus.io v0.22.1
Expand Down
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,6 @@ github.com/google/btree v1.0.0/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ
github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M=
github.com/google/go-cmp v0.3.0 h1:crn/baboCvb5fXaQ0IJ1SGTsTVrWpDsCWC8EGETZijY=
github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
github.com/google/go-cmp v0.3.2-0.20190829225427-b1c9c4891a65 h1:B3yqxlLHBEoav+FDQM8ph7IIRA6AhQ70w119k3hoT2Y=
github.com/google/go-cmp v0.3.2-0.20190829225427-b1c9c4891a65/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
github.com/google/martian v2.1.0+incompatible h1:/CP5g8u/VJHijgedC/Legn3BAbAaWPgecwXBIDzw5no=
github.com/google/martian v2.1.0+incompatible/go.mod h1:9I4somxYTbIHy5NJKHRl3wXiIaQGbYVAs8BPL6v8lEs=
github.com/google/pprof v0.0.0-20181206194817-3ea8567a2e57/go.mod h1:zfwlbNMJ+OItoe0UupaVj+oy1omPYYDuagoSzA8v9mc=
Expand Down
9 changes: 4 additions & 5 deletions internal/assert/assert.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,16 @@ import (
// Equal asserts exp == act.
func Equal(t testing.TB, exp, act interface{}, name string) {
t.Helper()
diff := CmpDiff(exp, act)
if diff != "" {
t.Fatalf("unexpected %v: %v", name, diff)
if !reflect.DeepEqual(exp, act) {
t.Fatalf("unexpected %v: exp: %q but got %q", name, exp, act)
}
}

// NotEqual asserts exp != act.
func NotEqual(t testing.TB, exp, act interface{}, name string) {
t.Helper()
if CmpDiff(exp, act) == "" {
t.Fatalf("expected different %v: %+v", name, act)
if reflect.DeepEqual(exp, act) {
t.Fatalf("expected different %v: %q", name, act)
}
}

Expand Down
54 changes: 0 additions & 54 deletions internal/assert/cmp.go

This file was deleted.

20 changes: 12 additions & 8 deletions sloggers/slogtest/assert/assert.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ package assert // import "cdr.dev/slog/sloggers/slogtest/assert"

import (
"errors"
"reflect"
"testing"

"cdr.dev/slog"
"cdr.dev/slog/internal/assert"
"cdr.dev/slog/sloggers/slogtest"
)

Expand All @@ -19,18 +19,18 @@ import (
// If they are not equal, it will fatal the test with a diff of the
// two objects.
//
// If act is an error it will be unwrapped.
// If act or exp is an error it will be unwrapped.
func Equal(t testing.TB, exp, act interface{}, name string) {
slog.Helper()

if err, ok := act.(error); ok {
act = unwrapErr(err)
}
exp = unwrapErr(exp)
act = unwrapErr(act)

if diff := assert.CmpDiff(exp, act); diff != "" {
if !reflect.DeepEqual(exp, act) {
slogtest.Fatal(t, "unexpected value",
slog.F("name", name),
slog.F("diff", diff),
slog.F("exp", exp),
slog.F("act", act),
)
}
}
Expand Down Expand Up @@ -62,7 +62,11 @@ func Error(t testing.TB, err error, name string) {
}
}

func unwrapErr(err error) error {
func unwrapErr(v interface{}) interface{} {
err, ok := v.(error)
if !ok {
return v
}
uerr := errors.Unwrap(err)
for uerr != nil {
err = uerr
Expand Down
2 changes: 1 addition & 1 deletion sloggers/slogtest/assert/assert_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,5 +91,5 @@ func (tb *fakeTB) Error(v ...interface{}) {

func (tb *fakeTB) Fatal(v ...interface{}) {
tb.fatals++
panic("")
panic(fmt.Sprint(v...))
}

0 comments on commit 6cdf8ea

Please sign in to comment.