unittests: Run tests in a separate process

This commit is contained in:
ZyX
2016-09-25 23:48:22 +03:00
parent b2b15e6e13
commit 82e5af85c1
2 changed files with 58 additions and 1 deletions

View File

@@ -4,6 +4,9 @@ local Set = require('test.unit.set')
local Preprocess = require('test.unit.preprocess') local Preprocess = require('test.unit.preprocess')
local Paths = require('test.config.paths') local Paths = require('test.config.paths')
local global_helpers = require('test.helpers') local global_helpers = require('test.helpers')
local posix = require('posix')
local assert = require('luassert')
local say = require('say')
local neq = global_helpers.neq local neq = global_helpers.neq
local eq = global_helpers.eq local eq = global_helpers.eq
@@ -216,6 +219,52 @@ do
main.event_init() main.event_init()
end end
local function gen_itp(it)
local function just_fail(_)
return false
end
say:set('assertion.just_fail.positive', '%s')
say:set('assertion.just_fail.negative', '%s')
assert:register('assertion', 'just_fail', just_fail,
'assertion.just_fail.positive',
'assertion.just_fail.negative')
local function itp(name, func)
it(name, function()
local rd, wr = posix.pipe()
local pid = posix.fork()
if pid == 0 then
posix.close(rd)
local err, emsg = pcall(func)
emsg = tostring(emsg)
if not err then
posix.write(wr, ('-\n%05u\n%s'):format(#emsg, emsg))
posix.close(wr)
posix._exit(1)
else
posix.write(wr, '+\n')
posix.close(wr)
posix._exit(0)
end
else
posix.close(wr)
posix.wait(pid)
local res = posix.read(rd, 2)
eq(2, #res)
if res == '+\n' then
return
end
eq('-\n', res)
local len_s = posix.read(rd, 5)
local len = tonumber(len_s)
neq(0, len)
local err = posix.read(rd, len + 1)
assert.just_fail(err)
end
end)
end
return itp
end
return { return {
cimport = cimport, cimport = cimport,
cppimport = cppimport, cppimport = cppimport,
@@ -231,4 +280,5 @@ return {
OK = OK, OK = OK,
FAIL = FAIL, FAIL = FAIL,
alloc_log_new = alloc_log_new, alloc_log_new = alloc_log_new,
gen_itp = gen_itp,
} }

View File

@@ -172,5 +172,12 @@ if(USE_BUNDLED_BUSTED)
add_custom_target(nvim-client add_custom_target(nvim-client
DEPENDS ${HOSTDEPS_LIB_DIR}/luarocks/rocks/nvim-client) DEPENDS ${HOSTDEPS_LIB_DIR}/luarocks/rocks/nvim-client)
list(APPEND THIRD_PARTY_DEPS busted luacheck nvim-client) add_custom_command(OUTPUT ${HOSTDEPS_BIN_DIR}/luaposix
COMMAND ${LUAROCKS_BINARY}
ARGS build https://raw.githubusercontent.com/luaposix/luaposix/release-v33.4.0/luaposix-33.4.0-1.rockspec ${LUAROCKS_BUILDARGS}
DEPENDS luarocks)
add_custom_target(luaposix
DEPENDS ${HOSTDEPS_BIN_DIR}/luaposix)
list(APPEND THIRD_PARTY_DEPS busted luacheck nvim-client luaposix)
endif() endif()