Skip to content

Commit

Permalink
test: simplify testing harness
Browse files Browse the repository at this point in the history
It keeps all necessary functionality working:

* The module from the repository (strictly speaking, from the build
  directory) is preferred over one installed into a system or to .rocks.
* The test does not spoil the working directory with *.snap and *.xlog
  files.
* `make test` works as for in-source as well as for out-of-source build.

See details in PR #14.

@Totktonada: Added comments, rewrote the commit message, adjusted
.gitignore. The idea and actual changes are from @rosik.
  • Loading branch information
rosik authored and Totktonada committed Jun 3, 2021
1 parent 45bd8db commit 7dc758d
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 49 deletions.
3 changes: 0 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,3 @@ extra/txt2c

# Vim Swap files
.*.sw[a-z]

# Default test working directory
test/var/
13 changes: 2 additions & 11 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,13 +1,4 @@
add_test(
NAME tuple_keydef.test.lua
COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/runtest.sh tuple_keydef.test.lua)

# Add LUA_CPATH that points to the location, where the built
# module (tuple/keydef.{so,dylib}) is placed. It is different
# from the source directory, when out-of-source build is used
# (`cmake /path/to/sources`, not just `cmake .`).
#
# Double semicolons (';;') are replaced with default paths.
set(TEST_ENV
"LUA_CPATH=${CMAKE_CURRENT_BINARY_DIR}/../?${CMAKE_SHARED_LIBRARY_SUFFIX}\\\;\\\;")
set_tests_properties(tuple_keydef.test.lua PROPERTIES ENVIRONMENT ${TEST_ENV})
COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/tuple_keydef.test.lua
WORKING_DIRECTORY ${CMAKE_BINARY_DIR})
18 changes: 0 additions & 18 deletions test/runtest.sh

This file was deleted.

44 changes: 27 additions & 17 deletions test/tuple_keydef.test.lua
Original file line number Diff line number Diff line change
@@ -1,20 +1,5 @@
#!/usr/bin/env tarantool

-- Prefer the module from the repository.
--
-- It correctly finds the module, when in-source build is used
-- (`cmake .` as opposed to `cmake /path/to/source`). Otherwise
-- the module should be installed into one of default locations
-- (rare case for testing) or LUA_CPATH should point to its
-- location.
--
-- You don't need to bother about LUA_CPATH if you're use
-- `make test` or run the test manually with in-source build.
local cur_dir = require('fio').abspath(debug.getinfo(1).source:match("@?(.*/)")
:gsub('/%./', '/'):gsub('/+$', ''))
local soext = jit.os == 'OSX' and 'dylib' or 'so'
package.cpath = ('%s/../?.%s;%s'):format(cur_dir, soext, package.cpath)

-- {{{ Compatibility layer between different tarantool versions

local function parse_tarantool_version(component)
Expand Down Expand Up @@ -145,9 +130,34 @@ local tuple_keydef_new_cases = {
}},
exp_err = coll_not_found(1, 'unicode_ci'),
},
-- Call box.cfg() to load collations, which are used in the
-- following test cases.
function()
-- For collations.
box.cfg{}
-- Trick to don't leave *.snap, *.xlog files after
-- testing.
--
-- 1. Write the initial snapshot to a temporary directory
-- and remove it right after dumping the snapshot.
-- 2. Disable *.xlog writting at all.
--
-- We lean on the following assumptions here:
--
-- a) The test does not call box.snapshot() and its
-- duration is less than the default checkpoint
-- interval (1 hour).
-- b) The test is irrelevant to tarantool functionality
-- that is available only with enabled WAL (say,
-- replication).
-- c) The test does not write any logs or temporary files
-- into the working directory (otherwise we should
-- clean up them too somehow).
local fio = require('fio')
local tempdir = fio.tempdir()
box.cfg{
memtx_dir = tempdir,
wal_mode = 'none',
}
fio.rmtree(tempdir)
end,
-- Cases to call after box.cfg{}.
--[[ FIXME: Bring collation_id support back.
Expand Down

0 comments on commit 7dc758d

Please sign in to comment.