-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(test): improve failure messages in custom matchers (#422)
display a readable diff of the "processed actual" vs "expected" values Fixes #421 Signed-off-by: Xavier Coulon <[email protected]>
- Loading branch information
Showing
19 changed files
with
164 additions
and
112 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package testsupport | ||
|
||
import ( | ||
"reflect" | ||
|
||
"github.com/davecgh/go-spew/spew" | ||
. "github.com/onsi/ginkgo" // nolint: go-lint | ||
"github.com/sergi/go-diff/diffmatchpatch" | ||
) | ||
|
||
type comparison struct { | ||
actual string | ||
expected string | ||
diffs string | ||
} | ||
|
||
// compare compares the 'actual' vs 'expected' values and produces a 'comparison' report | ||
func compare(actual interface{}, expected interface{}) comparison { | ||
c := comparison{ | ||
actual: spew.Sdump(actual), | ||
expected: spew.Sdump(expected), | ||
} | ||
if !reflect.DeepEqual(actual, expected) { | ||
dmp := diffmatchpatch.New() | ||
diffs := dmp.DiffMain(c.actual, c.expected, true) | ||
c.diffs = dmp.DiffPrettyText(diffs) | ||
} | ||
GinkgoT().Logf("actual:\n%s", c.actual) | ||
GinkgoT().Logf("expected:\n%s", c.expected) | ||
GinkgoT().Logf("diff:\n%s", c.diffs) | ||
return c | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package testsupport_test | ||
|
||
import ( | ||
"reflect" | ||
|
||
"github.com/davecgh/go-spew/spew" | ||
"github.com/sergi/go-diff/diffmatchpatch" | ||
) | ||
|
||
// compare compares the 'actual' vs 'expected' values and produces a 'comparison' report | ||
func compare(actual interface{}, expected interface{}) string { | ||
a := spew.Sdump(actual) | ||
e := spew.Sdump(expected) | ||
if reflect.DeepEqual(actual, expected) { | ||
return "" | ||
} | ||
dmp := diffmatchpatch.New() | ||
diffs := dmp.DiffMain(a, e, true) | ||
return dmp.DiffPrettyText(diffs) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.