main.lua

changeset 115
0f8d0906af6e
parent 114
48aab6c9e9d3
child 117
fd4025e54f4d
--- a/main.lua	Mon Sep 10 13:48:25 2018 +0100
+++ b/main.lua	Mon Sep 10 13:52:35 2018 +0100
@@ -5,6 +5,7 @@
 local sleep = require "socket".sleep;
 
 local is_scansion_error = require "scansion.error".is;
+local console_handlers = require "scansion.console".handlers;
 
 local result_log_filename = nil;
 local server_log_reader = nil;
@@ -168,12 +169,13 @@
 				extra = action.extra;
 				annotation = action.annotation;
 			});
+			--[[
 			if not quiet then
 				if action.annotation then
 					print(action.annotation);
 				end
 				print(object.name.." "..action.action);
-			end
+			end]]
 			if action_timeout and action_timeout > 0 then
 				local action_number = i;
 				verse.add_task(action_timeout, function ()
@@ -220,35 +222,43 @@
 -- Process command-line options
 process_options();
 
--- Dummy logging function, used if no log file set
-local log_data = function () end;
+local function console_logger(event, data)
+	if not quiet or type == "test-failed" or type == "test-error" then
+		local h = console_handlers[event];
+		if h then
+			io.write(h(data), "\n");
+		end
+	end
+end
+
 
 local result_log;
 if result_log_filename then
 	result_log = assert(io.open(result_log_filename, "w+"));
 	result_log:write("[\n");
-	function log_data(type, data)
+end
+
+local function log_data(type, data)
+	console_logger(type, data);
+
+	if result_log then
 		local entry = { type = type, data = data, time = time() };
 		result_log:write("  ", json.encode(entry), ",\n");
 		result_log:flush();
 	end
-end
+end;
 
 local function run_test_script(script_name)
-
 	local ok, result, err = pcall(main, log_data, script_name);
 
 	local exit_code = 0;
 	if not ok then
-		print("TEST ERROR:", result);
 		exit_code = 2;
 		log_data("test-error", { error = result });
 	elseif not result then
-		print("TEST FAILED", err);
 		exit_code = 1;
 		log_data("test-failed", { error = err });
 	elseif not quiet then
-		print("TEST PASSED");
 		log_data("test-passed");
 	end
 	return exit_code;

mercurial