main.lua

changeset 131
2d19fdddb9ee
parent 129
ff11f32d2499
child 132
e6df4368029d
equal deleted inserted replaced
130:ce99abde467b 131:2d19fdddb9ee
4 local time = require "socket".gettime; 4 local time = require "socket".gettime;
5 local sleep = require "socket".sleep; 5 local sleep = require "socket".sleep;
6 6
7 local is_scansion_error = require "scansion.error".is; 7 local is_scansion_error = require "scansion.error".is;
8 local new_error = require "scansion.error".new_error; 8 local new_error = require "scansion.error".new_error;
9
10 local console_handlers = require "scansion.console".handlers;
11 9
12 local result_log_filename = nil; 10 local result_log_filename = nil;
13 local server_log_reader = nil; 11 local server_log_reader = nil;
14 local test_metadata = {}; 12 local test_metadata = {};
15 local server_log_wait_time = 0.2; 13 local server_log_wait_time = 0.2;
16 local skip_server_startup_log = false; 14 local skip_server_startup_log = false;
17 local action_timeout = 5; 15 local action_timeout = 5;
18 local verse_log_levels = { "warn", "error" }; 16 local verse_log_levels = { "warn", "error" };
19 local quiet = false; 17 local quiet = false;
18 local force_summary = false;
20 19
21 local property_rules = {}; 20 local property_rules = {};
22 21
23 local function apply_object_properties(class, name, object) 22 local function apply_object_properties(class, name, object)
24 for _, rule in ipairs(property_rules) do 23 for _, rule in ipairs(property_rules) do
94 for f in lfs.dir(path) do 93 for f in lfs.dir(path) do
95 if f:sub(1,1) ~= "." then 94 if f:sub(1,1) ~= "." then
96 table.insert(files, path.."/"..f); 95 table.insert(files, path.."/"..f);
97 end 96 end
98 end 97 end
98 elseif opt == "--summary" then
99 force_summary = true;
99 else 100 else
100 error("Unhandled command-line option: "..opt); 101 error("Unhandled command-line option: "..opt);
101 end 102 end
102 end 103 end
103 for _, file in ipairs(arg) do 104 for _, file in ipairs(arg) do
177 local runner = async.runner(function () 178 local runner = async.runner(function ()
178 for i, action in ipairs(script.actions) do 179 for i, action in ipairs(script.actions) do
179 local object = script.objects[action.object_name]; 180 local object = script.objects[action.object_name];
180 local handler = object.handler; 181 local handler = object.handler;
181 assert(handler[action.action], "Objects of type '"..object.type.."' do not support action '"..action.action.."'"); 182 assert(handler[action.action], "Objects of type '"..object.type.."' do not support action '"..action.action.."'");
182 if not quiet then 183
183 print("");
184 end
185 if server_log_reader then 184 if server_log_reader then
186 log_data("server", { lines = server_log_reader() }); 185 log_data("server", { lines = server_log_reader() });
187 end 186 end
188 log_data("action", { 187 log_data("action", {
189 action = action.action; 188 action = action.action;
190 object = object.name; 189 object = object.name;
191 object_type = object.type; 190 object_type = object.type;
192 extra = action.extra; 191 extra = action.extra;
193 annotation = action.annotation; 192 annotation = action.annotation;
194 }); 193 });
195 --[[ 194
196 if not quiet then
197 if action.annotation then
198 print(action.annotation);
199 end
200 print(object.name.." "..action.action);
201 end]]
202 if action_timeout and action_timeout > 0 then 195 if action_timeout and action_timeout > 0 then
203 local action_number = i; 196 local action_number = i;
204 verse.add_task(action_timeout, function () 197 verse.add_task(action_timeout, function ()
205 if i == action_number then 198 if i == action_number then
206 local e = new_error("action-timeout", { text = "Timeout waiting for response" }); 199 local e = new_error("action-timeout", { text = "Timeout waiting for response" });
246 end 239 end
247 240
248 -- Process command-line options 241 -- Process command-line options
249 local files = process_options(); 242 local files = process_options();
250 243
244 local console_handlers = require "scansion.console".new({
245 summary = not(quiet) or force_summary;
246 quiet = quiet;
247 });
248
251 local function console_logger(event, data) 249 local function console_logger(event, data)
252 if not quiet or type == "test-failed" or type == "test-error" then 250 local h = console_handlers[event];
253 local h = console_handlers[event]; 251 if h then
254 if h then 252 io.write(h(data), "\n");
255 io.write(h(data), "\n");
256 end
257 end 253 end
258 end 254 end
259 255
260 256
261 local result_log; 257 local result_log;
290 status, reason = "error", result; 286 status, reason = "error", result;
291 log_data("test-error", { error = result }); 287 log_data("test-error", { error = result });
292 elseif not result then 288 elseif not result then
293 status, reason = "fail", err; 289 status, reason = "fail", err;
294 log_data("test-failed", { error = err }); 290 log_data("test-failed", { error = err });
295 elseif not quiet then 291 else
296 log_data("test-passed"); 292 log_data("test-passed");
297 end 293 end
298 return { name = script.title or script_name, status = status, reason = reason }; 294 return { name = script.title or script_name, status = status, reason = reason };
299 end 295 end
300 296

mercurial