[Tarantool-patches] [PATCH luajit v3 03/29] test: adapt PUC-Rio suite for out-of-source build
Sergey Kaplun
skaplun at tarantool.org
Tue Apr 13 16:27:03 MSK 2021
The redefined `dofile()` function failed to find the test file to load,
when tests are run out-of-source. So, fullpath is detected considering
`arg[0]` value. Moreover, some tests use `loadfile()` instead, so their
argument has to be adjusted to the full path to the files.
Usage of functions invoking source test files was changed to
`_loadfile()` and `_dofile()` correspondingly. They equal
`loadfile()` and `dofile()` by default and can be overloaded via running
lua code from LUAJIT_TEST_INIT. This patch introduces the
<test/luajit-test-init.lua> file to be executed before tests and
redefines the functions considering the path from `arg[0]` variable.
Part of tarantool/tarantool#5845
Part of tarantool/tarantool#4473
---
CMakeLists.txt | 4 +--
test/PUC-Rio-Lua-5.1-tests/all.lua | 51 +++++++++++++++++-------------
test/luajit-test-init.lua | 18 +++++++++++
3 files changed, 49 insertions(+), 24 deletions(-)
create mode 100644 test/luajit-test-init.lua
diff --git a/CMakeLists.txt b/CMakeLists.txt
index eb562923..df82d57c 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -302,8 +302,8 @@ set(LUAJIT_TEST_BINARY ${LUAJIT_BINARY} CACHE STRING
# tweaked, the introduced option can be used.
# XXX: The default behaviour is nop, so /dev/null is the best
# option for this.
-set(LUAJIT_TEST_INIT "/dev/null" CACHE STRING
- "Lua code need to be run before tests are started. Default is nop."
+set(LUAJIT_TEST_INIT "${PROJECT_SOURCE_DIR}/test/luajit-test-init.lua" CACHE STRING
+ "Lua code need to be run before tests are started."
)
add_subdirectory(test)
diff --git a/test/PUC-Rio-Lua-5.1-tests/all.lua b/test/PUC-Rio-Lua-5.1-tests/all.lua
index 8c4aface..7460a677 100755
--- a/test/PUC-Rio-Lua-5.1-tests/all.lua
+++ b/test/PUC-Rio-Lua-5.1-tests/all.lua
@@ -66,7 +66,12 @@ dofile = function (n)
return f()
end
-dofile('main.lua')
+-- LuaJIT: Adapt tests for testing with out-of-source build.
+-- See the comment in <test/luajit-test-init.lua>.
+local _dofile = _dofile or dofile
+local _loadstring = _loadstring or loadstring
+
+_dofile('main.lua')
do
local u = newproxy(true)
@@ -77,32 +82,34 @@ do
end
end
-local f = assert(loadfile('gc.lua'))
+-- LuaJIT: Adapt tests for testing with out-of-source build.
+-- See the comment in <test/luajit-test-init.lua>.
+local f = assert(_loadfile('gc.lua'))
f()
-dofile('db.lua')
-assert(dofile('calls.lua') == deep and deep)
-dofile('strings.lua')
-dofile('literals.lua')
-assert(dofile('attrib.lua') == 27)
-assert(dofile('locals.lua') == 5)
-dofile('constructs.lua')
-dofile('code.lua')
+_dofile('db.lua')
+assert(_dofile('calls.lua') == deep and deep)
+_dofile('strings.lua')
+_dofile('literals.lua')
+assert(_dofile('attrib.lua') == 27)
+assert(_dofile('locals.lua') == 5)
+_dofile('constructs.lua')
+_dofile('code.lua')
do
- local f = coroutine.wrap(assert(loadfile('big.lua')))
+ local f = coroutine.wrap(assert(_loadfile('big.lua')))
assert(f() == 'b')
assert(f() == 'a')
end
-dofile('nextvar.lua')
-dofile('pm.lua')
-dofile('api.lua')
-assert(dofile('events.lua') == 12)
-dofile('vararg.lua')
-dofile('closure.lua')
-dofile('errors.lua')
-dofile('math.lua')
-dofile('sort.lua')
-assert(dofile('verybig.lua') == 10); collectgarbage()
-dofile('files.lua')
+_dofile('nextvar.lua')
+_dofile('pm.lua')
+_dofile('api.lua')
+assert(_dofile('events.lua') == 12)
+_dofile('vararg.lua')
+_dofile('closure.lua')
+_dofile('errors.lua')
+_dofile('math.lua')
+_dofile('sort.lua')
+assert(_dofile('verybig.lua') == 10); collectgarbage()
+_dofile('files.lua')
if #msgs > 0 then
print("\ntests not performed:")
diff --git a/test/luajit-test-init.lua b/test/luajit-test-init.lua
new file mode 100644
index 00000000..aadd15af
--- /dev/null
+++ b/test/luajit-test-init.lua
@@ -0,0 +1,18 @@
+-- XXX: PUC Rio Lua 5.1 test suite checks that global variable
+-- `_loadfile()` exists and use it for code loading from test
+-- files If the variable is not defined then suite uses
+-- `loadfile()` as default. Same for the `_dofile()`.
+
+-- XXX: Some tests in PUC Rio Lua 5.1 test suite clean `arg`
+-- variable, so evaluate this once and use later.
+local path_to_sources = arg[0]:gsub("[^/]+$", "")
+
+-- luacheck: no global
+function _loadfile(filename)
+ return loadfile(path_to_sources..filename)
+end
+
+-- luacheck: no global
+function _dofile(filename)
+ return dofile(path_to_sources..filename)
+end
--
2.31.0
More information about the Tarantool-patches
mailing list