[Tarantool-patches] [PATCH v2 05/10] test: refactor with _dofile

Maxim Kokryashkin max.kokryashkin at gmail.com
Tue Jul 20 19:26:53 MSK 2021


The patch[1] from lua-Harness suite is quite similar to commit
d11c5bbc08a118b11167c5d455d4024607dab662 ('test: adjust lua-Harness
tests that use dofile'), with the one difference (except the naming):
`make_specific_checks()` provides the particular behaviour to run the
tests for out-of-source build, however `_dofile()` allows user to
overload this function considering his purposes. If user leave
`_dofile()` untouched, it defaults to `dofile()` Lua standard library
function.

It's worth to mention, that LuaJIT testing machinery has been using
such approach since commit 734cc0f1d508429c2c3c46bd1860398db0051060
('test: adapt PUC-Rio suite for out-of-source build') and `_dofile()`
behaviour for running tests when out of source build is used is
already defined in luajit-test-init.lua.

[1]: https://framagit.org/fperrad/lua-Harness/-/commit/60da289

Part of tarantool/tarantool#5970
Part of tarantool/tarantool#4473
---
 test/lua-Harness-tests/101-boolean.t      |  2 +-
 test/lua-Harness-tests/102-function.t     |  2 +-
 test/lua-Harness-tests/103-nil.t          |  2 +-
 test/lua-Harness-tests/104-number.t       |  2 +-
 test/lua-Harness-tests/105-string.t       |  2 +-
 test/lua-Harness-tests/106-table.t        |  2 +-
 test/lua-Harness-tests/107-thread.t       |  2 +-
 test/lua-Harness-tests/108-userdata.t     |  2 +-
 test/lua-Harness-tests/203-lexico.t       |  8 ++++----
 test/lua-Harness-tests/231-metatable.t    |  2 +-
 test/lua-Harness-tests/301-basic.t        |  2 +-
 test/lua-Harness-tests/305-utf8.t         |  4 ++--
 test/lua-Harness-tests/404-ext.t          |  2 +-
 test/lua-Harness-tests/test_assertion.lua | 10 ++--------
 test/luajit-test-init.lua                 |  2 ++
 15 files changed, 21 insertions(+), 25 deletions(-)

diff --git a/test/lua-Harness-tests/101-boolean.t b/test/lua-Harness-tests/101-boolean.t
index eb8b6bbd..9b36174f 100755
--- a/test/lua-Harness-tests/101-boolean.t
+++ b/test/lua-Harness-tests/101-boolean.t
@@ -114,7 +114,7 @@ error_matches(function () local a = true; a[1] = 1; end,
         "index")
 
 if has_op53 then
-    make_specific_checks'lexico53/boolean.t'
+    _dofile'lexico53/boolean.t'
 end
 
 done_testing()
diff --git a/test/lua-Harness-tests/102-function.t b/test/lua-Harness-tests/102-function.t
index a0a3ad33..f144f702 100755
--- a/test/lua-Harness-tests/102-function.t
+++ b/test/lua-Harness-tests/102-function.t
@@ -193,7 +193,7 @@ t[print] = true
 truthy(t[print])
 
 if has_op53 then
-    make_specific_checks'lexico53/function.t'
+    _dofile'lexico53/function.t'
 end
 
 done_testing()
diff --git a/test/lua-Harness-tests/103-nil.t b/test/lua-Harness-tests/103-nil.t
index 718fde16..d7cab0da 100755
--- a/test/lua-Harness-tests/103-nil.t
+++ b/test/lua-Harness-tests/103-nil.t
@@ -114,7 +114,7 @@ error_matches(function () local a = nil; a[1] = 1; end,
         "index")
 
 if has_op53 then
-    make_specific_checks'lexico53/nil.t'
+    _dofile'lexico53/nil.t'
 end
 
 done_testing()
diff --git a/test/lua-Harness-tests/104-number.t b/test/lua-Harness-tests/104-number.t
index 872042c0..9dd3ffa0 100755
--- a/test/lua-Harness-tests/104-number.t
+++ b/test/lua-Harness-tests/104-number.t
@@ -233,7 +233,7 @@ error_matches(function () local a = 3.14; a[1] = 1; end,
         "index")
 
 if has_op53 then
-    make_specific_checks'lexico53/number.t'
+    _dofile'lexico53/number.t'
 end
 
 done_testing()
diff --git a/test/lua-Harness-tests/105-string.t b/test/lua-Harness-tests/105-string.t
index 22e6cfa6..3d167840 100755
--- a/test/lua-Harness-tests/105-string.t
+++ b/test/lua-Harness-tests/105-string.t
@@ -264,7 +264,7 @@ error_matches(function () a = 'text'; a[1] = 1; end,
         "index")
 
 if has_op53 then
-    make_specific_checks'lexico53/string.t'
+    _dofile'lexico53/string.t'
 end
 
 done_testing()
diff --git a/test/lua-Harness-tests/106-table.t b/test/lua-Harness-tests/106-table.t
index ecb761d2..6beb2a5e 100755
--- a/test/lua-Harness-tests/106-table.t
+++ b/test/lua-Harness-tests/106-table.t
@@ -122,7 +122,7 @@ error_matches(function () t = {}; t[0/0] = 42 end,
         "table index is NaN")
 
 if has_op53 then
-    make_specific_checks'lexico53/table.t'
+    _dofile'lexico53/table.t'
 end
 
 done_testing()
diff --git a/test/lua-Harness-tests/107-thread.t b/test/lua-Harness-tests/107-thread.t
index 33ebf769..e9b17139 100755
--- a/test/lua-Harness-tests/107-thread.t
+++ b/test/lua-Harness-tests/107-thread.t
@@ -122,7 +122,7 @@ t[co] = true
 truthy(t[co])
 
 if has_op53 then
-    make_specific_checks'lexico53/thread.t'
+    _dofile'lexico53/thread.t'
 end
 
 done_testing()
diff --git a/test/lua-Harness-tests/108-userdata.t b/test/lua-Harness-tests/108-userdata.t
index 314a60e7..0c7f0c24 100755
--- a/test/lua-Harness-tests/108-userdata.t
+++ b/test/lua-Harness-tests/108-userdata.t
@@ -119,7 +119,7 @@ t[u] = true
 truthy(t[u])
 
 if has_op53 then
-    make_specific_checks'lexico53/userdata.t'
+    _dofile'lexico53/userdata.t'
 end
 
 done_testing()
diff --git a/test/lua-Harness-tests/203-lexico.t b/test/lua-Harness-tests/203-lexico.t
index c9345c71..396a167f 100755
--- a/test/lua-Harness-tests/203-lexico.t
+++ b/test/lua-Harness-tests/203-lexico.t
@@ -118,19 +118,19 @@ do
 end
 
 if _VERSION >= 'Lua 5.2' or jit then
-    make_specific_checks'lexico52/lexico.t'
+    _dofile'lexico52/lexico.t'
 end
 
 if _VERSION >= 'Lua 5.3' or luajit21 then
-    make_specific_checks'lexico53/lexico.t'
+    _dofile'lexico53/lexico.t'
 end
 
 if _VERSION >= 'Lua 5.4' then
-    make_specific_checks'lexico54/lexico.t'
+    _dofile'lexico54/lexico.t'
 end
 
 if jit and pcall(require, 'ffi') then
-    make_specific_checks'lexicojit/lexico.t'
+    _dofile'lexicojit/lexico.t'
 end
 
 done_testing()
diff --git a/test/lua-Harness-tests/231-metatable.t b/test/lua-Harness-tests/231-metatable.t
index 15625c11..06cc902c 100755
--- a/test/lua-Harness-tests/231-metatable.t
+++ b/test/lua-Harness-tests/231-metatable.t
@@ -589,7 +589,7 @@ do
 end
 
 if has_anno_toclose then
-    make_specific_checks'lexico54/metatable.t'
+    _dofile'lexico54/metatable.t'
 end
 
 done_testing()
diff --git a/test/lua-Harness-tests/301-basic.t b/test/lua-Harness-tests/301-basic.t
index c45b2558..01e187d9 100755
--- a/test/lua-Harness-tests/301-basic.t
+++ b/test/lua-Harness-tests/301-basic.t
@@ -843,7 +843,7 @@ do -- xpcall
 end
 
 if jit and pcall(require, 'ffi') then
-    make_specific_checks'lexicojit/basic.t'
+    _dofile'lexicojit/basic.t'
 end
 
 done_testing()
diff --git a/test/lua-Harness-tests/305-utf8.t b/test/lua-Harness-tests/305-utf8.t
index e448a448..2ba48c08 100755
--- a/test/lua-Harness-tests/305-utf8.t
+++ b/test/lua-Harness-tests/305-utf8.t
@@ -40,9 +40,9 @@ if not utf8 then
     falsy(has_utf8, "no has_utf8")
 else
     plan'no_plan'
-    make_specific_checks'lexico53/utf8.t'
+    _dofile'lexico53/utf8.t'
     if _VERSION >= 'Lua 5.4' then
-        make_specific_checks'lexico54/utf8.t'
+        _dofile'lexico54/utf8.t'
     end
     done_testing()
 end
diff --git a/test/lua-Harness-tests/404-ext.t b/test/lua-Harness-tests/404-ext.t
index 7239e5df..45701671 100755
--- a/test/lua-Harness-tests/404-ext.t
+++ b/test/lua-Harness-tests/404-ext.t
@@ -158,7 +158,7 @@ end
 
 -- thread.exdata
 if pcall(require, 'ffi') and (profile.openresty or jit.version:match'moonjit') then
-    make_specific_checks'lexicojit/ext.t'
+    _dofile'lexicojit/ext.t'
 end
 
 done_testing()
diff --git a/test/lua-Harness-tests/test_assertion.lua b/test/lua-Harness-tests/test_assertion.lua
index f126eab1..67cf37f9 100644
--- a/test/lua-Harness-tests/test_assertion.lua
+++ b/test/lua-Harness-tests/test_assertion.lua
@@ -9,6 +9,8 @@
 
 ]]
 
