-
Notifications
You must be signed in to change notification settings - Fork 12
Add unified diff support for luatest.assert_equals
#438
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
69c5c84 to
fef0177
Compare
ligurio
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Max, thanks for the patch!
Please take a look on my comments.
1d91b35 to
26138ab
Compare
edcc8eb to
6a22390
Compare
6a22390 to
f2c9536
Compare
ligurio
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks!
f2c9536 to
8f7455d
Compare
8f7455d to
1858e02
Compare
1858e02 to
d8c2af9
Compare
|
@locker |
locker
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mandesero Thanks for implementing the diff algo. I like it much more than using a third-party module.
8567667 to
e57cc86
Compare
e57cc86 to
d470e14
Compare
This patch adds a simple line-by-line diff output for `t.assert_equals()` and `t.assert_covers()` failures. Closes tarantool#412
d470e14 to
64e8e8a
Compare
| local actual_text = pp.tostring(actual) | ||
| pp.LINE_LENGTH = old | ||
|
|
||
| if expected_text == nil or actual_text == nil then |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
AFAICS pp.tostring never returns nil.
|
|
||
| local M = {} | ||
|
|
||
| local function diff_by_lines(text1, text2) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I presume you used this wiki page as a reference? It'd be nice to put a link to it somewhere in a comment.
| return diffs | ||
| end | ||
|
|
||
| local function prettify_patch(diffs) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It doesn't look like there's much point in splitting this function in two. I'd simply merge prettify_patch into diff_by_lines.
| end | ||
| end | ||
|
|
||
| if #out == 0 then |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How can it be? Why do we need to care, anyways?
| return nil | ||
| end | ||
|
|
||
| if expected_text == actual_text then |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we need this check. actual and expected aren't supposed to be the same, but even if they are, we can print the diff without +-.
| local diffs = diff_by_lines(expected_text, actual_text) | ||
| local patch_text = prettify_patch(diffs) | ||
|
|
||
| if patch_text == '' or patch_text == nil then |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we need this special case, either.
| assert_failure_contains('diff', t.assert_equals, actual, expected) | ||
| end | ||
|
|
||
| function g_diff.test_msgpack_table() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All these tests checking various Lua types look pointless now, when we use pp.tostring. They should already be covered by pp.tostring tests.
This patch adds unified diff output for
t.assert_equals()failures when the test suite is run with the--diffoption, using a vendored Lua implementation of google/diff-match-patch (luatest/vendor/diff_match_patch.luataken from 1).Closes #412
Here is the output for the example from the issue:
code
Footnotes
https://github.com/google/diff-match-patch/blob/master/lua/diff_match_patch.lua ↩