unittests: Run all unit tests in their own processes

Used

    sed -r -i -e '/ helpers =/ s/$/\nlocal itp = helpers.gen_itp(it)/; s/^(\s*)it\(/\1itp(/' test/unit/**/*_spec.lua

to alter all tests. Locally they all run fine now.

Reasoning:

1. General: state from one test should not affect other tests.
2. Local: travis build is failing with something which may be an output of
   garbage collector. This should prevent state of the garbage collector from
   interferring as well.
This commit is contained in:
ZyX
2017-03-05 04:02:45 +03:00
parent 5898b42d82
commit 12b062b2c8
22 changed files with 386 additions and 364 deletions

View File

@@ -1,4 +1,5 @@
local helpers = require('test.unit.helpers')
local itp = helpers.gen_itp(it)
local cimport = helpers.cimport
local to_cstr = helpers.to_cstr
@@ -29,7 +30,7 @@ describe('json_decode_string()', function()
return ffi.gc(decode.xmemdup(c, 1), decode.xfree)
end
it('does not overflow when running with `n…`, `t…`, `f…`', function()
itp('does not overflow when running with `n…`, `t…`, `f…`', function()
local rettv = ffi.new('typval_T', {v_type=decode.VAR_UNKNOWN})
decode.emsg_silent = 1
-- This will not crash, but if `len` argument will be ignored it will parse
@@ -56,7 +57,7 @@ describe('json_decode_string()', function()
eq(decode.VAR_UNKNOWN, rettv.v_type)
end)
it('does not overflow and crash when running with `n`, `t`, `f`', function()
itp('does not overflow and crash when running with `n`, `t`, `f`', function()
local rettv = ffi.new('typval_T', {v_type=decode.VAR_UNKNOWN})
decode.emsg_silent = 1
eq(0, decode.json_decode_string(char('n'), 1, rettv))
@@ -67,7 +68,7 @@ describe('json_decode_string()', function()
eq(decode.VAR_UNKNOWN, rettv.v_type)
end)
it('does not overflow when running with `"…`', function()
itp('does not overflow when running with `"…`', function()
local rettv = ffi.new('typval_T', {v_type=decode.VAR_UNKNOWN})
decode.emsg_silent = 1
eq(0, decode.json_decode_string('"t"', 2, rettv))
@@ -84,7 +85,7 @@ describe('json_decode_string()', function()
eq(msg, ffi.string(decode.last_msg_hist.msg))
end
it('does not overflow in error messages', function()
itp('does not overflow in error messages', function()
check_failure(']test', 1, 'E474: No container to close: ]')
check_failure('[}test', 2, 'E474: Closing list with curly bracket: }')
check_failure('{]test', 2,
@@ -129,11 +130,11 @@ describe('json_decode_string()', function()
check_failure('[1test', 2, 'E474: Unexpected end of input: [1')
end)
it('does not overflow with `-`', function()
itp('does not overflow with `-`', function()
check_failure('-0', 1, 'E474: Missing number after minus sign: -')
end)
it('does not overflow and crash when running with `"`', function()
itp('does not overflow and crash when running with `"`', function()
local rettv = ffi.new('typval_T', {v_type=decode.VAR_UNKNOWN})
decode.emsg_silent = 1
eq(0, decode.json_decode_string(char('"'), 1, rettv))

View File

@@ -1,4 +1,5 @@
local helpers = require('test.unit.helpers')
local itp = helpers.gen_itp(it)
local eval_helpers = require('test.unit.eval.helpers')
local cimport = helpers.cimport
@@ -18,25 +19,25 @@ describe('encode_list_write()', function()
return encode.encode_list_write(l, to_cstr(s), #s)
end
it('writes empty string', function()
itp('writes empty string', function()
local l = list()
eq(0, encode_list_write(l, ''))
eq({[type_key]=list_type}, lst2tbl(l))
end)
it('writes ASCII string literal with printable characters', function()
itp('writes ASCII string literal with printable characters', function()
local l = list()
eq(0, encode_list_write(l, 'abc'))
eq({'abc'}, lst2tbl(l))
end)
it('writes string starting with NL', function()
itp('writes string starting with NL', function()
local l = list()
eq(0, encode_list_write(l, '\nabc'))
eq({null_string, 'abc'}, lst2tbl(l))
end)
it('writes string starting with NL twice', function()
itp('writes string starting with NL twice', function()
local l = list()
eq(0, encode_list_write(l, '\nabc'))
eq({null_string, 'abc'}, lst2tbl(l))
@@ -44,13 +45,13 @@ describe('encode_list_write()', function()
eq({null_string, 'abc', 'abc'}, lst2tbl(l))
end)
it('writes string ending with NL', function()
itp('writes string ending with NL', function()
local l = list()
eq(0, encode_list_write(l, 'abc\n'))
eq({'abc', null_string}, lst2tbl(l))
end)
it('writes string ending with NL twice', function()
itp('writes string ending with NL twice', function()
local l = list()
eq(0, encode_list_write(l, 'abc\n'))
eq({'abc', null_string}, lst2tbl(l))
@@ -58,7 +59,7 @@ describe('encode_list_write()', function()
eq({'abc', 'abc', null_string}, lst2tbl(l))
end)
it('writes string starting, ending and containing NL twice', function()
itp('writes string starting, ending and containing NL twice', function()
local l = list()
eq(0, encode_list_write(l, '\na\nb\n'))
eq({null_string, 'a', 'b', null_string}, lst2tbl(l))
@@ -66,7 +67,7 @@ describe('encode_list_write()', function()
eq({null_string, 'a', 'b', null_string, 'a', 'b', null_string}, lst2tbl(l))
end)
it('writes string starting, ending and containing NUL with NL between twice', function()
itp('writes string starting, ending and containing NUL with NL between twice', function()
local l = list()
eq(0, encode_list_write(l, '\0\n\0\n\0'))
eq({'\n', '\n', '\n'}, lst2tbl(l))
@@ -74,7 +75,7 @@ describe('encode_list_write()', function()
eq({'\n', '\n', '\n\n', '\n', '\n'}, lst2tbl(l))
end)
it('writes string starting, ending and containing NL with NUL between twice', function()
itp('writes string starting, ending and containing NL with NUL between twice', function()
local l = list()
eq(0, encode_list_write(l, '\n\0\n\0\n'))
eq({null_string, '\n', '\n', null_string}, lst2tbl(l))
@@ -82,7 +83,7 @@ describe('encode_list_write()', function()
eq({null_string, '\n', '\n', null_string, '\n', '\n', null_string}, lst2tbl(l))
end)
it('writes string containing a single NL twice', function()
itp('writes string containing a single NL twice', function()
local l = list()
eq(0, encode_list_write(l, '\n'))
eq({null_string, null_string}, lst2tbl(l))
@@ -90,7 +91,7 @@ describe('encode_list_write()', function()
eq({null_string, null_string, null_string}, lst2tbl(l))
end)
it('writes string containing a few NLs twice', function()
itp('writes string containing a few NLs twice', function()
local l = list()
eq(0, encode_list_write(l, '\n\n\n'))
eq({null_string, null_string, null_string, null_string}, lst2tbl(l))

View File

@@ -1,4 +1,5 @@
local helpers = require('test.unit.helpers')
local itp = helpers.gen_itp(it)
local cimport = helpers.cimport
local to_cstr = helpers.to_cstr
@@ -15,7 +16,7 @@ local eval_expr = function(expr)
end
describe('NULL typval_T', function()
it('is produced by $XXX_UNEXISTENT_VAR_XXX', function()
itp('is produced by $XXX_UNEXISTENT_VAR_XXX', function()
-- Required for various tests which need to check whether typval_T with NULL
-- string works correctly. This test checks that unexistent environment
-- variable produces NULL string, not that some specific environment
@@ -29,13 +30,13 @@ describe('NULL typval_T', function()
eq(nil, rettv.vval.v_string)
end)
it('is produced by v:_null_list', function()
itp('is produced by v:_null_list', function()
local rettv = eval_expr('v:_null_list')
eq(eval.VAR_LIST, rettv.v_type)
eq(nil, rettv.vval.v_list)
end)
it('is produced by v:_null_dict', function()
itp('is produced by v:_null_dict', function()
local rettv = eval_expr('v:_null_dict')
eq(eval.VAR_DICT, rettv.v_type)
eq(nil, rettv.vval.v_dict)

View File

@@ -1,4 +1,5 @@
local helpers = require('test.unit.helpers')
local itp = helpers.gen_itp(it)
local eval_helpers = require('test.unit.eval.helpers')
local alloc_log_new = helpers.alloc_log_new
@@ -26,7 +27,7 @@ after_each(function()
end)
describe('clear_tv()', function()
it('successfully frees all lists in [&l [1], *l, *l]', function()
itp('successfully frees all lists in [&l [1], *l, *l]', function()
local l_inner = {1}
local list = {l_inner, l_inner, l_inner}
local list_tv = ffi.gc(lua2typvalt(list), nil)
@@ -53,7 +54,7 @@ describe('clear_tv()', function()
a.freed(list_p),
})
end)
it('successfully frees all lists in [&l [], *l, *l]', function()
itp('successfully frees all lists in [&l [], *l, *l]', function()
local l_inner = {[type_key]=list_type}
local list = {l_inner, l_inner, l_inner}
local list_tv = ffi.gc(lua2typvalt(list), nil)
@@ -77,7 +78,7 @@ describe('clear_tv()', function()
a.freed(list_p),
})
end)
it('successfully frees all dictionaries in [&d {}, *d]', function()
itp('successfully frees all dictionaries in [&d {}, *d]', function()
local d_inner = {}
local list = {d_inner, d_inner}
local list_tv = ffi.gc(lua2typvalt(list), nil)
@@ -99,7 +100,7 @@ describe('clear_tv()', function()
a.freed(list_p),
})
end)
it('successfully frees all dictionaries in [&d {a: 1}, *d]', function()
itp('successfully frees all dictionaries in [&d {a: 1}, *d]', function()
local d_inner = {a=1}
local list = {d_inner, d_inner}
local list_tv = ffi.gc(lua2typvalt(list), nil)