Print diffs for reference tests (#481) Fixes #469
Cameron Moore moorereason@gmail.com
Tue, 04 Sep 2018 16:36:14 -0500
1 files changed,
14 insertions(+),
2 deletions(-)
jump to
M
helpers_test.go
→
helpers_test.go
@@ -18,6 +18,8 @@ "io/ioutil"
"path/filepath" "regexp" "testing" + + "github.com/pmezard/go-difflib/difflib" ) type TestParams struct {@@ -168,8 +170,7 @@ expected := string(expectedBytes)
actual := string(runMarkdown(input, params)) if actual != expected { - t.Errorf("\n [%#v]\nExpected[%#v]\nActual [%#v]", - basename+".text", expected, actual) + t.Errorf("\n" + doTestDiff(basename, expected, actual)) } // now test every prefix of every input to check for@@ -184,3 +185,14 @@ }
} }) } + +func doTestDiff(name, expected, actual string) string { + d, _ := difflib.GetUnifiedDiffString(difflib.UnifiedDiff{ + A: difflib.SplitLines(expected), + B: difflib.SplitLines(actual), + FromFile: "expect: " + name, + ToFile: "actual: " + name, + Context: 1, + }) + return d +}