From 761273f26deba5911e2e04d2c3b2c855fe864846 Mon Sep 17 00:00:00 2001
From: Alexander Turenko <alexander.turenko@tarantool.org>
Date: Mon, 23 Oct 2023 20:05:19 +0300
Subject: [PATCH] test: allow to quote CLI arguments in justrun

Sometimes shell quoting is needed in tests to trigger a validation
error. For example, if the argument is empty or contains whitespaces.

Left the default unchanged to don't affect existing tests.

Part of #8862

NO_DOC=testing helper change
NO_CHANGELOG=see NO_DOC
NO_TEST=see NO_DOC
---
 test/justrun.lua | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/test/justrun.lua b/test/justrun.lua
index 596adf88e9..953b53fefe 100644
--- a/test/justrun.lua
+++ b/test/justrun.lua
@@ -65,6 +65,11 @@ end
 --
 --   Collect stderr and place it into the `stderr` field of the
 --   return value
+--
+-- - quote_args (boolean, default: false)
+--
+--   Quote CLI arguments before concatenating them into a shell
+--   command.
 function justrun.tarantool(dir, env, args, opts)
     assert(type(dir) == 'string')
     assert(type(env) == 'table')
@@ -82,8 +87,11 @@ function justrun.tarantool(dir, env, args, opts)
     local env_str = table.concat(fun.iter(env):map(function(k, v)
         return ('%s=%q'):format(k, v)
     end):totable(), ' ')
+    local args_str = table.concat(fun.iter(args):map(function(v)
+        return opts.quote_args and ('%q'):format(v) or v
+    end):totable(), ' ')
     local command = ('cd %s && %s %s %s'):format(dir, env_str, tarantool_exe,
-                                                 table.concat(args, ' '))
+                                                 args_str)
     log.info(('Running a command: %s'):format(command))
     local mode = opts.stderr and 'rR' or 'r'
     local ph = popen.shell(command, mode)
-- 
GitLab