main, scansion.console: Refactor (changes event data format) so that test results include test name

Wed, 12 Sep 2018 10:58:46 +0100

author
Matthew Wild <mwild1@gmail.com>
date
Wed, 12 Sep 2018 10:58:46 +0100
changeset 146
885fa9f5929d
parent 145
df4faaa2d36f
child 147
db39e8e9146c

main, scansion.console: Refactor (changes event data format) so that test results include test name

main.lua file | annotate | diff | comparison | revisions
scansion/console.lua file | annotate | diff | comparison | revisions
--- 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
 
 
--- 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)

mercurial