From 28e44f905c5d91306b7b222402ae86437c8d8dff Mon Sep 17 00:00:00 2001 From: Anmol Sethi Date: Thu, 5 Jan 2023 13:19:08 -0800 Subject: [PATCH] assert: Add Equal and NotEqual [ci-base] --- assert/assert.go | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/assert/assert.go b/assert/assert.go index 1ac8233..b72efcd 100644 --- a/assert/assert.go +++ b/assert/assert.go @@ -4,6 +4,7 @@ package assert import ( "io" "path/filepath" + "reflect" "testing" "oss.terrastruct.com/util-go/xjson" @@ -63,18 +64,35 @@ func Runes(tb testing.TB, exp, got string) { } func TestdataJSON(tb testing.TB, got interface{}) { + tb.Helper() err := diff.TestdataJSON(filepath.Join("testdata", tb.Name()), got) Success(tb, err) } func Testdata(tb testing.TB, ext string, got []byte) { + tb.Helper() err := diff.Testdata(filepath.Join("testdata", tb.Name()), ext, got) Success(tb, err) } -func Close(t *testing.T, c io.Closer) { +func Close(tb testing.TB, c io.Closer) { + tb.Helper() err := c.Close() if err != nil { - t.Fatalf("failed to close %T: %v", c, err) + tb.Fatalf("failed to close %T: %v", c, err) + } +} + +func Equal(tb testing.TB, exp, got interface{}) { + tb.Helper() + if exp != got { + tb.Fatalf("expected %[1]p %#[1]v but got %[2]p %#[2]v", exp, got) + } +} + +func NotEqual(tb testing.TB, v1, v2 interface{}) { + tb.Helper() + if v1 == v2 { + tb.Fatalf("did not expect %[1]p %#[1]v", v2) } }