From a3ea05c1e5965ca23b1b926c41b00597e9d0211c Mon Sep 17 00:00:00 2001 From: ZyX Date: Sat, 21 Jan 2017 00:00:47 +0300 Subject: functests: Add some tests --- test/helpers.lua | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'test/helpers.lua') diff --git a/test/helpers.lua b/test/helpers.lua index e5224349c2..18f47e950b 100644 --- a/test/helpers.lua +++ b/test/helpers.lua @@ -225,6 +225,14 @@ local function which(exe) end end +local function shallowcopy(orig) + local copy = {} + for orig_key, orig_value in pairs(orig) do + copy[orig_key] = orig_value + end + return copy +end + return { eq = eq, neq = neq, @@ -238,4 +246,5 @@ return { check_cores = check_cores, hasenv = hasenv, which = which, + shallowcopy = shallowcopy, } -- cgit From ffaf7c7521399826d9a32b12a1180bcd162f88be Mon Sep 17 00:00:00 2001 From: ZyX Date: Sun, 5 Mar 2017 01:09:55 +0300 Subject: unittests: Add tv_dict_item_{alloc,free} tests --- test/helpers.lua | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'test/helpers.lua') diff --git a/test/helpers.lua b/test/helpers.lua index e5224349c2..1a86effa1c 100644 --- a/test/helpers.lua +++ b/test/helpers.lua @@ -225,6 +225,19 @@ local function which(exe) end end +local function concat_tables(...) + local ret = {} + for i = 1, select('#', ...) do + local tbl = select(i, ...) + if tbl then + for _, v in ipairs(tbl) do + ret[#ret + 1] = v + end + end + end + return ret +end + return { eq = eq, neq = neq, @@ -238,4 +251,5 @@ return { check_cores = check_cores, hasenv = hasenv, which = which, + concat_tables = concat_tables, } -- cgit From 1ea9ebf112d6c9d6355038afb4aaee794187cb23 Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Wed, 29 Mar 2017 20:07:39 +0200 Subject: test: Use workspace-local temp directory. Closes #6291 --- test/helpers.lua | 41 +++++++++++++++++++++++++++-------------- 1 file changed, 27 insertions(+), 14 deletions(-) (limited to 'test/helpers.lua') diff --git a/test/helpers.lua b/test/helpers.lua index 1a86effa1c..82451bc61d 100644 --- a/test/helpers.lua +++ b/test/helpers.lua @@ -106,20 +106,33 @@ local uname = (function() end) end)() -local function tmpname() - local fname = os.tmpname() - if uname() == 'Windows' and fname:sub(1, 2) == '\\s' then - -- In Windows tmpname() returns a filename starting with - -- special sequence \s, prepend $TEMP path - local tmpdir = os.getenv('TEMP') - return tmpdir..fname - elseif fname:match('^/tmp') and uname() == 'Darwin' then - -- In OS X /tmp links to /private/tmp - return '/private'..fname - else - return fname - end -end +local tmpname = (function() + local seq = 0 + local tmpdir = os.getenv('TMPDIR') and os.getenv('TMPDIR') or os.getenv('TEMP') + -- Is $TMPDIR defined local to the project workspace? + local in_workspace = not not (tmpdir and string.find(tmpdir, 'Xtest')) + return (function() + if in_workspace then + -- Cannot control os.tmpname() dir, so hack our own tmpname() impl. + seq = seq + 1 + local fname = tmpdir..'/nvim-test-lua-'..seq + io.open(fname, 'w'):close() + return fname + else + local fname = os.tmpname() + if uname() == 'Windows' and fname:sub(1, 2) == '\\s' then + -- In Windows tmpname() returns a filename starting with + -- special sequence \s, prepend $TEMP path + return tmpdir..fname + elseif fname:match('^/tmp') and uname() == 'Darwin' then + -- In OS X /tmp links to /private/tmp + return '/private'..fname + else + return fname + end + end + end) +end)() local function map(func, tab) local rettab = {} -- cgit From 9dd0d4f8b9217f711fff32e9f47674e556a8fab0 Mon Sep 17 00:00:00 2001 From: ZyX Date: Sat, 1 Apr 2017 12:52:28 +0300 Subject: unittests: Add trace description right to the error message --- test/helpers.lua | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'test/helpers.lua') diff --git a/test/helpers.lua b/test/helpers.lua index 82451bc61d..3fc10e9e30 100644 --- a/test/helpers.lua +++ b/test/helpers.lua @@ -251,6 +251,28 @@ local function concat_tables(...) return ret end +local function dedent(str) + -- find minimum common indent across lines + local indent = nil + for line in str:gmatch('[^\n]+') do + local line_indent = line:match('^%s+') or '' + if indent == nil or #line_indent < #indent then + indent = line_indent + end + end + if indent == nil or #indent == 0 then + -- no minimum common indent + return str + end + -- create a pattern for the indent + indent = indent:gsub('%s', '[ \t]') + -- strip it from the first line + str = str:gsub('^'..indent, '') + -- strip it from the remaining lines + str = str:gsub('[\n]'..indent, '\n') + return str +end + return { eq = eq, neq = neq, @@ -265,4 +287,5 @@ return { hasenv = hasenv, which = which, concat_tables = concat_tables, + dedent = dedent, } -- cgit From a83511d1a19d6277f8258f2c5b970c936f0bc56e Mon Sep 17 00:00:00 2001 From: ZyX Date: Thu, 6 Apr 2017 08:23:33 +0300 Subject: unittests: Move checking cores to check_child_err --- test/helpers.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'test/helpers.lua') diff --git a/test/helpers.lua b/test/helpers.lua index 3fc10e9e30..beef53b5a9 100644 --- a/test/helpers.lua +++ b/test/helpers.lua @@ -162,7 +162,7 @@ end local tests_skipped = 0 -local function check_cores(app) +local function check_cores(app, force) app = app or 'build/bin/nvim' local initial_path, re, exc_re local gdb_db_cmd = 'gdb -n -batch -ex "thread apply all bt full" "$_NVIM_TEST_APP" -c "$_NVIM_TEST_CORE"' @@ -188,7 +188,7 @@ local function check_cores(app) random_skip = true end -- Finding cores takes too much time on linux - if random_skip and math.random() < 0.9 then + if not force and random_skip and math.random() < 0.9 then tests_skipped = tests_skipped + 1 return end -- cgit From 26bf6e6f6f8819a758611a88e0c0b04e38d4b915 Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Sun, 9 Apr 2017 15:49:31 +0200 Subject: test/check_cores(): Skip workspace-local temp dir. (#6483) Avoids this error: ./test/helpers.lua:27: cannot open ./Xtest-tmpdir/nvimfqH9dL: No such file or directory stack traceback: ./test/helpers.lua:27: in function 'glob' ./test/helpers.lua:195: in function 'check_cores' ./test/functional/helpers.lua:628: in function <./test/functional/helpers.lua:626> --- test/helpers.lua | 36 +++++++++++++++++++++++++++--------- 1 file changed, 27 insertions(+), 9 deletions(-) (limited to 'test/helpers.lua') diff --git a/test/helpers.lua b/test/helpers.lua index beef53b5a9..d0b1ad552b 100644 --- a/test/helpers.lua +++ b/test/helpers.lua @@ -17,18 +17,28 @@ local ok = function(res) return assert.is_true(res) end +-- initial_path: directory to recurse into +-- re: include pattern (string) +-- exc_re: exclude pattern(s) (string or table) local function glob(initial_path, re, exc_re) + exc_re = type(exc_re) == 'table' and exc_re or { exc_re } local paths_to_check = {initial_path} local ret = {} local checked_files = {} + local function is_excluded(path) + for _, pat in pairs(exc_re) do + if path:match(pat) then return true end + end + return false + end + while #paths_to_check > 0 do local cur_path = paths_to_check[#paths_to_check] paths_to_check[#paths_to_check] = nil for e in lfs.dir(cur_path) do local full_path = cur_path .. '/' .. e local checked_path = full_path:sub(#initial_path + 1) - if ((not exc_re or not checked_path:match(exc_re)) - and e:sub(1, 1) ~= '.') then + if (not is_excluded(checked_path)) and e:sub(1, 1) ~= '.' then local attrs = lfs.attributes(full_path) if attrs then local check_key = attrs.dev .. ':' .. tostring(attrs.ino) @@ -106,13 +116,20 @@ local uname = (function() end) end)() +local function tmpdir_get() + return os.getenv('TMPDIR') and os.getenv('TMPDIR') or os.getenv('TEMP') +end + +-- Is temp directory `dir` defined local to the project workspace? +local function tmpdir_is_local(dir) + return not not (dir and string.find(dir, 'Xtest')) +end + local tmpname = (function() local seq = 0 - local tmpdir = os.getenv('TMPDIR') and os.getenv('TMPDIR') or os.getenv('TEMP') - -- Is $TMPDIR defined local to the project workspace? - local in_workspace = not not (tmpdir and string.find(tmpdir, 'Xtest')) + local tmpdir = tmpdir_get() return (function() - if in_workspace then + if tmpdir_is_local(tmpdir) then -- Cannot control os.tmpname() dir, so hack our own tmpname() impl. seq = seq + 1 local fname = tmpdir..'/nvim-test-lua-'..seq @@ -168,22 +185,23 @@ local function check_cores(app, force) local gdb_db_cmd = 'gdb -n -batch -ex "thread apply all bt full" "$_NVIM_TEST_APP" -c "$_NVIM_TEST_CORE"' local lldb_db_cmd = 'lldb -Q -o "bt all" -f "$_NVIM_TEST_APP" -c "$_NVIM_TEST_CORE"' local random_skip = false + local local_tmpdir = tmpdir_is_local(tmpdir_get()) and tmpdir_get() or nil local db_cmd if hasenv('NVIM_TEST_CORE_GLOB_DIRECTORY') then initial_path = os.getenv('NVIM_TEST_CORE_GLOB_DIRECTORY') re = os.getenv('NVIM_TEST_CORE_GLOB_RE') - exc_re = os.getenv('NVIM_TEST_CORE_EXC_RE') + exc_re = { os.getenv('NVIM_TEST_CORE_EXC_RE'), local_tmpdir } db_cmd = os.getenv('NVIM_TEST_CORE_DB_CMD') or gdb_db_cmd random_skip = os.getenv('NVIM_TEST_CORE_RANDOM_SKIP') elseif os.getenv('TRAVIS_OS_NAME') == 'osx' then initial_path = '/cores' re = nil - exc_re = nil + exc_re = { local_tmpdir } db_cmd = lldb_db_cmd else initial_path = '.' re = '/core[^/]*$' - exc_re = '^/%.deps$' + exc_re = { '^/%.deps$', local_tmpdir } db_cmd = gdb_db_cmd random_skip = true end -- cgit From 58d2ce9bdbb6feab7176f451ca0248c78606aa2e Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Fri, 14 Apr 2017 20:34:54 +0200 Subject: test: check_cores(): Escape $TMPDIR path. (#6520) Lua string:match() considers hyphen to be a special char, we want the path to be a literal match. Also remove "./", etc. References #6483 --- test/helpers.lua | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'test/helpers.lua') diff --git a/test/helpers.lua b/test/helpers.lua index d0b1ad552b..d60d5ba242 100644 --- a/test/helpers.lua +++ b/test/helpers.lua @@ -32,6 +32,9 @@ local function glob(initial_path, re, exc_re) return false end + if is_excluded(initial_path) then + return ret + end while #paths_to_check > 0 do local cur_path = paths_to_check[#paths_to_check] paths_to_check[#paths_to_check] = nil @@ -185,7 +188,11 @@ local function check_cores(app, force) local gdb_db_cmd = 'gdb -n -batch -ex "thread apply all bt full" "$_NVIM_TEST_APP" -c "$_NVIM_TEST_CORE"' local lldb_db_cmd = 'lldb -Q -o "bt all" -f "$_NVIM_TEST_APP" -c "$_NVIM_TEST_CORE"' local random_skip = false - local local_tmpdir = tmpdir_is_local(tmpdir_get()) and tmpdir_get() or nil + -- Workspace-local $TMPDIR, scrubbed and pattern-escaped. + -- "./Xtest-tmpdir/" => "Xtest%-tmpdir" + local local_tmpdir = (tmpdir_is_local(tmpdir_get()) + and tmpdir_get():gsub('^[ ./]+',''):gsub('%/+$',''):gsub('([^%w])', '%%%1') + or nil) local db_cmd if hasenv('NVIM_TEST_CORE_GLOB_DIRECTORY') then initial_path = os.getenv('NVIM_TEST_CORE_GLOB_DIRECTORY') -- cgit From 607dc3e0f9119fa4939d9cfa8ee1f7f764c6e530 Mon Sep 17 00:00:00 2001 From: ZyX Date: Tue, 20 Jun 2017 18:17:19 +0300 Subject: functests: Add tests --- test/helpers.lua | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'test/helpers.lua') diff --git a/test/helpers.lua b/test/helpers.lua index 7a0e4b8c3c..260f10002e 100644 --- a/test/helpers.lua +++ b/test/helpers.lua @@ -284,7 +284,7 @@ local function concat_tables(...) return ret end -local function dedent(str) +local function dedent(str, leave_indent) -- find minimum common indent across lines local indent = nil for line in str:gmatch('[^\n]+') do @@ -297,12 +297,13 @@ local function dedent(str) -- no minimum common indent return str end + local left_indent = (' '):rep(leave_indent or 0) -- create a pattern for the indent indent = indent:gsub('%s', '[ \t]') -- strip it from the first line - str = str:gsub('^'..indent, '') + str = str:gsub('^'..indent, left_indent) -- strip it from the remaining lines - str = str:gsub('[\n]'..indent, '\n') + str = str:gsub('[\n]'..indent, '\n' .. left_indent) return str end -- cgit From 753d0091e8f5d3358eeb2f53288b5b07a8f13a7f Mon Sep 17 00:00:00 2001 From: Björn Linse Date: Tue, 5 Sep 2017 17:38:14 +0200 Subject: core dumps: don't use pipe, it does not work --- test/helpers.lua | 17 ++--------------- 1 file changed, 2 insertions(+), 15 deletions(-) (limited to 'test/helpers.lua') diff --git a/test/helpers.lua b/test/helpers.lua index 260f10002e..123dd111ee 100644 --- a/test/helpers.lua +++ b/test/helpers.lua @@ -225,21 +225,8 @@ local function check_cores(app, force) local esigns = ('='):rep(len / 2) out:write(('\n%s Core file %s %s\n'):format(esigns, core, esigns)) out:flush() - local pipe = io.popen( - db_cmd:gsub('%$_NVIM_TEST_APP', app):gsub('%$_NVIM_TEST_CORE', core) - .. ' 2>&1', 'r') - if pipe then - local bt = pipe:read('*a') - if bt then - out:write(bt) - out:write('\n') - else - out:write('Failed to read from the pipe\n') - end - else - out:write('Failed to create pipe\n') - end - out:flush() + os.execute(db_cmd:gsub('%$_NVIM_TEST_APP', app):gsub('%$_NVIM_TEST_CORE', core) .. ' 2>&1') + out:write('\n') found_cores = found_cores + 1 os.remove(core) end -- cgit