main.lua

changeset 127
df5aa6a12561
parent 125
dfff8dfe8861
child 128
d241861a36b4
equal deleted inserted replaced
126:87ea077acc21 127:df5aa6a12561
33 33
34 local function process_options() 34 local function process_options()
35 local function get_value() 35 local function get_value()
36 return (assert(table.remove(arg, 1), "unexpected end of command-line options")); 36 return (assert(table.remove(arg, 1), "unexpected end of command-line options"));
37 end 37 end
38
39 local files = {};
40
38 while arg[1] and arg[1]:sub(1,1) == "-" do 41 while arg[1] and arg[1]:sub(1,1) == "-" do
39 local opt = arg[1]; 42 local opt = arg[1];
40 if opt == "--" then 43 if opt == "--" then
41 table.remove(arg, 1); 44 table.remove(arg, 1);
42 break; 45 break;
80 verse_log_levels = { "debug", "info", "warn", "error" }; 83 verse_log_levels = { "debug", "info", "warn", "error" };
81 quiet = false; 84 quiet = false;
82 elseif opt == "--quiet" or opt == "-q" then 85 elseif opt == "--quiet" or opt == "-q" then
83 verse_log_levels = { "error" }; 86 verse_log_levels = { "error" };
84 quiet = true; 87 quiet = true;
88 elseif opt == "-d" then
89 local have_lfs, lfs = pcall(require, "lfs");
90 if not have_lfs then
91 error("The '-d' parameter requires LuaFileSystem (lfs), please make sure this library is available");
92 end
93 local path = assert(get_value(), "path expected for '-d'"):gsub("/*$", "");
94 for f in lfs.dir(path) do
95 if f:sub(1,1) ~= "." then
96 table.insert(files, path.."/"..f);
97 end
98 end
85 else 99 else
86 error("Unhandled command-line option: "..opt); 100 error("Unhandled command-line option: "..opt);
87 end 101 end
88 end 102 end
89 assert(#arg > 0, "No test script provided"); 103 for _, file in ipairs(arg) do
104 table.insert(files, file);
105 end
106 assert(#files > 0, "No test script provided");
107 return files;
90 end 108 end
91 109
92 local function read_script(script_name) 110 local function read_script(script_name)
93 io.input(script_name); 111 io.input(script_name);
94 return io.read("*a"); 112 return io.read("*a");
226 244
227 return ok, err; 245 return ok, err;
228 end 246 end
229 247
230 -- Process command-line options 248 -- Process command-line options
231 process_options(); 249 local files = process_options();
232 250
233 local function console_logger(event, data) 251 local function console_logger(event, data)
234 if not quiet or type == "test-failed" or type == "test-error" then 252 if not quiet or type == "test-failed" or type == "test-error" then
235 local h = console_handlers[event]; 253 local h = console_handlers[event];
236 if h then 254 if h then
260 end 278 end
261 end 279 end
262 end; 280 end;
263 281
264 local function run_test_script(script_name) 282 local function run_test_script(script_name)
283 print(script_name)
265 local script = parse_script(read_script(script_name)) 284 local script = parse_script(read_script(script_name))
266 log_data("script", { title = script.title, summary = script.summary, tags = script.tags, filename = script_name }); 285 log_data("script", { title = script.title, summary = script.summary, tags = script.tags, filename = script_name });
267 286
268 local ok, result, err = pcall(main, log_data, script); 287 local ok, result, err = pcall(main, log_data, script);
269 288
282 301
283 log_data("start", { metadata = test_metadata }); 302 log_data("start", { metadata = test_metadata });
284 303
285 local result_tally = { all = {} }; 304 local result_tally = { all = {} };
286 305
287 for i = 1, #arg do 306 for i = 1, #files do
288 local ret = run_test_script(arg[i]); 307 local ret = run_test_script(files[i]);
289 if not result_tally[ret.status] then 308 if not result_tally[ret.status] then
290 result_tally[ret.status] = {}; 309 result_tally[ret.status] = {};
291 end 310 end
292 table.insert(result_tally[ret.status], ret); 311 table.insert(result_tally[ret.status], ret);
293 table.insert(result_tally.all, ret); 312 table.insert(result_tally.all, ret);

mercurial