Skip to content

Commit 6cdf8ea

Browse files
committed
Remove google/go-cmp
See google/go-cmp#174 In general its a very heavy library and I'm not convinced it offers enough.
1 parent 1e111e4 commit 6cdf8ea

File tree

6 files changed

+17
-71
lines changed

6 files changed

+17
-71
lines changed

Diff for: go.mod

-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ require (
66
cloud.google.com/go v0.43.0
77
github.com/alecthomas/chroma v0.6.6
88
github.com/fatih/color v1.7.0
9-
github.com/google/go-cmp v0.3.2-0.20190829225427-b1c9c4891a65
109
github.com/mattn/go-colorable v0.1.2 // indirect
1110
github.com/mattn/go-isatty v0.0.9 // indirect
1211
go.opencensus.io v0.22.1

Diff for: go.sum

-2
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,6 @@ github.com/google/btree v1.0.0/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ
4848
github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M=
4949
github.com/google/go-cmp v0.3.0 h1:crn/baboCvb5fXaQ0IJ1SGTsTVrWpDsCWC8EGETZijY=
5050
github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
51-
github.com/google/go-cmp v0.3.2-0.20190829225427-b1c9c4891a65 h1:B3yqxlLHBEoav+FDQM8ph7IIRA6AhQ70w119k3hoT2Y=
52-
github.com/google/go-cmp v0.3.2-0.20190829225427-b1c9c4891a65/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
5351
github.com/google/martian v2.1.0+incompatible h1:/CP5g8u/VJHijgedC/Legn3BAbAaWPgecwXBIDzw5no=
5452
github.com/google/martian v2.1.0+incompatible/go.mod h1:9I4somxYTbIHy5NJKHRl3wXiIaQGbYVAs8BPL6v8lEs=
5553
github.com/google/pprof v0.0.0-20181206194817-3ea8567a2e57/go.mod h1:zfwlbNMJ+OItoe0UupaVj+oy1omPYYDuagoSzA8v9mc=

Diff for: internal/assert/assert.go

+4-5
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,16 @@ import (
1010
// Equal asserts exp == act.
1111
func Equal(t testing.TB, exp, act interface{}, name string) {
1212
t.Helper()
13-
diff := CmpDiff(exp, act)
14-
if diff != "" {
15-
t.Fatalf("unexpected %v: %v", name, diff)
13+
if !reflect.DeepEqual(exp, act) {
14+
t.Fatalf("unexpected %v: exp: %q but got %q", name, exp, act)
1615
}
1716
}
1817

1918
// NotEqual asserts exp != act.
2019
func NotEqual(t testing.TB, exp, act interface{}, name string) {
2120
t.Helper()
22-
if CmpDiff(exp, act) == "" {
23-
t.Fatalf("expected different %v: %+v", name, act)
21+
if reflect.DeepEqual(exp, act) {
22+
t.Fatalf("expected different %v: %q", name, act)
2423
}
2524
}
2625

Diff for: internal/assert/cmp.go

-54
This file was deleted.

Diff for: sloggers/slogtest/assert/assert.go

+12-8
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ package assert // import "cdr.dev/slog/sloggers/slogtest/assert"
77

88
import (
99
"errors"
10+
"reflect"
1011
"testing"
1112

1213
"cdr.dev/slog"
13-
"cdr.dev/slog/internal/assert"
1414
"cdr.dev/slog/sloggers/slogtest"
1515
)
1616

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

26-
if err, ok := act.(error); ok {
27-
act = unwrapErr(err)
28-
}
26+
exp = unwrapErr(exp)
27+
act = unwrapErr(act)
2928

30-
if diff := assert.CmpDiff(exp, act); diff != "" {
29+
if !reflect.DeepEqual(exp, act) {
3130
slogtest.Fatal(t, "unexpected value",
3231
slog.F("name", name),
33-
slog.F("diff", diff),
32+
slog.F("exp", exp),
33+
slog.F("act", act),
3434
)
3535
}
3636
}
@@ -62,7 +62,11 @@ func Error(t testing.TB, err error, name string) {
6262
}
6363
}
6464

65-
func unwrapErr(err error) error {
65+
func unwrapErr(v interface{}) interface{} {
66+
err, ok := v.(error)
67+
if !ok {
68+
return v
69+
}
6670
uerr := errors.Unwrap(err)
6771
for uerr != nil {
6872
err = uerr

Diff for: sloggers/slogtest/assert/assert_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -91,5 +91,5 @@ func (tb *fakeTB) Error(v ...interface{}) {
9191

9292
func (tb *fakeTB) Fatal(v ...interface{}) {
9393
tb.fatals++
94-
panic("")
94+
panic(fmt.Sprint(v...))
9595
}

0 commit comments

Comments
 (0)