[Tarantool-patches] [PATCH v2 luajit 1/3] test: add auxillary module for testing

Igor Munkin imun at tarantool.org
Wed Apr 15 03:34:25 MSK 2020


The introduced Lua module provides the <selfrun> routine for testing the
platform behaviour in some cases e.g. when test case leads to panic and
error message need to be checked after the platform failure.

Signed-off-by: Igor Munkin <imun at tarantool.org>
---
 test/suite.ini |  1 +
 test/utils.lua | 33 +++++++++++++++++++++++++++++++++
 2 files changed, 34 insertions(+)
 create mode 100644 test/utils.lua

diff --git a/test/suite.ini b/test/suite.ini
index 3e860c9..0b9d5e2 100644
--- a/test/suite.ini
+++ b/test/suite.ini
@@ -1,5 +1,6 @@
 [default]
 core = app
 description = Luajit tests
+lua_libs = utils.lua
 is_parallel = True
 pretest_clean = True
diff --git a/test/utils.lua b/test/utils.lua
new file mode 100644
index 0000000..5e6f8d9
--- /dev/null
+++ b/test/utils.lua
@@ -0,0 +1,33 @@
+local M = { }
+
+local tap = require('tap')
+
+function M.selfrun(arg, checks)
+  local test = tap.test(arg[0]:match('/?(.+)%.test%.lua'))
+
+  test:plan(#checks)
+
+  local vars = {
+    LUABIN = arg[-1],
+    SCRIPT = arg[0],
+    PATH   = arg[0]:gsub('%.test%.lua', ''),
+    SUFFIX = package.cpath:match('?.(%a+);'),
+  }
+
+  local cmd = string.gsub('LUA_CPATH="$LUA_CPATH;<PATH>/?.<SUFFIX>" ' ..
+                          'LUA_PATH="$LUA_PATH;<PATH>/?.lua" ' ..
+                          'LD_LIBRARY_PATH=<PATH> ' ..
+                          '<LUABIN> 2>&1 <SCRIPT>', '%<(%w+)>', vars)
+
+  for _, ch in pairs(checks) do
+    local res
+    local proc = io.popen((cmd .. (' %s'):rep(#ch.arg)):format(unpack(ch.arg)))
+    for s in proc:lines() do res = s end
+    assert(res, 'proc:lines failed')
+    test:is(res, ch.res, ch.msg)
+  end
+
+  os.exit(test:check() and 0 or 1)
+end
+
+return M
-- 
2.25.0



More information about the Tarantool-patches mailing list