Skip to content

Commit 5a2f88c

Browse files
committed
test(formattest): Print a diff between the expected and actual result.
1 parent b1a1889 commit 5a2f88c

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

pkg/yaml/formattest/testcase.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import (
2323
"path/filepath"
2424
"testing"
2525

26+
"github.com/google/go-cmp/cmp"
2627
"github.com/google/yamlfmt/pkg/yaml"
2728
)
2829

@@ -77,8 +78,9 @@ func (tc formatTestCase) Run(t *testing.T) {
7778
if err != nil {
7879
t.Fatal(err)
7980
}
80-
if buf.String() != string(expected) {
81-
t.Fatalf("expected:\n%s\nactual:\n%s", string(expected), buf.String())
81+
82+
if diff := cmp.Diff(string(expected), buf.String()); diff != "" {
83+
t.Fatalf("Encode() result differs (-want/+got):\n%s", diff)
8284
}
8385
})
8486
}

0 commit comments

Comments
 (0)