aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZyX <kp-pav@yandex.ru>2017-04-04 18:14:09 +0300
committerZyX <kp-pav@yandex.ru>2017-04-06 07:29:15 +0300
commit271df03fa4b507d8ec608abd530616cb4b57616e (patch)
tree911dbbfd50670f18c46605452f8affb392f1ddde
parent210b013ce75b5ea8a897071e32decc1e1f88189e (diff)
downloadrneovim-271df03fa4b507d8ec608abd530616cb4b57616e.tar.gz
rneovim-271df03fa4b507d8ec608abd530616cb4b57616e.tar.bz2
rneovim-271df03fa4b507d8ec608abd530616cb4b57616e.zip
unittests: Force GC, fix GC failures in typval_spec
-rw-r--r--test/unit/eval/typval_spec.lua37
-rw-r--r--test/unit/helpers.lua3
2 files changed, 29 insertions, 11 deletions
diff --git a/test/unit/eval/typval_spec.lua b/test/unit/eval/typval_spec.lua
index 258b5c4c1f..c477683038 100644
--- a/test/unit/eval/typval_spec.lua
+++ b/test/unit/eval/typval_spec.lua
@@ -460,6 +460,10 @@ describe('typval.c', function()
eq(empty_list, typvalt2lua(l_tv))
eq({true, true, true}, {lws[1].lw_item == nil, lws[2].lw_item == nil, lws[3].lw_item == nil})
+ lib.tv_list_watch_remove(l, lws[1])
+ lib.tv_list_watch_remove(l, lws[2])
+ lib.tv_list_watch_remove(l, lws[3])
+
alloc_log:check({})
end)
end)
@@ -1090,9 +1094,13 @@ describe('typval.c', function()
local function list_join(l, sep, ret)
local ga = ga_alloc()
eq(ret or OK, lib.tv_list_join(ga, l, sep))
- if ga.ga_data == nil then return ''
- else return ffi.string(ga.ga_data)
+ local ret = ''
+ if ga.ga_data ~= nil then
+ ret = ffi.string(ga.ga_data)
end
+ -- For some reason this is not working well in GC
+ lib.ga_clear(ffi.gc(ga, nil))
+ return ret
end
itp('works', function()
local l
@@ -2659,7 +2667,8 @@ describe('typval.c', function()
{lib.VAR_SPECIAL, {v_special=lib.kSpecialVarFalse}, nil, 0},
{lib.VAR_UNKNOWN, nil, 'E685: Internal error: tv_get_number(UNKNOWN)', 0},
}) do
- local tv = typvalt(v[1], v[2])
+ -- Using to_cstr, cannot free with tv_clear
+ local tv = ffi.gc(typvalt(v[1], v[2]), nil)
alloc_log:check({})
local emsg = v[3]
local ret = v[4]
@@ -2687,7 +2696,8 @@ describe('typval.c', function()
{lib.VAR_SPECIAL, {v_special=lib.kSpecialVarFalse}, nil, 0},
{lib.VAR_UNKNOWN, nil, 'E685: Internal error: tv_get_number(UNKNOWN)', 0},
}) do
- local tv = typvalt(v[1], v[2])
+ -- Using to_cstr, cannot free with tv_clear
+ local tv = ffi.gc(typvalt(v[1], v[2]), nil)
alloc_log:check({})
local emsg = v[3]
local ret = {v[4], not not emsg}
@@ -2721,7 +2731,8 @@ describe('typval.c', function()
{lib.VAR_UNKNOWN, nil, 'E685: Internal error: tv_get_number(UNKNOWN)', -1},
}) do
lib.curwin.w_cursor.lnum = 46
- local tv = typvalt(v[1], v[2])
+ -- Using to_cstr, cannot free with tv_clear
+ local tv = ffi.gc(typvalt(v[1], v[2]), nil)
alloc_log:check({})
local emsg = v[3]
local ret = v[4]
@@ -2749,7 +2760,8 @@ describe('typval.c', function()
{lib.VAR_SPECIAL, {v_special=lib.kSpecialVarFalse}, 'E907: Using a special value as a Float', 0},
{lib.VAR_UNKNOWN, nil, 'E685: Internal error: tv_get_float(UNKNOWN)', 0},
}) do
- local tv = typvalt(v[1], v[2])
+ -- Using to_cstr, cannot free with tv_clear
+ local tv = ffi.gc(typvalt(v[1], v[2]), nil)
alloc_log:check({})
local emsg = v[3]
local ret = v[4]
@@ -2780,7 +2792,9 @@ describe('typval.c', function()
{lib.VAR_SPECIAL, {v_special=lib.kSpecialVarFalse}, nil, 'false'},
{lib.VAR_UNKNOWN, nil, 'E908: using an invalid value as a String', ''},
}) do
- local tv = typvalt(v[1], v[2])
+ -- Using to_cstr in place of Neovim allocated string, cannot
+ -- tv_clear() that.
+ local tv = ffi.gc(typvalt(v[1], v[2]), nil)
alloc_log:check({})
local emsg = v[3]
local ret = v[4]
@@ -2821,7 +2835,8 @@ describe('typval.c', function()
{lib.VAR_SPECIAL, {v_special=lib.kSpecialVarFalse}, nil, 'false'},
{lib.VAR_UNKNOWN, nil, 'E908: using an invalid value as a String', nil},
}) do
- local tv = typvalt(v[1], v[2])
+ -- Using to_cstr, cannot free with tv_clear
+ local tv = ffi.gc(typvalt(v[1], v[2]), nil)
alloc_log:check({})
local emsg = v[3]
local ret = v[4]
@@ -2861,7 +2876,8 @@ describe('typval.c', function()
{lib.VAR_SPECIAL, {v_special=lib.kSpecialVarFalse}, nil, 'false'},
{lib.VAR_UNKNOWN, nil, 'E908: using an invalid value as a String', ''},
}) do
- local tv = typvalt(v[1], v[2])
+ -- Using to_cstr, cannot free with tv_clear
+ local tv = ffi.gc(typvalt(v[1], v[2]), nil)
alloc_log:check({})
local emsg = v[3]
local ret = v[4]
@@ -2902,7 +2918,8 @@ describe('typval.c', function()
{lib.VAR_SPECIAL, {v_special=lib.kSpecialVarFalse}, nil, 'false'},
{lib.VAR_UNKNOWN, nil, 'E908: using an invalid value as a String', nil},
}) do
- local tv = typvalt(v[1], v[2])
+ -- Using to_cstr, cannot free with tv_clear
+ local tv = ffi.gc(typvalt(v[1], v[2]), nil)
alloc_log:check({})
local emsg = v[3]
local ret = v[4]
diff --git a/test/unit/helpers.lua b/test/unit/helpers.lua
index 74f214a231..6d0de5c651 100644
--- a/test/unit/helpers.lua
+++ b/test/unit/helpers.lua
@@ -632,8 +632,9 @@ local function itp_child(wr, func)
collectgarbage('stop')
child_sethook(wr)
local err, emsg = pcall(func)
- debug.sethook()
collectgarbage('restart')
+ collectgarbage()
+ debug.sethook()
emsg = tostring(emsg)
sc.write(wr, trace_end_msg)
if not err then