tinyyarn

scenario testing of Unix command line tools
Log | Files | Refs | README | LICENSE

commit 87a79ecb14a0aecf597cc6804f31feec8ee756a0
parent 37a617f5f2faa5dc934567a3124739da93711614
Author: Richard Ipsum <richardipsum@vx21.xyz>
Date:   Sat, 30 Nov 2019 04:12:28 +0000

Improve progress reporting and test summary

Diffstat:
Mtyarn.c | 2+-
Mtyarn.in | 69++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++---------
2 files changed, 61 insertions(+), 10 deletions(-)

diff --git a/tyarn.c b/tyarn.c @@ -472,7 +472,7 @@ static int tyarn_parse_args(lua_State *L) lua_setfield(L, -2, "help"); lua_pushstring(L, tmpdir); lua_setfield(L, -2, "tmpdir"); - lua_pushinteger(L, verbose); + lua_pushboolean(L, verbose); lua_setfield(L, -2, "verbose"); lua_pushstring(L, shell); lua_setfield(L, -2, "shell"); diff --git a/tyarn.in b/tyarn.in @@ -391,10 +391,35 @@ function fs_quote(s) return s:gsub("[ /'\"()]", "_"):lower() end +local maxline = 0 + +function write_progress(s) + local ws = '' + + if parsed_args["verbose"] or parsed_args["debug"] or DEBUG then + print(s) + return + end + + if string.len(s) > maxline then + maxline = string.len(s) + end + + io.stderr:write(s .. string.rep(' ', maxline - string.len(s)) .. '\r') +end + +function write_progress_final(s) + write_progress(s) + if parsed_args["verbose"] or parsed_args["debug"] or DEBUG then + return + end + print('') +end + function run_scenario(scenarios, implementations, scenario_key, shell_lib_path) - print('Running', scenario_key) - scenario = scenarios[scenario_key] - tmpdir = nil + local scenario = scenarios[scenario_key] + local tmpdir = nil + local failed_step = nil debug('parsed_args["tmpdir"]', parsed_args["tmpdir"]) @@ -446,7 +471,7 @@ function run_scenario(scenarios, implementations, scenario_key, shell_lib_path) scenario_passed = true for n, step in ipairs(scenario) do - if parsed_args['verbose'] > 0 then + if parsed_args['verbose'] then print('Running step', step) end success, skip_scenario = run_step(scenario_dir, datadir, implementations, @@ -454,6 +479,7 @@ function run_scenario(scenarios, implementations, scenario_key, shell_lib_path) if not success then scenario_passed = false + failed_step = step break end @@ -478,7 +504,7 @@ function run_scenario(scenarios, implementations, scenario_key, shell_lib_path) end - return scenario_passed + return scenario_passed, failed_step end parsed_args, parsed_env = tyarn.parse_args(arg) @@ -509,6 +535,8 @@ scenario_list, scenarios = parse_scenarios(parsed_args[1]) implementations = {} seen = {} +failed = {} +nfailed = 0 for i = 2, #parsed_args do parse_implementations(parsed_args[i], implementations) @@ -523,11 +551,18 @@ for _, scenario_name in ipairs(scenario_list) do seen[scenario_name] = true end -for _, scenario_name in ipairs(scenario_list) do - passed = run_scenario(scenarios, implementations, scenario_name, parsed_args['shell_lib']) +for n, scenario_name in ipairs(scenario_list) do + write_progress(string.format("%d/%d: %s", n, #scenario_list, scenario_name)) + passed, failed_step = run_scenario(scenarios, implementations, scenario_name, parsed_args['shell_lib']) - if not passed and parsed_args["exit_early"] then - os.exit(1) + if not passed then + if parsed_args["exit_early"] then + print(string.format("%d/%d: %s: FAILED", n, #scenario_list, scenario_name)) + os.exit(1) + end + + failed[scenario_name] = failed_step + nfailed = nfailed + 1 end seen_scenario = true @@ -537,3 +572,19 @@ if not seen_scenario then io.stderr:write("No scenarios\n") os.exit(1) end + +if nfailed > 0 then + write_progress_final("Failed scenarios:") + for scenario, step in pairs(failed) do + print(string.format(" - %s", scenario)) + end + if nfailed > 1 then + print(string.format("ERROR: Test suite FAILED in %d scenarios", nfailed)) + else + print(string.format("ERROR: Test suite FAILED in %d scenario", nfailed)) + end + os.exit(1) +end + +write_progress_final('Scenario test suite PASS') +os.exit(0)