Skip to content

Commit

Permalink
Print diffs for reference tests (#481)
Browse files Browse the repository at this point in the history
Fixes #469
  • Loading branch information
moorereason authored and rtfb committed Sep 4, 2018
1 parent eebcfd6 commit 2ab1ea3
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ import (
"path/filepath"
"regexp"
"testing"

"github.com/pmezard/go-difflib/difflib"
)

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

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
Expand All @@ -184,3 +185,14 @@ func doTestsReference(t *testing.T, files []string, flag Extensions) {
}
})
}

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
}

0 comments on commit 2ab1ea3

Please sign in to comment.