Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .luacheckrc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
include_files = {"**/*.lua", "*.rockspec", "*.luacheckrc"}
exclude_files = {"build.luarocks/", "lua_modules/", "tmp/", ".luarocks/", ".rocks/"}
exclude_files = {"build.luarocks/", "lua_modules/", "tmp/", ".luarocks/", ".rocks/", "luatest/vendor/"}

max_line_length = 120
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Changelog

## Unreleased

- Added support for unified diff output in `t.assert_equals()` failure messages
when expected and actual values are YAML-serializable (gh-412).

## 1.3.1

- Fixed a bug when `assert_covers` didn't check array items for coverage and
Expand Down
14 changes: 14 additions & 0 deletions luatest/assertions.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
local math = require('math')

local comparator = require('luatest.comparator')
local diff = require('luatest.diff')
local mismatch_formatter = require('luatest.mismatch_formatter')
local pp = require('luatest.pp')
local log = require('luatest.log')
Expand All @@ -20,12 +21,17 @@ local prettystr_pairs = pp.tostring_pair
local M = {}

local xfail = false
local diff_enabled = true

local box_error_type = ffi.typeof(box.error.new(box.error.UNKNOWN))

-- private exported functions (for testing)
M.private = {}

function M.private.set_diff_enabled(value)
diff_enabled = value and true or false
end
Comment on lines +31 to +33
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sseems this function is not needed anymore, right?
As I get right, diff_enabled logic in the test was needed when option for diff support was present.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I use this here to avoid editing old tests

g.before_all(function()
t.private.set_diff_enabled(false)
end)
g.after_all(function()
t.private.set_diff_enabled(true)
end)


function M.private.is_xfail()
local xfail_status = xfail
xfail = false
Expand Down Expand Up @@ -83,6 +89,14 @@ local function error_msg_equality(actual, expected, deep_analysis)
if success then
result = table.concat({result, mismatchResult}, '\n')
end

if diff_enabled then
local diff_result = diff.build_unified_diff(expected, actual)
if diff_result then
result = table.concat({result, 'diff:', diff_result}, '\n')
end
end

return result
end
return string.format("expected: %s, actual: %s",
Expand Down
Loading
Loading