From 56f7a1850d752d16ea4bcac0cd6d5e8cec96f0c3 Mon Sep 17 00:00:00 2001 From: Brandon Dyck Date: Mon, 9 Sep 2024 09:02:25 -0600 Subject: [PATCH] assertions: make Error helper output more consistent --- internal/assertions/assertions.go | 16 ++++++++-------- must/must_test.go | 10 +++++----- test_test.go | 10 +++++----- 3 files changed, 18 insertions(+), 18 deletions(-) diff --git a/internal/assertions/assertions.go b/internal/assertions/assertions.go index e6c5f8a..8adae00 100644 --- a/internal/assertions/assertions.go +++ b/internal/assertions/assertions.go @@ -130,14 +130,14 @@ func Unreachable() (s string) { func Error(err error) (s string) { if err == nil { - s = "expected non-nil error; is nil\n" + s = "expected non-nil error; got nil\n" } return } func EqError(err error, msg string) (s string) { if err == nil { - s = "expected error; got nil\n" + s = "expected non-nil error; got nil\n" return } e := err.Error() @@ -151,30 +151,30 @@ func EqError(err error, msg string) (s string) { func ErrorIs(err error, target error) (s string) { if err == nil { - s = "expected error; got nil\n" + s = "expected non-nil error; got nil\n" return } if !errors.Is(err, target) { s = "expected errors.Is match\n" - s += bullet(" error: %v\n", err) s += bullet("target: %v\n", target) + s += bullet(" got: %v\n", err) } return } func ErrorAs[E error, Target *E](err error, target Target) (s string) { if err == nil { - s = "expected error; got nil\n" + s = "expected non-nil error; got nil\n" return } if target == nil { - s = "expected target not to be nil" + s = "expected non-nil target; got nil\n" return } if !errors.As(err, target) { s = "expected errors.As match\n" - s += bullet(" error: %v\n", err) s += bullet("target: %v\n", target) + s += bullet(" got: %v\n", err) } return } @@ -189,7 +189,7 @@ func NoError(err error) (s string) { func ErrorContains(err error, sub string) (s string) { if err == nil { - s = "expected non-nil error\n" + s = "expected non-nil error; got nil\n" return } actual := err.Error() diff --git a/must/must_test.go b/must/must_test.go index 56aabb0..2fbfdbe 100644 --- a/must/must_test.go +++ b/must/must_test.go @@ -105,7 +105,7 @@ func TestUnreachable_PS(t *testing.T) { } func TestError(t *testing.T) { - tc := newCase(t, `expected non-nil error; is nil`) + tc := newCase(t, `expected non-nil error; got nil`) t.Cleanup(tc.assert) Error(tc, nil) @@ -133,7 +133,7 @@ func TestEqError_PS(t *testing.T) { } func TestEqError_nil(t *testing.T) { - tc := newCase(t, `expected error; got nil`) + tc := newCase(t, `expected non-nil error; got nil`) t.Cleanup(tc.assert) EqError(tc, nil, "blah") @@ -158,7 +158,7 @@ func TestErrorIs_PS(t *testing.T) { } func TestErrorIs_nil(t *testing.T) { - tc := newCase(t, `expected error; got nil`) + tc := newCase(t, `expected non-nil error; got nil`) t.Cleanup(tc.assert) err := errors.New("oops") @@ -181,7 +181,7 @@ func TestErrorAs(t *testing.T) { } func TestErrorAs_nilErr(t *testing.T) { - tc := newCase(t, `expected error; got nil`) + tc := newCase(t, `expected non-nil error; got nil`) t.Cleanup(tc.assert) var target FakeError @@ -189,7 +189,7 @@ func TestErrorAs_nilErr(t *testing.T) { } func TestErrorAs_nilTarget(t *testing.T) { - tc := newCase(t, `expected target not to be nil`) + tc := newCase(t, `expected non-nil target; got nil`) t.Cleanup(tc.assert) var target *FakeError diff --git a/test_test.go b/test_test.go index 0f76dcd..a9b8389 100644 --- a/test_test.go +++ b/test_test.go @@ -103,7 +103,7 @@ func TestUnreachable_PS(t *testing.T) { } func TestError(t *testing.T) { - tc := newCase(t, `expected non-nil error; is nil`) + tc := newCase(t, `expected non-nil error; got nil`) t.Cleanup(tc.assert) Error(tc, nil) @@ -131,7 +131,7 @@ func TestEqError_PS(t *testing.T) { } func TestEqError_nil(t *testing.T) { - tc := newCase(t, `expected error; got nil`) + tc := newCase(t, `expected non-nil error; got nil`) t.Cleanup(tc.assert) EqError(tc, nil, "blah") @@ -156,7 +156,7 @@ func TestErrorIs_PS(t *testing.T) { } func TestErrorIs_nil(t *testing.T) { - tc := newCase(t, `expected error; got nil`) + tc := newCase(t, `expected non-nil error; got nil`) t.Cleanup(tc.assert) err := errors.New("oops") @@ -179,7 +179,7 @@ func TestErrorAs(t *testing.T) { } func TestErrorAs_nilErr(t *testing.T) { - tc := newCase(t, `expected error; got nil`) + tc := newCase(t, `expected non-nil error; got nil`) t.Cleanup(tc.assert) var target FakeError @@ -187,7 +187,7 @@ func TestErrorAs_nilErr(t *testing.T) { } func TestErrorAs_nilTarget(t *testing.T) { - tc := newCase(t, `expected target not to be nil`) + tc := newCase(t, `expected non-nil target; got nil`) t.Cleanup(tc.assert) var target *FakeError