diff options
author | ZyX <kp-pav@yandex.ru> | 2017-10-16 03:06:34 +0300 |
---|---|---|
committer | ZyX <kp-pav@yandex.ru> | 2017-10-16 03:06:34 +0300 |
commit | 252a76db80dd846f9ccac4d7001697c12c009826 (patch) | |
tree | 329208f3d9c7302143ff6b5114a2fa88373613f6 /test/unit/viml/expressions/parser_spec.lua | |
parent | c03dc13bb74205d15a83ce3bd6ecb6b76b869878 (diff) | |
download | rneovim-252a76db80dd846f9ccac4d7001697c12c009826.tar.gz rneovim-252a76db80dd846f9ccac4d7001697c12c009826.tar.bz2 rneovim-252a76db80dd846f9ccac4d7001697c12c009826.zip |
unittests: Free everything and check for memory leaks
Also improves error reporting.
Diffstat (limited to 'test/unit/viml/expressions/parser_spec.lua')
-rw-r--r-- | test/unit/viml/expressions/parser_spec.lua | 56 |
1 files changed, 35 insertions, 21 deletions
diff --git a/test/unit/viml/expressions/parser_spec.lua b/test/unit/viml/expressions/parser_spec.lua index 54fd54aea8..5f5924c630 100644 --- a/test/unit/viml/expressions/parser_spec.lua +++ b/test/unit/viml/expressions/parser_spec.lua @@ -5,6 +5,8 @@ local viml_helpers = require('test.unit.viml.helpers') local make_enum_conv_tab = helpers.make_enum_conv_tab local child_call_once = helpers.child_call_once +local alloc_log_new = helpers.alloc_log_new +local kvi_destroy = helpers.kvi_destroy local conv_enum = helpers.conv_enum local ptr2key = helpers.ptr2key local cimport = helpers.cimport @@ -23,6 +25,8 @@ local format_luav = global_helpers.format_luav local lib = cimport('./src/nvim/viml/parser/expressions.h') +local alloc_log = alloc_log_new() + local function format_check(expr, flags, ast, hls) -- That forces specific order. print( format_string('\ncheck_parsing(%r, %u, {', expr, flags)) @@ -230,30 +234,40 @@ end) describe('Expressions parser', function() local function check_parsing(str, flags, exp_ast, exp_highlighting_fs) - flags = flags or 0 - - if os.getenv('NVIM_TEST_PARSER_SPEC_PRINT_TEST_CASE') == '1' then - print(str, flags) - end + local err, msg = pcall(function() + flags = flags or 0 - local pstate = new_pstate({str}) - local east = lib.viml_pexpr_parse(pstate, flags) - local ast = east2lua(pstate, east) - local hls = phl2lua(pstate) - if exp_ast == nil then - format_check(str, flags, ast, hls) - return - end - eq(exp_ast, ast) - if exp_highlighting_fs then - local exp_highlighting = {} - local next_col = 0 - for i, h in ipairs(exp_highlighting_fs) do - exp_highlighting[i], next_col = h(next_col) + if os.getenv('NVIM_TEST_PARSER_SPEC_PRINT_TEST_CASE') == '1' then + print(str, flags) + end + alloc_log:check({}) + + local pstate = new_pstate({str}) + local east = lib.viml_pexpr_parse(pstate, flags) + local ast = east2lua(pstate, east) + local hls = phl2lua(pstate) + if exp_ast == nil then + format_check(str, flags, ast, hls) + return + end + eq(exp_ast, ast) + if exp_highlighting_fs then + local exp_highlighting = {} + local next_col = 0 + for i, h in ipairs(exp_highlighting_fs) do + exp_highlighting[i], next_col = h(next_col) + end + eq(exp_highlighting, hls) end - eq(exp_highlighting, hls) + lib.viml_pexpr_free_ast(east) + kvi_destroy(pstate.colors) + alloc_log:clear_tmp_allocs(true) + alloc_log:check({}) + end) + if not err then + msg = format_string('Error while processing test (%r, %u):\n%s', str, flags, msg) + error(msg) end - lib.viml_pexpr_free_ast(east) end local function hl(group, str, shift) return function(next_col) |