Skip to content

Commit 2ab1ea3

Browse files
moorereasonrtfb
authored andcommitted
Print diffs for reference tests (#481)
Fixes #469
1 parent eebcfd6 commit 2ab1ea3

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

helpers_test.go

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ import (
1818
"path/filepath"
1919
"regexp"
2020
"testing"
21+
22+
"github.com/pmezard/go-difflib/difflib"
2123
)
2224

2325
type TestParams struct {
@@ -168,8 +170,7 @@ func doTestsReference(t *testing.T, files []string, flag Extensions) {
168170

169171
actual := string(runMarkdown(input, params))
170172
if actual != expected {
171-
t.Errorf("\n [%#v]\nExpected[%#v]\nActual [%#v]",
172-
basename+".text", expected, actual)
173+
t.Errorf("\n" + doTestDiff(basename, expected, actual))
173174
}
174175

175176
// now test every prefix of every input to check for
@@ -184,3 +185,14 @@ func doTestsReference(t *testing.T, files []string, flag Extensions) {
184185
}
185186
})
186187
}
188+
189+
func doTestDiff(name, expected, actual string) string {
190+
d, _ := difflib.GetUnifiedDiffString(difflib.UnifiedDiff{
191+
A: difflib.SplitLines(expected),
192+
B: difflib.SplitLines(actual),
193+
FromFile: "expect: " + name,
194+
ToFile: "actual: " + name,
195+
Context: 1,
196+
})
197+
return d
198+
}

0 commit comments

Comments
 (0)