+_dofile = _dofile or dofile     -- could be defined in profile
+
 function _retrieve_progname ()
     local i = 0
     while arg[i] do
@@ -227,14 +229,6 @@ function todo (reason, count)
     todo_reason = reason
 end
 
--- XXX: If tests is run out of the tests source tree, the
--- relative paths below become invalid. Hence, we need to
--- prepend the directory from the script (i.e. test) name to
--- the auxiliary files to be loaded and executed.
-function make_specific_checks (filename)
-    return dofile(arg[0]:gsub('([^/]+)%.t$', '') .. filename)
-end
-
 --
 -- Copyright (c) 2009-2021 Francois Perrad
 --
diff --git a/test/luajit-test-init.lua b/test/luajit-test-init.lua
index 54a1f815..feec17cf 100644
--- a/test/luajit-test-init.lua
+++ b/test/luajit-test-init.lua
@@ -2,6 +2,8 @@
 -- `_loadfile()` exists and uses it for code loading from test
 -- files. If the variable is not defined then suite uses
 -- `loadfile()` as default. Same for the `_dofile()`.
+-- Lua-Harness also uses the same implementation of `dofile()`
+-- fot he same reason
 
 -- XXX: Some tests in PUC Rio Lua 5.1 test suite clean `arg`
 -- variable, so evaluate this once and use later.
-- 
2.32.0



More information about the Tarantool-patches mailing list