[Tarantool-patches] [PATCH luajit 3/5] test: introduce test:skipall TAP helper

Igor Munkin imun at tarantool.org
Mon Feb 27 12:07:21 MSK 2023


Sometimes one need to skip all tests in the script. TAP13 protocol
supports this via the following line:
| 1..0 # SKIP <reason>

Within this commit <test:skipall> helper is introduced that yields the
aforementined line to the TAP consumer and exits the test script. It's
worth to mention, that skipall helper is implemented only for root (i.e.
test with no parent) tests and subtests are not supported at the moment.
The corresponding assertion with FIXME reason is added to <finalize>.

Signed-off-by: Igor Munkin <imun at tarantool.org>
---
 test/tarantool-tests/tap.lua | 23 ++++++++++++++++++++---
 1 file changed, 20 insertions(+), 3 deletions(-)

diff --git a/test/tarantool-tests/tap.lua b/test/tarantool-tests/tap.lua
index a1f54d20..92d59ce9 100644
--- a/test/tarantool-tests/tap.lua
+++ b/test/tarantool-tests/tap.lua
@@ -7,6 +7,12 @@
 local ffi = require("ffi")
 local NULL = ffi.new("void *")
 
+local function finalize(test)
+  -- TODO: implement finalization for subtests too.
+  assert(test.parent == nil, 'FIXME: There is no way to use finalize subtest')
+  os.exit(test:check() and 0 or 1)
+end
+
 local function indent(level, size)
   -- Use the default indent size if none is specified.
   size = tonumber(size) or 4
@@ -90,6 +96,11 @@ local function skip(test, message, extra)
   ok(test, true, message .. " # skip", extra)
 end
 
+local function skipall(test, reason)
+  test:plan(0, reason)
+  finalize(test)
+end
+
 local function like(test, got, pattern, message, extra)
   extra = extra or {}
   extra.got = got
@@ -246,7 +257,7 @@ local function new(parent, name, fun, ...)
     level   = level,
     total   = 0,
     failed  = 0,
-    planned = 0,
+    planned = nil,
     trace   = parent == nil and true or parent.trace,
     -- Set test.strict = true if test:is, test:isnt and
     -- test:is_deeply must be compared strictly with nil.
@@ -266,9 +277,14 @@ local function new(parent, name, fun, ...)
   return test:check()
 end
 
-local function plan(test, planned)
+local function plan(test, planned, reason)
+  if test.planned then
+    -- Use <plan> call location in the error message.
+    error("plan called twice", 2)
+  end
   test.planned = planned
-  io.write(indent(test.level), ("1..%d\n"):format(planned))
+  local tail = planned == 0 and (" # SKIP %s"):format(reason) or ""
+  io.write(indent(test.level), ("1..%d%s\n"):format(planned, tail))
 end
 
 local function check(test)
@@ -313,6 +329,7 @@ test_mt = {
     ok         = ok,
     fail       = fail,
     skip       = skip,
+    skipall    = skipall,
     is         = is,
     isnt       = isnt,
     isnil      = isnil,
-- 
2.30.2



More information about the Tarantool-patches mailing list