commit 6abe801825372a613b12a09e83534e1a46a2871f
parent d34e17f39e77aae671c324c56f9f6950f3b67eec
Author: Richard Ipsum <richardipsum@vx21.xyz>
Date: Wed, 23 Dec 2020 14:52:29 +0000
Move main code into main() function
Diffstat:
M | tyarn.lua.in | | | 131 | +++++++++++++++++++++++++++++++++++++++++-------------------------------------- |
1 file changed, 68 insertions(+), 63 deletions(-)
diff --git a/tyarn.lua.in b/tyarn.lua.in
@@ -574,90 +574,95 @@ function run_scenario(scenarios, implementations, scenario_key, shell_lib_path)
return scenario_passed, failed_step
end
-parsed_args, parsed_env = tyarn.parse_args(arg)
+function main()
+ parsed_args, parsed_env = tyarn.parse_args(arg)
-if parsed_args["help"] then
- tyarn.help()
- os.exit(0)
-end
-
-if #parsed_args < 2 then
- tyarn.usage()
- os.exit(0)
-end
-
-if parsed_args["debug"] or DEBUG then
- print("Args:")
- for k, v in ipairs(parsed_args) do
- print(k, v)
+ if parsed_args["help"] then
+ tyarn.help()
+ os.exit(0)
end
- print("Parsed environment options:")
- for k, v in pairs(parsed_env) do
- print(k, v)
+ if #parsed_args < 2 then
+ tyarn.usage()
+ os.exit(0)
end
-end
-scenario_filepath = parsed_args[1]
-scenario_list, scenarios = parse_scenarios(scenario_filepath)
+ if parsed_args["debug"] or DEBUG then
+ print("Args:")
+ for k, v in ipairs(parsed_args) do
+ print(k, v)
+ end
-implementations = {}
-seen = {}
-failed = {}
-nfailed = 0
+ print("Parsed environment options:")
+ for k, v in pairs(parsed_env) do
+ print(k, v)
+ end
+ end
-if scenario_list == nil then
- io.stderr:write(string.format("No scenarios found in '%s'\n", scenario_filepath))
- os.exit(1)
-end
+ scenario_filepath = parsed_args[1]
+ scenario_list, scenarios = parse_scenarios(scenario_filepath)
-for i = 2, #parsed_args do
- parse_implementations(parsed_args[i], implementations)
-end
+ implementations = {}
+ seen = {}
+ failed = {}
+ nfailed = 0
-for _, scenario_name in ipairs(scenario_list) do
- if seen[scenario_name] then
- io.stderr:write(string.format("Duplicate scenario: '%s'\n", scenario_name))
+ if scenario_list == nil then
+ io.stderr:write(string.format("No scenarios found in '%s'\n", scenario_filepath))
os.exit(1)
end
- seen[scenario_name] = true
-end
-
-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'])
+ for i = 2, #parsed_args do
+ parse_implementations(parsed_args[i], implementations)
+ end
- if not passed then
- if parsed_args["exit_early"] then
- print(string.format("%d/%d: %s: FAILED", n, #scenario_list, scenario_name))
+ for _, scenario_name in ipairs(scenario_list) do
+ if seen[scenario_name] then
+ io.stderr:write(string.format("Duplicate scenario: '%s'\n", scenario_name))
os.exit(1)
end
- failed[scenario_name] = failed_step
- nfailed = nfailed + 1
+ seen[scenario_name] = true
end
- seen_scenario = true
-end
+ 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 seen_scenario then
- io.stderr:write("No scenarios\n")
- os.exit(1)
-end
+ 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
-if nfailed > 0 then
- write_progress_final("Failed scenarios:")
- for scenario, step in pairs(failed) do
- print(string.format(" - %s", scenario))
+ seen_scenario = true
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))
+
+ if not seen_scenario then
+ io.stderr:write("No scenarios\n")
+ os.exit(1)
end
- os.exit(1)
+
+ 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')
end
-write_progress_final('Scenario test suite PASS')
-os.exit(0)
+main()