# HG changeset patch # User Matthew Wild # Date 1536746326 -3600 # Node ID 885fa9f5929da9fc41608914742920303e15077d # Parent df4faaa2d36f9b3ed0a0dde54b4292df8e40be32 main, scansion.console: Refactor (changes event data format) so that test results include test name diff -r df4faaa2d36f -r 885fa9f5929d main.lua --- a/main.lua Wed Sep 12 10:57:23 2018 +0100 +++ b/main.lua Wed Sep 12 10:58:46 2018 +0100 @@ -282,21 +282,25 @@ local function run_test_script(script_name, script_text) local script = parse_script(script_text) - log_data("script", { title = script.title, summary = script.summary, tags = script.tags, filename = script_name }); + local script_data = { title = script.title, summary = script.summary, tags = script.tags, filename = script_name }; + log_data("script", script_data); local ok, result, err = pcall(main, log_data, script); - local status, reason = "ok"; + local event, status, reason; if not ok then - status, reason = "error", result; - log_data("test-error", { error = result }); + event, status, reason = "test-error", "error", result; elseif not result then - status, reason = "fail", err; - log_data("test-failed", { error = err }); + event, status, reason = "test-failed", "fail", err; else - log_data("test-passed"); + event, status, reason = "test-passed", "ok", nil; end - return { name = script.title or script_name, status = status, reason = reason }; + + local result_data = { name = script.title or script_name, status = status, reason = reason }; + + log_data(event, result_data); + + return result_data; end diff -r df4faaa2d36f -r 885fa9f5929d scansion/console.lua --- a/scansion/console.lua Wed Sep 12 10:57:23 2018 +0100 +++ b/scansion/console.lua Wed Sep 12 10:58:46 2018 +0100 @@ -13,18 +13,28 @@ end; ["test-failed"] = function (data) local error_text; - if data.error and data.error.type == "unexpected-stanza" then - error_text = "Received unexpected stanza:\n\n"..pretty(data.error.data.stanza, 4); - if data.error.data.expected then - error_text = error_text.."\n\nExpected:\n\n"..pretty(data.error.data.expected, 4); + if data.reason and data.reason.type == "unexpected-stanza" then + error_text = "Received unexpected stanza:\n\n"..pretty(data.reason.data.stanza, 4); + if data.reason.data.expected then + error_text = error_text.."\n\nExpected:\n\n"..pretty(data.reason.data.expected, 4); end else - error_text = tostring(data.error); + error_text = tostring(data.reason); end - return "FAIL: "..error_text + return lines({ + "FAILED: "..data.name; + ""; + (error_text:gsub("\n", "\n ")); + ""; + }, 4); end; ["test-error"] = function (data) - return "ERROR: "..tostring(data.error); + return lines({ + "ERROR: "..data.name; + ""; + (tostring(data.reason):gsub("\n", "\n ")); + ""; + }, 4); end; ["action"] = function (data)