tinyyarn

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

commit 51befa40a2b5b059c708dfb5d162a9a3b3311af3
parent 4ce92416beb93921086fa8488ba02da2227a4101
Author: Richard Ipsum <richardipsum@vx21.xyz>
Date:   Sat, 23 Nov 2019 18:20:51 +0000

Allow multiple implementation files

Diffstat:
Mtyarn.1 | 2+-
Mtyarn.c | 2+-
Mtyarn.in | 24++++++++++++++++--------
3 files changed, 18 insertions(+), 10 deletions(-)

diff --git a/tyarn.1 b/tyarn.1 @@ -2,7 +2,7 @@ .SH NAME tyarn \- scenario testing of Unix command line tools .SH SYNOPSIS -.B tyarn \fR[OPTION...] \fISCENARIO_FILE IMPLEMENTATION_FILE\fR +.B tyarn \fR[OPTION...] \fISCENARIO_FILE IMPLEMENTATION_FILE...\fR .SH DESCRIPTION tyarn is a scenario testing tool, it is based on yarn, and supports a similar but more limited set of features and syntax. tyarn translates scenarios written diff --git a/tyarn.c b/tyarn.c @@ -329,7 +329,7 @@ static int tyarn_rmutil(lua_State *L) static void usage(void) { - fprintf(stderr, "usage: tyarn [-CdEehlstv] SCENARIO_FILE IMPLEMENTATION_FILE\n"); + fprintf(stderr, "usage: tyarn [-CdEehlstv] SCENARIO_FILE IMPLEMENTATION_FILE...\n"); } static int tyarn_usage(lua_State *L) diff --git a/tyarn.in b/tyarn.in @@ -39,9 +39,7 @@ function normalise_scenario_line(str, step_type) return normalised end -function parse_implementations(filepath) - implementations = {} - +function parse_implementations(filepath, implementations) file, err = io.open(filepath) if file == nil then io.stderr:write(string.format("Couldn't open implementation file: %s\n", filepath, err)) @@ -203,9 +201,10 @@ function _parse_scenarios(scenario_list, scenarios, file, scenario_name, scenari end function parse_scenarios(filepath) - scenario_list = {} - scenarios = {} - line_no = 0 + local scenario_list = {} + local scenarios = {} + local scenario_name = nil + local line_no = 0 file, err = io.open(filepath) if file == nil then @@ -225,6 +224,10 @@ function parse_scenarios(filepath) end end + if scenario_name == nil then + return nil, nil -- no scenario + end + -- now we have the base case, begin the recursion _parse_scenarios(scenario_list, scenarios, file, scenario_name, line_no) @@ -479,7 +482,14 @@ if parsed_args["debug"] or DEBUG then end scenario_list, scenarios = parse_scenarios(parsed_args[1]) + +implementations = {} seen = {} + +for i = 2, #parsed_args do + parse_implementations(parsed_args[i], implementations) +end + for _, scenario_name in ipairs(scenario_list) do if seen[scenario_name] then io.stderr:write(string.format("Duplicate scenario: '%s'\n", scenario_name)) @@ -489,8 +499,6 @@ for _, scenario_name in ipairs(scenario_list) do seen[scenario_name] = true end -implementations = parse_implementations(parsed_args[2]) - for _, scenario_name in ipairs(scenario_list) do passed = run_scenario(scenarios, implementations, scenario_name, parsed_args['shell_lib'])