diff options
author | ZyX <kp-pav@yandex.ru> | 2016-09-25 23:48:22 +0300 |
---|---|---|
committer | ZyX <kp-pav@yandex.ru> | 2017-03-11 23:23:30 +0300 |
commit | 82e5af85c1c6d61cc8cf33cf16fa1f3f1e3bf2fa (patch) | |
tree | cc497813373b3b1727dd8904234d8780183f97d1 /test | |
parent | b2b15e6e137d7be2b01bf2174791f36bd12981bd (diff) | |
download | rneovim-82e5af85c1c6d61cc8cf33cf16fa1f3f1e3bf2fa.tar.gz rneovim-82e5af85c1c6d61cc8cf33cf16fa1f3f1e3bf2fa.tar.bz2 rneovim-82e5af85c1c6d61cc8cf33cf16fa1f3f1e3bf2fa.zip |
unittests: Run tests in a separate process
Diffstat (limited to 'test')
-rw-r--r-- | test/unit/helpers.lua | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/test/unit/helpers.lua b/test/unit/helpers.lua index 4af078b486..482bedd6c0 100644 --- a/test/unit/helpers.lua +++ b/test/unit/helpers.lua @@ -4,6 +4,9 @@ local Set = require('test.unit.set') local Preprocess = require('test.unit.preprocess') local Paths = require('test.config.paths') local global_helpers = require('test.helpers') +local posix = require('posix') +local assert = require('luassert') +local say = require('say') local neq = global_helpers.neq local eq = global_helpers.eq @@ -216,6 +219,52 @@ do main.event_init() 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 { cimport = cimport, cppimport = cppimport, @@ -231,4 +280,5 @@ return { OK = OK, FAIL = FAIL, alloc_log_new = alloc_log_new, + gen_itp = gen_itp, } |