1
0
Fork 0

🧑‍💻 Show diff between test output and golden file

This commit is contained in:
Maxim Lebedev 2024-02-09 13:06:37 +06:00
parent 2704399e3f
commit 8ce87b8603
Signed by: toby3d
GPG Key ID: 1F14E25B7C119FC5
3 changed files with 8 additions and 3 deletions

2
go.mod
View File

@ -1,3 +1,5 @@
module source.toby3d.me/toby3d/hacks
go 1.22.0
require github.com/google/go-cmp v0.6.0

2
go.sum Normal file
View File

@ -0,0 +1,2 @@
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=

View File

@ -2,13 +2,14 @@
package testing
import (
"bytes"
"errors"
"flag"
"io"
"os"
"path/filepath"
"testing"
"github.com/google/go-cmp/cmp"
)
//nolint:gochecknoglobals // сompiler global flags cannot be read from within tests
@ -67,7 +68,7 @@ func GoldenEqual(tb testing.TB, output io.Reader) {
tb.Fatal("cannot read golden file data:", err)
}
if !bytes.Equal(actual, expect) {
tb.Errorf("the test output does not match the contents of %s.golden file", tb.Name())
if diff := cmp.Diff(actual, expect); diff != "" {
tb.Error(diff)
}
}