From 0ce961891887acc7623162ac3db1fa00156dd2bb Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Mon, 10 Apr 2017 19:12:56 +0200 Subject: test/rmdir(): Remove `readonly` attr on Windows. --- test/functional/helpers.lua | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) (limited to 'test/functional/helpers.lua') diff --git a/test/functional/helpers.lua b/test/functional/helpers.lua index 13b06e7f1b..a27b0e7783 100644 --- a/test/functional/helpers.lua +++ b/test/functional/helpers.lua @@ -428,6 +428,16 @@ local function expect_any(contents) return ok(nil ~= string.find(curbuf_contents(), contents, 1, true)) end +local function win_remove_readonly_attr(abspath) + assert(os_name() == "windows") + local cmd = 'attrib -h -r "'..abspath..'"' + -- TODO: Lua 5.2 io.popen():close() returns better info: + -- http://stackoverflow.com/a/14031974 + -- https://www.lua.org/manual/5.2/manual.html#pdf-file:close + local exitcode = os.execute(cmd) + return (exitcode == 0), exitcode +end + local function do_rmdir(path) if lfs.attributes(path, 'mode') ~= 'directory' then return nil @@ -443,8 +453,21 @@ local function do_rmdir(path) else local ret, err = os.remove(abspath) if not ret then - error('os.remove: '..err) - return nil + if os_name() == "windows" then + -- Remove `readonly` attribute (if any)... + local attr_status, attr_rv = win_remove_readonly_attr(abspath) + if not attr_status then + error('win_remove_readonly_attr: '..attr_rv) + return nil + end + -- ...then try again. + ret, err = os.remove(abspath) + end + + if not ret then + error('os.remove: '..err) + return nil + end end end end -- cgit From 6cbf290d56d618601635d301969c697cfcc2b653 Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Mon, 10 Apr 2017 22:57:49 +0200 Subject: test/rmdir(): fallback to Nvim delete() Lua has too many pitfalls here: - os.execute() requires shell-escaping - os.execute() has breaking changes between Lua 5.1 and 5.2 - No native way in Lua to handle "readonly" etc. on Windows --- test/functional/helpers.lua | 40 +++++++++++----------------------------- 1 file changed, 11 insertions(+), 29 deletions(-) (limited to 'test/functional/helpers.lua') diff --git a/test/functional/helpers.lua b/test/functional/helpers.lua index a27b0e7783..bb46f57691 100644 --- a/test/functional/helpers.lua +++ b/test/functional/helpers.lua @@ -428,45 +428,28 @@ local function expect_any(contents) return ok(nil ~= string.find(curbuf_contents(), contents, 1, true)) end -local function win_remove_readonly_attr(abspath) - assert(os_name() == "windows") - local cmd = 'attrib -h -r "'..abspath..'"' - -- TODO: Lua 5.2 io.popen():close() returns better info: - -- http://stackoverflow.com/a/14031974 - -- https://www.lua.org/manual/5.2/manual.html#pdf-file:close - local exitcode = os.execute(cmd) - return (exitcode == 0), exitcode -end - local function do_rmdir(path) if lfs.attributes(path, 'mode') ~= 'directory' then - return nil + return -- Don't complain. end for file in lfs.dir(path) do if file ~= '.' and file ~= '..' then local abspath = path..'/'..file if lfs.attributes(abspath, 'mode') == 'directory' then - local ret = do_rmdir(abspath) -- recurse - if not ret then - return nil - end + do_rmdir(abspath) -- recurse else local ret, err = os.remove(abspath) if not ret then - if os_name() == "windows" then - -- Remove `readonly` attribute (if any)... - local attr_status, attr_rv = win_remove_readonly_attr(abspath) - if not attr_status then - error('win_remove_readonly_attr: '..attr_rv) - return nil - end - -- ...then try again. - ret, err = os.remove(abspath) - end - - if not ret then + if not session then error('os.remove: '..err) - return nil + else + -- Try Nvim delete(): it handles `readonly` attribute on Windows, + -- and avoids Lua cross-version/platform incompatibilities. + if -1 == nvim_call('delete', abspath) then + local hint = (os_name() == 'windows' + and ' (hint: try :%bwipeout! before rmdir())' or '') + error('delete() failed'..hint..': '..abspath) + end end end end @@ -476,7 +459,6 @@ local function do_rmdir(path) if not ret then error('lfs.rmdir('..path..'): '..err) end - return ret end local function rmdir(path) -- cgit From 2d296387447cbf89308a4a136cce866e4691cca8 Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Mon, 10 Apr 2017 01:38:20 +0200 Subject: test: `:file {name}` --- test/functional/helpers.lua | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) (limited to 'test/functional/helpers.lua') diff --git a/test/functional/helpers.lua b/test/functional/helpers.lua index bb46f57691..7edb2381e8 100644 --- a/test/functional/helpers.lua +++ b/test/functional/helpers.lua @@ -32,20 +32,15 @@ local nvim_set = 'set shortmess+=I background=light noswapfile noautoindent' ..' belloff= noshowcmd noruler nomore' local nvim_argv = {nvim_prog, '-u', 'NONE', '-i', 'NONE', '-N', '--cmd', nvim_set, '--embed'} - -local mpack = require('mpack') - -local tmpname = global_helpers.tmpname -local uname = global_helpers.uname - --- Formulate a path to the directory containing nvim. We use this to --- help run test executables. It helps to keep the tests working, even --- when the build is not in the default location. +-- Directory containing nvim. local nvim_dir = nvim_prog:gsub("[/\\][^/\\]+$", "") if nvim_dir == nvim_prog then nvim_dir = "." end +local mpack = require('mpack') +local tmpname = global_helpers.tmpname +local uname = global_helpers.uname local prepend_argv if os.getenv('VALGRIND') then -- cgit From 799443c9942fa145320d9cc7c4638bdaa8c8d67a Mon Sep 17 00:00:00 2001 From: Rui Abreu Ferreira Date: Sat, 25 Mar 2017 22:47:38 +0000 Subject: win/test: Enable more system() tests --- test/functional/helpers.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test/functional/helpers.lua') diff --git a/test/functional/helpers.lua b/test/functional/helpers.lua index 7edb2381e8..5882758b5a 100644 --- a/test/functional/helpers.lua +++ b/test/functional/helpers.lua @@ -348,7 +348,7 @@ end local function set_shell_powershell() source([[ set shell=powershell shellquote=\" shellpipe=\| shellredir=> - set shellcmdflag=\ -ExecutionPolicy\ RemoteSigned\ -Command + set shellcmdflag=\ -NoProfile\ -ExecutionPolicy\ RemoteSigned\ -Command let &shellxquote=' ' ]]) end -- cgit From 48f0542ad6f923443ab4bba858aae2d9558f8d76 Mon Sep 17 00:00:00 2001 From: Björn Linse Date: Fri, 21 Apr 2017 10:59:06 +0200 Subject: tests: detect invalid helpers.sleep --- test/functional/helpers.lua | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'test/functional/helpers.lua') diff --git a/test/functional/helpers.lua b/test/functional/helpers.lua index 5882758b5a..84e81c5af4 100644 --- a/test/functional/helpers.lua +++ b/test/functional/helpers.lua @@ -392,7 +392,16 @@ end -- sleeps the test runner (_not_ the nvim instance) local function sleep(ms) - run(nil, nil, nil, ms) + local function notification_cb(method, args) + local _ = args + if method == "redraw" then + error("helpers.sleep() called while screen is attached. ".. + "Use screen:sleep(...) instead") + end + return true + end + + run(nil, notification_cb, nil, ms) end local function curbuf_contents() -- cgit From 3ea10077534cb1dcb1597ffcf85e601fa0c0e27b Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Mon, 13 Mar 2017 15:02:37 +0100 Subject: api: nvim_get_mode() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Asynchronous API functions are served immediately, which means pending input could change the state of Nvim shortly after an async API function result is returned. nvim_get_mode() is different: - If RPCs are known to be blocked, it responds immediately (without flushing the input/event queue) - else it is handled just-in-time before waiting for input, after pending input was processed. This makes the result more reliable (but not perfect). Internally this is handled as a special case, but _semantically_ nothing has changed: API users never know when input flushes, so this internal special-case doesn't violate that. As far as API users are concerned, nvim_get_mode() is just another asynchronous API function. In all cases nvim_get_mode() never blocks for more than the time it takes to flush the input/event queue (~µs). Note: This doesn't address #6166; nvim_get_mode() will provoke #6166 if e.g. `d` is operator-pending. Closes #6159 --- test/functional/helpers.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'test/functional/helpers.lua') diff --git a/test/functional/helpers.lua b/test/functional/helpers.lua index 0f30910450..2919165280 100644 --- a/test/functional/helpers.lua +++ b/test/functional/helpers.lua @@ -385,9 +385,9 @@ local function curbuf(method, ...) end local function wait() - -- Execute 'vim_eval' (a deferred function) to block + -- Execute 'nvim_eval' (a deferred function) to block -- until all pending input is processed. - session:request('vim_eval', '1') + session:request('nvim_eval', '1') end -- sleeps the test runner (_not_ the nvim instance) -- cgit