From 27786df6a3c885eeee689869beeba7202686fbbf Mon Sep 17 00:00:00 2001 From: Björn Linse Date: Sun, 18 Aug 2019 15:06:15 +0200 Subject: test/ui: make screen:expect() print full state when height does not match --- test/functional/ui/screen.lua | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/test/functional/ui/screen.lua b/test/functional/ui/screen.lua index 3b39794465..36fe46fd13 100644 --- a/test/functional/ui/screen.lua +++ b/test/functional/ui/screen.lua @@ -391,27 +391,31 @@ function Screen:expect(expected, attr_ids, attr_ignore, ...) end if grid ~= nil then + local err_msg, msg_expected_rows = nil, {} -- `expected` must match the screen lines exactly. if #actual_rows ~= #expected_rows then - return "Expected screen state's row count(" .. #expected_rows - .. ') differs from configured height(' .. #actual_rows .. ') of Screen.' + err_msg = "Expected screen height " .. #expected_rows + .. ' differs from actual height ' .. #actual_rows .. '.' end - for i = 1, #actual_rows do + for i = 1, #expected_rows do + msg_expected_rows[i] = expected_rows[i] if expected_rows[i] ~= actual_rows[i] and expected_rows[i] ~= "{IGNORE}|" then - local msg_expected_rows = {} - for j = 1, #expected_rows do - msg_expected_rows[j] = expected_rows[j] - end msg_expected_rows[i] = '*' .. msg_expected_rows[i] - actual_rows[i] = '*' .. actual_rows[i] - return ( - 'Row ' .. tostring(i) .. ' did not match.\n' - ..'Expected:\n |'..table.concat(msg_expected_rows, '\n |')..'\n' - ..'Actual:\n |'..table.concat(actual_rows, '\n |')..'\n\n'..[[ + if i <= #actual_rows then + actual_rows[i] = '*' .. actual_rows[i] + end + if err_msg == nil then + err_msg = 'Row ' .. tostring(i) .. ' did not match.' + end + end + end + if err_msg ~= nil then + return ( + err_msg..'\nExpected:\n |'..table.concat(msg_expected_rows, '\n |')..'\n' + ..'Actual:\n |'..table.concat(actual_rows, '\n |')..'\n\n'..[[ To print the expect() call that would assert the current screen state, use screen:snapshot_util(). In case of non-deterministic failures, use screen:redraw_debug() to show all intermediate screen states. ]]) - end end end -- cgit