# HG changeset patch # User Matthew Wild # Date 1536698062 -3600 # Node ID 2d19fdddb9ee26826f9833803fc9ed9e0623d923 # Parent ce99abde467b0a3e1d22a882f2f92cb82a470a0f main, console: Allow force-printing --summary even if -q is passed diff -r ce99abde467b -r 2d19fdddb9ee main.lua --- a/main.lua Tue Sep 11 21:32:53 2018 +0100 +++ b/main.lua Tue Sep 11 21:34:22 2018 +0100 @@ -7,8 +7,6 @@ local is_scansion_error = require "scansion.error".is; local new_error = require "scansion.error".new_error; -local console_handlers = require "scansion.console".handlers; - local result_log_filename = nil; local server_log_reader = nil; local test_metadata = {}; @@ -17,6 +15,7 @@ local action_timeout = 5; local verse_log_levels = { "warn", "error" }; local quiet = false; +local force_summary = false; local property_rules = {}; @@ -96,6 +95,8 @@ table.insert(files, path.."/"..f); end end + elseif opt == "--summary" then + force_summary = true; else error("Unhandled command-line option: "..opt); end @@ -179,9 +180,7 @@ local object = script.objects[action.object_name]; local handler = object.handler; assert(handler[action.action], "Objects of type '"..object.type.."' do not support action '"..action.action.."'"); - if not quiet then - print(""); - end + if server_log_reader then log_data("server", { lines = server_log_reader() }); end @@ -192,13 +191,7 @@ extra = action.extra; annotation = action.annotation; }); - --[[ - if not quiet then - if action.annotation then - print(action.annotation); - end - print(object.name.." "..action.action); - end]] + if action_timeout and action_timeout > 0 then local action_number = i; verse.add_task(action_timeout, function () @@ -248,12 +241,15 @@ -- Process command-line options local files = process_options(); +local console_handlers = require "scansion.console".new({ + summary = not(quiet) or force_summary; + quiet = quiet; +}); + 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 + local h = console_handlers[event]; + if h then + io.write(h(data), "\n"); end end @@ -292,7 +288,7 @@ elseif not result then status, reason = "fail", err; log_data("test-failed", { error = err }); - elseif not quiet then + else log_data("test-passed"); end return { name = script.title or script_name, status = status, reason = reason }; diff -r ce99abde467b -r 2d19fdddb9ee scansion/console.lua --- a/scansion/console.lua Tue Sep 11 21:32:53 2018 +0100 +++ b/scansion/console.lua Tue Sep 11 21:34:22 2018 +0100 @@ -68,6 +68,23 @@ end; }; +local quiet_handlers = { "test-failed", "test-error" }; + +local function new(config) + local h = {}; + if config.quiet then + for _, handler_name in ipairs(quiet_handlers) do + h[handler_name] = handlers[handler_name]; + end + if config.summary then + h["end"] = handlers["end"]; + end + else + h = handlers; + end + return h; +end + return { - handlers = handlers; + new = new; }