tinyyarn

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

commit bbc17ff57e61cee529d92f38864dfde648a50482
parent 87c98e1eb4cc3d633c5af2e6a288c6f5de5720cc
Author: Richard Ipsum <richardipsum@vx21.xyz>
Date:   Tue,  7 Jan 2020 17:58:18 +0000

Write a file with environ contents to DATADIR

This can help with debugging failing scenarios.

Diffstat:
Mtyarn.lua.in | 18+++++++++++++++++-
1 file changed, 17 insertions(+), 1 deletion(-)

diff --git a/tyarn.lua.in b/tyarn.lua.in @@ -289,6 +289,19 @@ function env_from_table(env) return e end +function write_env_to_file(datadir, envvars) + local path = datadir .. "/ENV" + local file, err = io.open(path, "w") + if file == nil then + io.stderr:write(string.format("Couldn't open `%s': %s\n", path, err)) + os.exit(1) + end + for _, var in pairs(envvars) do + file:write(var .. '\n') + end + file:close() +end + function run_step(scenario_dir, datadir, implementations, scenario_key, step, shell_prelude) success = true skip_scenario = false @@ -310,6 +323,7 @@ function run_step(scenario_dir, datadir, implementations, scenario_key, step, sh env[string.format('MATCH_%d', n)] = capture end + -- Add any environment variables passed via command line for k, v in pairs(parsed_env) do env[k] = v end @@ -341,7 +355,9 @@ function run_step(scenario_dir, datadir, implementations, scenario_key, step, sh debug('shell_script_str:', shell_script_str) cmd = {"/usr/bin/env", parsed_args["shell"] or DEFAULT_SHELL, path} - ret, exit_code, stdout, stderr = tyarn.exec(cmd, env_from_table(env), datadir) + envvars = env_from_table(env) + write_env_to_file(datadir, envvars) + ret, exit_code, stdout, stderr = tyarn.exec(cmd, envvars, datadir) if parsed_args["show_stdout"] and string.len(stdout) > 0 then io.stderr:write("STDOUT:\n" .. stdout) end