commit 3f9cd8512da191a6b5329bedfb17e839dcc13c5e
parent b13d103099ea0abf93b047610aa72cc9563378d6
Author: Richard Ipsum <richardipsum@fastmail.co.uk>
Date:   Sat, 22 Jun 2019 22:49:09 +0100
Add options to show test's stdout/stderr messages
Diffstat:
3 files changed, 27 insertions(+), 1 deletion(-)
diff --git a/tyarn.1 b/tyarn.1
@@ -106,5 +106,11 @@ Use DIR as temporary directory for tests, DIR is a template e.g. /tmp/foo.XXXXXX
 .TP
 .BR \-v
 Show verbose messages
+.TP
+.BR \-1
+Display any messages printed to stdout during execution of scenario steps
+.TP
+.BR \-2
+Display any messages printed to stderr during execution of scenario steps
 .SH "SEE ALSO"
 yarn(1)
diff --git a/tyarn.c b/tyarn.c
@@ -353,6 +353,8 @@ static void help(void)
         "           (this argument can be repeated to add multiple variables)\n"
         "  -h       This help message\n"
         "  -l SHELL_LIBRARY\n"
+        "  -1       Show any messages printed to stdout during execution of scenario steps\n"
+        "  -2       Show any messages printed to stderr during execution of scenario steps\n"
         "           Shell library to be used by scenario implementations\n"
         "  -s SHELL Execute scenario implementations using SHELL\n"
         "  -t DIR\n"
@@ -388,6 +390,8 @@ static int tyarn_parse_args(lua_State *L)
     char *shell = NULL;
     char *envopts[8192];
     size_t envoptsn = 0;
+    bool show_stdout = false;
+    bool show_stderr = false;
 
     luaL_checktype(L, 1, LUA_TTABLE);
 
@@ -411,8 +415,14 @@ static int tyarn_parse_args(lua_State *L)
         buf[bufn++] = strdup(args[i]);
     }
 
-    while ((c = getopt(bufn, buf, ":l:s:dECht:e:v")) != -1) {
+    while ((c = getopt(bufn, buf, ":12l:s:dECht:e:v")) != -1) {
         switch (c) {
+            case '1':
+                show_stdout = true;
+                break;
+            case '2':
+                show_stderr = true;
+                break;
             case 'C':
                 no_cleanup = true;
                 break;
@@ -466,6 +476,10 @@ static int tyarn_parse_args(lua_State *L)
     lua_setfield(L, -2, "verbose");
     lua_pushstring(L, shell);
     lua_setfield(L, -2, "shell");
+    lua_pushboolean(L, show_stdout);
+    lua_setfield(L, -2, "show_stdout");
+    lua_pushboolean(L, show_stderr);
+    lua_setfield(L, -2, "show_stderr");
 
     int tn = 1;
     for (int i = optind; i < bufn; i++) {
diff --git a/tyarn.in b/tyarn.in
@@ -282,6 +282,12 @@ function run_step(scenario_dir, datadir, implementations, scenario_key, step, sh
 
     cmd = {"/usr/bin/env", parsed_args["shell"] or DEFAULT_SHELL, path}
     ret, exit_code, stdout, stderr = tyarn.exec(cmd, env, datadir)
+    if parsed_args["show_stdout"] and string.len(stdout) > 0 then
+        io.stderr:write("STDOUT:\n" .. stdout)
+    end
+    if parsed_args["show_stderr"] and string.len(stderr) > 0 then
+        io.stderr:write("STDERR:\n" .. stderr)
+    end
     debug('ret', ret, 'exit_code', exit_code)
     if ret == -1 then
         error(string.format("Failed to exec step: %s", impl_step))