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 +++++++++++++++++++++++++-- test/functional/spell/spellfile_spec.lua | 4 +++- 2 files changed, 28 insertions(+), 3 deletions(-) (limited to 'test/functional') 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 diff --git a/test/functional/spell/spellfile_spec.lua b/test/functional/spell/spellfile_spec.lua index e7cd10d2ac..afd2c1bce4 100644 --- a/test/functional/spell/spellfile_spec.lua +++ b/test/functional/spell/spellfile_spec.lua @@ -5,6 +5,7 @@ local eq = helpers.eq local clear = helpers.clear local meths = helpers.meths local exc_exec = helpers.exc_exec +local rmdir = helpers.rmdir local write_file = helpers.write_file local testdir = 'Xtest-functional-spell-spellfile.d' @@ -12,11 +13,12 @@ local testdir = 'Xtest-functional-spell-spellfile.d' describe('spellfile', function() before_each(function() clear() + rmdir(testdir) lfs.mkdir(testdir) lfs.mkdir(testdir .. '/spell') end) after_each(function() - lfs.rmdir(testdir) + rmdir(testdir) end) -- ┌ Magic string (#VIMSPELLMAGIC) -- │ ┌ Spell file version (#VIMSPELLVERSION) -- 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') 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/ex_cmds/file_spec.lua | 35 +++++++++++++++++++++++++++++++++++ test/functional/helpers.lua | 13 ++++--------- 2 files changed, 39 insertions(+), 9 deletions(-) create mode 100644 test/functional/ex_cmds/file_spec.lua (limited to 'test/functional') diff --git a/test/functional/ex_cmds/file_spec.lua b/test/functional/ex_cmds/file_spec.lua new file mode 100644 index 0000000000..771c283134 --- /dev/null +++ b/test/functional/ex_cmds/file_spec.lua @@ -0,0 +1,35 @@ +local helpers = require('test.functional.helpers')(after_each) +local lfs = require('lfs') +local clear = helpers.clear +local command = helpers.command +local eq = helpers.eq +local funcs = helpers.funcs +local rmdir = helpers.rmdir + +describe(':file', function() + local swapdir = lfs.currentdir()..'/Xtest-file_spec' + before_each(function() + clear() + rmdir(swapdir) + lfs.mkdir(swapdir) + end) + after_each(function() + command('%bwipeout!') + rmdir(swapdir) + end) + + it("rename does not lose swapfile #6487", function() + local testfile = 'test-file_spec' + local testfile_renamed = testfile..'-renamed' + -- Note: `set swapfile` *must* go after `set directory`: otherwise it may + -- attempt to create a swapfile in different directory. + command('set directory^='..swapdir..'//') + command('set swapfile fileformat=unix undolevels=-1') + + command('edit! '..testfile) + -- Before #6487 this gave "E301: Oops, lost the swap file !!!" on Windows. + command('file '..testfile_renamed) + eq(testfile_renamed..'.swp', + string.match(funcs.execute('swapname'), '[^%%]+$')) + end) +end) 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 dab3f86d092706514bd207dd9900740bab785859 Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Mon, 10 Apr 2017 19:53:19 +0200 Subject: win/test: Enable recover_spec.lua --- test/functional/ex_cmds/recover_spec.lua | 41 ++++++++++++++++---------------- 1 file changed, 20 insertions(+), 21 deletions(-) (limited to 'test/functional') diff --git a/test/functional/ex_cmds/recover_spec.lua b/test/functional/ex_cmds/recover_spec.lua index 36bf85015a..cb68c29b9a 100644 --- a/test/functional/ex_cmds/recover_spec.lua +++ b/test/functional/ex_cmds/recover_spec.lua @@ -1,12 +1,11 @@ --- Tests for :recover - local helpers = require('test.functional.helpers')(after_each) local lfs = require('lfs') local feed_command, eq, clear, eval, feed, expect, source = helpers.feed_command, helpers.eq, helpers.clear, helpers.eval, helpers.feed, helpers.expect, helpers.source - -if helpers.pending_win32(pending) then return end +local command = helpers.command +local ok = helpers.ok +local rmdir = helpers.rmdir describe(':recover', function() before_each(clear) @@ -23,30 +22,29 @@ describe(':preserve', function() local swapdir = lfs.currentdir()..'/testdir_recover_spec' before_each(function() clear() - helpers.rmdir(swapdir) + rmdir(swapdir) lfs.mkdir(swapdir) end) after_each(function() - helpers.rmdir(swapdir) + command('%bwipeout!') + rmdir(swapdir) end) it("saves to custom 'directory' and (R)ecovers (issue #1836)", function() local testfile = 'testfile_recover_spec' + -- Put swapdir at the start of the 'directory' list. #1836 -- Note: `set swapfile` *must* go after `set directory`: otherwise it may -- attempt to create a swapfile in different directory. local init = [[ - set directory^=]]..swapdir..[[// + set directory^=]]..swapdir:gsub([[\]], [[\\]])..[[// set swapfile fileformat=unix undolevels=-1 ]] source(init) - feed_command('set swapfile fileformat=unix undolevels=-1') - -- Put swapdir at the start of the 'directory' list. #1836 - feed_command('set directory^='..swapdir..'//') - feed_command('edit '..testfile) + command('edit! '..testfile) feed('isometext') - feed_command('preserve') - source('redir => g:swapname | swapname | redir END') + command('preserve') + source('redir => g:swapname | silent swapname | redir END') local swappath1 = eval('g:swapname') @@ -59,19 +57,20 @@ describe(':preserve', function() source(init) -- Use the "SwapExists" event to choose the (R)ecover choice at the dialog. - feed_command('autocmd SwapExists * let v:swapchoice = "r"') - feed_command('silent edit '..testfile) - source('redir => g:swapname | swapname | redir END') + command('autocmd SwapExists * let v:swapchoice = "r"') + command('silent edit! '..testfile) + source('redir => g:swapname | silent swapname | redir END') local swappath2 = eval('g:swapname') + expect('sometext') -- swapfile from session 1 should end in .swp - assert(testfile..'.swp' == string.match(swappath1, '[^%%]+$')) - + eq(testfile..'.swp', string.match(swappath1, '[^%%]+$')) -- swapfile from session 2 should end in .swo - assert(testfile..'.swo' == string.match(swappath2, '[^%%]+$')) - - expect('sometext') + eq(testfile..'.swo', string.match(swappath2, '[^%%]+$')) + -- Verify that :swapname was not truncated (:help 'shortmess'). + ok(nil == string.find(swappath1, '%.%.%.')) + ok(nil == string.find(swappath2, '%.%.%.')) end) end) -- cgit From 119f0ca85463b7d9fb7dffe47d0fcee2c9604c53 Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Mon, 10 Apr 2017 21:54:19 +0200 Subject: test: helpers.execute() => helpers.feed_command() --- test/functional/normal/lang_spec.lua | 6 +++--- test/functional/ui/inccommand_spec.lua | 24 ++++++++++++------------ test/functional/ui/screen.lua | 19 +++++++------------ 3 files changed, 22 insertions(+), 27 deletions(-) (limited to 'test/functional') diff --git a/test/functional/normal/lang_spec.lua b/test/functional/normal/lang_spec.lua index 464b85d684..1da1d4679d 100644 --- a/test/functional/normal/lang_spec.lua +++ b/test/functional/normal/lang_spec.lua @@ -1,6 +1,6 @@ local helpers = require('test.functional.helpers')(after_each) local clear, insert, eq = helpers.clear, helpers.insert, helpers.eq -local execute, expect = helpers.execute, helpers.expect +local command, expect = helpers.command, helpers.expect local feed, eval = helpers.feed, helpers.eval local exc_exec = helpers.exc_exec @@ -32,7 +32,7 @@ describe('gu and gU', function() end before_each(function() - execute('lang ctype tr_TR.UTF-8') + command('lang ctype tr_TR.UTF-8') end) it('with default casemap', function() @@ -46,7 +46,7 @@ describe('gu and gU', function() end) it('with casemap=""', function() - execute('set casemap=') + command('set casemap=') -- expect Turkish locale behavior insert("iI") feed("VgU") diff --git a/test/functional/ui/inccommand_spec.lua b/test/functional/ui/inccommand_spec.lua index b7a33cb64d..a7be1a9dc8 100644 --- a/test/functional/ui/inccommand_spec.lua +++ b/test/functional/ui/inccommand_spec.lua @@ -1,6 +1,7 @@ local helpers = require('test.functional.helpers')(after_each) local Screen = require('test.functional.ui.screen') local clear = helpers.clear +local command = helpers.command local curbufmeths = helpers.curbufmeths local eq = helpers.eq local eval = helpers.eval @@ -21,9 +22,9 @@ local default_text = [[ local function common_setup(screen, inccommand, text) if screen then - feed_command("syntax on") - feed_command("set nohlsearch") - feed_command("hi Substitute guifg=red guibg=yellow") + command("syntax on") + command("set nohlsearch") + command("hi Substitute guifg=red guibg=yellow") screen:attach() screen:set_default_attr_ids({ [1] = {foreground = Screen.colors.Fuchsia}, @@ -46,7 +47,7 @@ local function common_setup(screen, inccommand, text) }) end - feed_command("set inccommand=" .. (inccommand and inccommand or "")) + command("set inccommand=" .. (inccommand and inccommand or "")) if text then insert(text) @@ -456,7 +457,7 @@ describe(":substitute, 'inccommand' preserves undo", function() insert("X") feed("IY") feed(":%s/tw/MO/") - -- execute("undo") here would cause "Press ENTER". + -- feed_command("undo") here would cause "Press ENTER". feed("u") expect(default_text:gsub("Inc", "XInc")) feed("u") @@ -514,7 +515,7 @@ describe(":substitute, 'inccommand' preserves undo", function() feed("Ay") feed("Az") feed(":%s/tw/AR") - -- using execute("undo") here will result in a "Press ENTER" prompt + -- feed_command("undo") here would cause "Press ENTER". feed("u") expect(default_text:gsub("lines", "linesxy")) feed("u") @@ -603,7 +604,7 @@ describe(":substitute, 'inccommand' preserves undo", function() feed_command("set undolevels=-1") feed(":%s/tw/MO/g") - -- using execute("undo") here will result in a "Press ENTER" prompt + -- feed_command("undo") here will result in a "Press ENTER" prompt feed("u") if case == "split" then screen:expect([[ @@ -804,7 +805,6 @@ describe(":substitute, inccommand=split", function() it('does not show split window for :s/', function() feed("2gg") feed(":s/tw") - wait() screen:expect([[ Inc substitution on | two lines | @@ -1291,14 +1291,14 @@ describe("'inccommand' and :cnoremap", function() it('work with remapped characters', function() for _, case in pairs(cases) do refresh(case) - local command = "%s/lines/LINES/g" + local cmd = "%s/lines/LINES/g" - for i = 1, string.len(command) do - local c = string.sub(command, i, i) + for i = 1, string.len(cmd) do + local c = string.sub(cmd, i, i) feed_command("cnoremap ".. c .. " " .. c) end - feed_command(command) + feed_command(cmd) expect([[ Inc substitution on two LINES diff --git a/test/functional/ui/screen.lua b/test/functional/ui/screen.lua index 2f2cc85dab..afbcd222c7 100644 --- a/test/functional/ui/screen.lua +++ b/test/functional/ui/screen.lua @@ -284,18 +284,13 @@ function Screen:wait(check, timeout) if failure_after_success then print([[ -Warning: Screen changes have been received after the expected state was seen. -This is probably due to an indeterminism in the test. Try adding -`wait()` (or even a separate `screen:expect(...)`) at a point of possible -indeterminism, typically in between a `feed()` or `execute()` which is non- -synchronous, and a synchronous api call. - -Note that sometimes a `wait` can trigger redraws and consequently generate more -indeterminism. If adding `wait` calls seems to increase the frequency of these -messages, try removing every `wait` call in the test. - -If everything else fails, use Screen:redraw_debug to help investigate what is - causing the problem. + +Warning: Screen changes were received after the expected state. This indicates +indeterminism in the test. Try adding wait() (or screen:expect(...)) between +asynchronous (feed(), nvim_input()) and synchronous API calls. + - Use Screen:redraw_debug() to investigate the problem. + - wait() can trigger redraws and consequently generate more indeterminism. + In that case try removing every wait(). ]]) local tb = debug.traceback() local index = string.find(tb, '\n%s*%[C]') -- cgit From 69775f603f0b21cb28adec99daaaa9356581ddd0 Mon Sep 17 00:00:00 2001 From: Björn Linse Date: Mon, 10 Apr 2017 19:48:45 +0200 Subject: ci: install Turkish locale and make locale tests more reliable --- test/functional/normal/lang_spec.lua | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) (limited to 'test/functional') diff --git a/test/functional/normal/lang_spec.lua b/test/functional/normal/lang_spec.lua index 1da1d4679d..24d1262f5f 100644 --- a/test/functional/normal/lang_spec.lua +++ b/test/functional/normal/lang_spec.lua @@ -17,13 +17,7 @@ describe('gu and gU', function() end) describe('works in Turkish locale', function() - if helpers.pending_win32(pending) then return end - clear() - if eval('has("mac")') ~= 0 then - pending("not yet on macOS", function() end) - return - end local err = exc_exec('lang ctype tr_TR.UTF-8') if err ~= 0 then @@ -47,13 +41,23 @@ describe('gu and gU', function() it('with casemap=""', function() command('set casemap=') - -- expect Turkish locale behavior - insert("iI") - feed("VgU") - expect("İI") - feed("Vgu") - expect("iı") + -- expect either Turkish locale behavior or ASCII behavior + local iupper = eval("toupper('i')") + if iupper == "İ" then + insert("iI") + feed("VgU") + expect("İI") + feed("Vgu") + expect("iı") + elseif iupper == "I" then + insert("iI") + feed("VgU") + expect("II") + feed("Vgu") + expect("ii") + else + error("expected toupper('i') to be either 'I' or 'İ'") + end end) - end) end) -- cgit From d6e5f94ae945308d96be414c9c1fb3f0ae71355e Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Fri, 24 Mar 2017 02:54:50 +0100 Subject: win: defaults: 'shellredir', 'shellxquote', 'shellxescape' --- test/functional/terminal/edit_spec.lua | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'test/functional') diff --git a/test/functional/terminal/edit_spec.lua b/test/functional/terminal/edit_spec.lua index 42a5c768bb..f691a58f6c 100644 --- a/test/functional/terminal/edit_spec.lua +++ b/test/functional/terminal/edit_spec.lua @@ -8,6 +8,7 @@ local command = helpers.command local meths = helpers.meths local clear = helpers.clear local eq = helpers.eq +local iswin = helpers.iswin describe(':edit term://*', function() local get_screen = function(columns, lines) @@ -46,7 +47,7 @@ describe(':edit term://*', function() local winheight = curwinmeths.get_height() local buf_cont_start = rep_size - sb - winheight + 2 local function bufline (i) - return ('%d: foobar'):format(i) + return (iswin() and '%d: (foobar)' or '%d: foobar'):format(i) end for i = buf_cont_start,(rep_size - 1) do bufcontents[#bufcontents + 1] = bufline(i) -- 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/eval/system_spec.lua | 74 ++++++++++++++++++++++++++---------- test/functional/helpers.lua | 2 +- 2 files changed, 54 insertions(+), 22 deletions(-) (limited to 'test/functional') diff --git a/test/functional/eval/system_spec.lua b/test/functional/eval/system_spec.lua index bf95752e3b..83d8028b56 100644 --- a/test/functional/eval/system_spec.lua +++ b/test/functional/eval/system_spec.lua @@ -94,17 +94,26 @@ describe('system()', function() end) end) - if helpers.pending_win32(pending) then return end - it('sets v:shell_error', function() - eval([[system("sh -c 'exit'")]]) - eq(0, eval('v:shell_error')) - eval([[system("sh -c 'exit 1'")]]) - eq(1, eval('v:shell_error')) - eval([[system("sh -c 'exit 5'")]]) - eq(5, eval('v:shell_error')) - eval([[system('this-should-not-exist')]]) - eq(127, eval('v:shell_error')) + if helpers.os_name() == 'windows' then + eval([[system("cmd.exe /c exit")]]) + eq(0, eval('v:shell_error')) + eval([[system("cmd.exe /c exit 1")]]) + eq(1, eval('v:shell_error')) + eval([[system("cmd.exe /c exit 5")]]) + eq(5, eval('v:shell_error')) + eval([[system('this-should-not-exist')]]) + eq(1, eval('v:shell_error')) + else + eval([[system("sh -c 'exit'")]]) + eq(0, eval('v:shell_error')) + eval([[system("sh -c 'exit 1'")]]) + eq(1, eval('v:shell_error')) + eval([[system("sh -c 'exit 5'")]]) + eq(5, eval('v:shell_error')) + eval([[system('this-should-not-exist')]]) + eq(127, eval('v:shell_error')) + end end) describe('executes shell function if passed a string', function() @@ -120,6 +129,15 @@ describe('system()', function() screen:detach() end) + it('escapes inner double quotes #6329', function() + if helpers.os_name() == 'windows' then + -- In Windows cmd.exe's echo prints the quotes + eq('""\n', eval([[system('echo ""')]])) + else + eq('\n', eval([[system('echo ""')]])) + end + end) + it('`echo` and waits for its return', function() feed(':call system("echo")') screen:expect([[ @@ -180,7 +198,11 @@ describe('system()', function() describe('passing no input', function() it('returns the program output', function() - eq("echoed", eval('system("echo -n echoed")')) + if helpers.os_name() == 'windows' then + eq("echoed\n", eval('system("echo echoed")')) + else + eq("echoed", eval('system("echo -n echoed")')) + end end) it('to backgrounded command does not crash', function() -- This is indeterminate, just exercise the codepath. May get E5677. @@ -277,21 +299,30 @@ describe('system()', function() end) end) -if helpers.pending_win32(pending) then return end - describe('systemlist()', function() -- Similar to `system()`, but returns List instead of String. before_each(clear) it('sets the v:shell_error variable', function() - eval([[systemlist("sh -c 'exit'")]]) - eq(0, eval('v:shell_error')) - eval([[systemlist("sh -c 'exit 1'")]]) - eq(1, eval('v:shell_error')) - eval([[systemlist("sh -c 'exit 5'")]]) - eq(5, eval('v:shell_error')) - eval([[systemlist('this-should-not-exist')]]) - eq(127, eval('v:shell_error')) + if helpers.os_name() == 'windows' then + eval([[systemlist("cmd.exe /c exit")]]) + eq(0, eval('v:shell_error')) + eval([[systemlist("cmd.exe /c exit 1")]]) + eq(1, eval('v:shell_error')) + eval([[systemlist("cmd.exe /c exit 5")]]) + eq(5, eval('v:shell_error')) + eval([[systemlist('this-should-not-exist')]]) + eq(1, eval('v:shell_error')) + else + eval([[systemlist("sh -c 'exit'")]]) + eq(0, eval('v:shell_error')) + eval([[systemlist("sh -c 'exit 1'")]]) + eq(1, eval('v:shell_error')) + eval([[systemlist("sh -c 'exit 5'")]]) + eq(5, eval('v:shell_error')) + eval([[systemlist('this-should-not-exist')]]) + eq(127, eval('v:shell_error')) + end end) describe('exectues shell function', function() @@ -389,6 +420,7 @@ describe('systemlist()', function() after_each(delete_file(fname)) it('replaces NULs by newline characters', function() + if helpers.pending_win32(pending) then return end eq({'part1\npart2\npart3'}, eval('systemlist("cat '..fname..'")')) end) end) 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 f3cc843755a6d638ada77dc31721aa53b3ff2364 Mon Sep 17 00:00:00 2001 From: Rui Abreu Ferreira Date: Tue, 28 Mar 2017 16:03:53 +0100 Subject: win: libuv_process_spawn(): special-case cmd.exe Disable CommandLineToArgvW-standard quoting for cmd.exe. libuv assumes spawned processes follow the convention expected by CommandLineToArgvW(). But cmd.exe is non-conformant, so for cmd.exe: - With system([]), the caller has full control (and responsibility) to quote arguments correctly. - With system(''), shell* options are used. libuv quoting is disabled if argv[0] is: - cmd.exe - cmd - $COMSPEC resolving to a path with filename cmd.exe Closes #6329 References #6387 --- test/functional/eval/system_spec.lua | 38 +++++++++++++++++++++++++++++------- 1 file changed, 31 insertions(+), 7 deletions(-) (limited to 'test/functional') diff --git a/test/functional/eval/system_spec.lua b/test/functional/eval/system_spec.lua index 83d8028b56..45ca69707d 100644 --- a/test/functional/eval/system_spec.lua +++ b/test/functional/eval/system_spec.lua @@ -129,14 +129,38 @@ describe('system()', function() screen:detach() end) - it('escapes inner double quotes #6329', function() - if helpers.os_name() == 'windows' then - -- In Windows cmd.exe's echo prints the quotes + if helpers.os_name() == 'windows' then + it('with the default cmd.exe shell', function() eq('""\n', eval([[system('echo ""')]])) - else - eq('\n', eval([[system('echo ""')]])) - end - end) + eq('"a b"\n', eval([[system('echo "a b"')]])) + -- TODO: consistent with Vim, but it should be fixed + eq('a & echo b\n', eval([[system('echo a & echo b')]])) + eval([[system('cd "C:\Program Files"')]]) + eq(0, eval('v:shell_error')) + end) + + it('with set shell="cmd"', function() + helpers.source('let &shell="cmd"') + eq('"a b"\n', eval([[system('echo "a b"')]])) + end) + + it('works with cmd.exe from $COMSPEC', function() + local comspecshell = eval("fnamemodify($COMSPEC, ':t')") + if comspecshell == 'cmd.exe' then + helpers.source('let &shell=$COMSPEC') + eq('"a b"\n', eval([[system('echo "a b"')]])) + else + pending('$COMSPEC is not cmd.exe ' .. comspecshell) + end + end) + + it('works with powershell', function() + helpers.set_shell_powershell() + eq('a\nb\n', eval([[system('echo a b')]])) + eq('C:\\\n', eval([[system('cd c:\; (Get-Location).Path')]])) + eq('a b\n', eval([[system('echo "a b"')]])) + end) + end it('`echo` and waits for its return', function() feed(':call system("echo")') -- cgit From d31d177a0c2c9997c2cdb04975bc3354b9a23fb8 Mon Sep 17 00:00:00 2001 From: Rui Abreu Ferreira Date: Thu, 30 Mar 2017 23:41:52 +0100 Subject: win: default shellxescape, shellxquote to empty Calling cmd.exe in Windows follows a very different pattern from Vim. The primary difference is that Vim does a nested call to cmd.exe, e.g. the following call in Vim system('echo a 2>&1') spawns the following processes "C:\Program Files (x86)\Vim\vim80\vimrun" -s C:\Windows\system32\cmd.exe /c (echo a 2^>^&1 ^>C:\Users\dummy\AppData\Local\Temp\VIoC169.tmp 2^>^&1) C:\Windows\system32\cmd.exe /c C:\Windows\system32\cmd.exe /c (echo a 2^>^&1 ^>C:\Users\dummy\AppData\Local\Temp\VIo3C6C.tmp 2^>^&1) C:\Windows\system32\cmd.exe /c (echo a 2>&1 >C:\Users\dummy\AppData\Local\Temp\VIo3C6C.tmp 2>&1) The escaping with ^ is needed because cmd.exe calls itself and needs to preserve the special metacharacters for the last call. However in nvim no nested call is made, system('') spawns a single cmd.exe process. Setting shellxescape to "" disables escaping with ^. The previous default for shellxquote=( wrapped any command in parenthesis, in Vim this is more meaningful due to the use of tempfiles to store the output and redirection (also see &shellquote). There is a slight benefit in having the default be empty because some expressions that run in console will not run within parens e.g. due to unbalanced double quotes system('echo "a b') --- test/functional/eval/system_spec.lua | 34 ++++++++++++++++++---------------- test/functional/terminal/edit_spec.lua | 6 +----- 2 files changed, 19 insertions(+), 21 deletions(-) (limited to 'test/functional') diff --git a/test/functional/eval/system_spec.lua b/test/functional/eval/system_spec.lua index 45ca69707d..7e213e2156 100644 --- a/test/functional/eval/system_spec.lua +++ b/test/functional/eval/system_spec.lua @@ -4,6 +4,8 @@ local nvim_dir = helpers.nvim_dir local eq, call, clear, eval, feed_command, feed, nvim = helpers.eq, helpers.call, helpers.clear, helpers.eval, helpers.feed_command, helpers.feed, helpers.nvim +local command = helpers.command +local iswin = helpers.iswin local Screen = require('test.functional.ui.screen') @@ -33,8 +35,7 @@ describe('system()', function() describe('command passed as a List', function() local function printargs_path() - return nvim_dir..'/printargs-test' - .. (helpers.os_name() == 'windows' and '.exe' or '') + return nvim_dir..'/printargs-test' .. (iswin() and '.exe' or '') end it('sets v:shell_error if cmd[0] is not executable', function() @@ -88,14 +89,14 @@ describe('system()', function() end) it('does NOT run in shell', function() - if helpers.os_name() ~= 'windows' then + if not iswin() then eq("* $PATH %PATH%\n", eval("system(['echo', '*', '$PATH', '%PATH%'])")) end end) end) it('sets v:shell_error', function() - if helpers.os_name() == 'windows' then + if iswin() then eval([[system("cmd.exe /c exit")]]) eq(0, eval('v:shell_error')) eval([[system("cmd.exe /c exit 1")]]) @@ -129,28 +130,29 @@ describe('system()', function() screen:detach() end) - if helpers.os_name() == 'windows' then - it('with the default cmd.exe shell', function() + if iswin() then + it('with shell=cmd.exe', function() + command('set shell=cmd.exe') eq('""\n', eval([[system('echo ""')]])) eq('"a b"\n', eval([[system('echo "a b"')]])) - -- TODO: consistent with Vim, but it should be fixed - eq('a & echo b\n', eval([[system('echo a & echo b')]])) + eq('a \nb\n', eval([[system('echo a & echo b')]])) + eq('a \n', eval([[system('echo a 2>&1')]])) eval([[system('cd "C:\Program Files"')]]) eq(0, eval('v:shell_error')) end) - it('with set shell="cmd"', function() - helpers.source('let &shell="cmd"') + it('with shell=cmd', function() + command('set shell=cmd') eq('"a b"\n', eval([[system('echo "a b"')]])) end) - it('works with cmd.exe from $COMSPEC', function() + it('with shell=$COMSPEC', function() local comspecshell = eval("fnamemodify($COMSPEC, ':t')") if comspecshell == 'cmd.exe' then - helpers.source('let &shell=$COMSPEC') + command('set shell=$COMSPEC') eq('"a b"\n', eval([[system('echo "a b"')]])) else - pending('$COMSPEC is not cmd.exe ' .. comspecshell) + pending('$COMSPEC is not cmd.exe: ' .. comspecshell) end end) @@ -222,7 +224,7 @@ describe('system()', function() describe('passing no input', function() it('returns the program output', function() - if helpers.os_name() == 'windows' then + if iswin() then eq("echoed\n", eval('system("echo echoed")')) else eq("echoed", eval('system("echo -n echoed")')) @@ -327,8 +329,8 @@ describe('systemlist()', function() -- Similar to `system()`, but returns List instead of String. before_each(clear) - it('sets the v:shell_error variable', function() - if helpers.os_name() == 'windows' then + it('sets v:shell_error', function() + if iswin() then eval([[systemlist("cmd.exe /c exit")]]) eq(0, eval('v:shell_error')) eval([[systemlist("cmd.exe /c exit 1")]]) diff --git a/test/functional/terminal/edit_spec.lua b/test/functional/terminal/edit_spec.lua index f691a58f6c..d2b2d8a60c 100644 --- a/test/functional/terminal/edit_spec.lua +++ b/test/functional/terminal/edit_spec.lua @@ -8,7 +8,6 @@ local command = helpers.command local meths = helpers.meths local clear = helpers.clear local eq = helpers.eq -local iswin = helpers.iswin describe(':edit term://*', function() local get_screen = function(columns, lines) @@ -46,11 +45,8 @@ describe(':edit term://*', function() local bufcontents = {} local winheight = curwinmeths.get_height() local buf_cont_start = rep_size - sb - winheight + 2 - local function bufline (i) - return (iswin() and '%d: (foobar)' or '%d: foobar'):format(i) - end for i = buf_cont_start,(rep_size - 1) do - bufcontents[#bufcontents + 1] = bufline(i) + bufcontents[#bufcontents + 1] = ('%d: foobar'):format(i) end bufcontents[#bufcontents + 1] = '' bufcontents[#bufcontents + 1] = '[Process exited 0]' -- cgit From 12fc1defd6a1b13d1f801173e0b6a1cef28527ae Mon Sep 17 00:00:00 2001 From: Björn Linse Date: Sat, 15 Apr 2017 11:19:40 +0200 Subject: ops: fix i with multi-byte text (#6524) --- test/functional/insert/ctrl_r_spec.lua | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 test/functional/insert/ctrl_r_spec.lua (limited to 'test/functional') diff --git a/test/functional/insert/ctrl_r_spec.lua b/test/functional/insert/ctrl_r_spec.lua new file mode 100644 index 0000000000..adc3c4b406 --- /dev/null +++ b/test/functional/insert/ctrl_r_spec.lua @@ -0,0 +1,19 @@ +local helpers = require('test.functional.helpers')(after_each) +local clear, feed = helpers.clear, helpers.feed +local expect, command = helpers.expect, helpers.command + +describe('insert-mode Ctrl-R', function() + before_each(clear) + + it('works', function() + command("let @@ = 'test'") + feed('i"') + expect('test') + end) + + it('works with multi-byte text', function() + command("let @@ = 'påskägg'") + feed('i"') + expect('påskägg') + end) +end) -- cgit From 263849b2dd4dc98bbe0870f5654c77809caeb965 Mon Sep 17 00:00:00 2001 From: Matthew Malcomson Date: Sun, 16 Apr 2017 20:15:50 +0100 Subject: fold: foldMoveRange(): fix :move bug #6534 Closes #6540 In #6221 there was a mistake in calculating which folds need to be re-ordered. When there are no folds after those that have been adjusted, then `move_end` remains 0. This results in reverse_fold_order() swapping folds that have been adjusted with uninitialised folds in the remainder of the grow array. Add a check in foldMoveRange() to account for this case. --- test/functional/normal/fold_spec.lua | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'test/functional') diff --git a/test/functional/normal/fold_spec.lua b/test/functional/normal/fold_spec.lua index 85e4631b61..00e83bedc8 100644 --- a/test/functional/normal/fold_spec.lua +++ b/test/functional/normal/fold_spec.lua @@ -232,6 +232,25 @@ a a]], '2,3m0') eq({1, 2, 0, 0, 0}, get_folds()) end) + it('handles shifting all remaining folds', function() + test_move_indent([[ + a + a + a + a + a + a + a + a + a + a + a + a + a + a +a]], '13m7') + eq({1, 2, 2, 2, 1, 2, 2, 1, 1, 1, 2, 2, 2, 1, 0}, get_folds()) + end) end) it('updates correctly on :read', function() -- luacheck: ignore 621 -- cgit From 45aa465fba73a9422a5c37779666eb59e0616142 Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Mon, 17 Apr 2017 03:53:29 +0200 Subject: test: Cursor after `:hi clear|syntax reset` Also enable tests on Windows. --- test/functional/ui/highlight_spec.lua | 45 +++++++++++++++++++---------------- 1 file changed, 25 insertions(+), 20 deletions(-) (limited to 'test/functional') diff --git a/test/functional/ui/highlight_spec.lua b/test/functional/ui/highlight_spec.lua index 5f8fafef07..2bda907c33 100644 --- a/test/functional/ui/highlight_spec.lua +++ b/test/functional/ui/highlight_spec.lua @@ -2,23 +2,23 @@ local helpers = require('test.functional.helpers')(after_each) local Screen = require('test.functional.ui.screen') local os = require('os') local clear, feed, insert = helpers.clear, helpers.feed, helpers.insert +local command = helpers.command +local eval = helpers.eval local feed_command, request, eq = helpers.feed_command, helpers.request, helpers.eq -if helpers.pending_win32(pending) then return end - -describe('color scheme compatibility', function() +describe('colorscheme compatibility', function() before_each(function() clear() end) it('t_Co is set to 256 by default', function() - eq('256', request('vim_eval', '&t_Co')) + eq('256', eval('&t_Co')) request('nvim_set_option', 't_Co', '88') - eq('88', request('vim_eval', '&t_Co')) + eq('88', eval('&t_Co')) end) end) -describe('manual syntax highlight', function() +describe('highlight: `:syntax manual`', function() -- When using manual syntax highlighting, it should be preserved even when -- switching buffers... bug did only occur without :set hidden -- Ref: vim patch 7.4.1236 @@ -63,32 +63,32 @@ describe('manual syntax highlight', function() end) it("works with buffer switch and 'nohidden'", function() - feed_command('e tmp1.vim') - feed_command('e Xtest-functional-ui-highlight.tmp.vim') - feed_command('filetype on') - feed_command('syntax manual') - feed_command('set ft=vim') - feed_command('set syntax=ON') + command('e tmp1.vim') + command('e Xtest-functional-ui-highlight.tmp.vim') + command('filetype on') + command('syntax manual') + command('set filetype=vim fileformat=unix') + command('set syntax=ON') feed('iecho 10') - feed_command('set nohidden') - feed_command('w') - feed_command('bn') - feed_command('bp') + command('set nohidden') + command('w') + command('silent bn') + eq("tmp1.vim", eval("fnamemodify(bufname('%'), ':t')")) + feed_command('silent bp') + eq("Xtest-functional-ui-highlight.tmp.vim", eval("fnamemodify(bufname('%'), ':t')")) screen:expect([[ {1:^echo} 1 | {0:~ }| {0:~ }| {0:~ }| - Date: Wed, 19 Apr 2017 19:11:50 +0300 Subject: *: Add comment to all C files --- test/functional/fixtures/printargs-test.c | 3 +++ test/functional/fixtures/shell-test.c | 3 +++ test/functional/fixtures/tty-test.c | 3 +++ 3 files changed, 9 insertions(+) (limited to 'test/functional') diff --git a/test/functional/fixtures/printargs-test.c b/test/functional/fixtures/printargs-test.c index 2c25cf8447..be54605817 100644 --- a/test/functional/fixtures/printargs-test.c +++ b/test/functional/fixtures/printargs-test.c @@ -1,3 +1,6 @@ +// This is an open source non-commercial project. Dear PVS-Studio, please check +// it. PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com + #include int main(int argc, char **argv) diff --git a/test/functional/fixtures/shell-test.c b/test/functional/fixtures/shell-test.c index 3f3976ece5..8dbec2aaee 100644 --- a/test/functional/fixtures/shell-test.c +++ b/test/functional/fixtures/shell-test.c @@ -1,3 +1,6 @@ +// This is an open source non-commercial project. Dear PVS-Studio, please check +// it. PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com + #include #include #include diff --git a/test/functional/fixtures/tty-test.c b/test/functional/fixtures/tty-test.c index 778e7f3cd3..3406b3a202 100644 --- a/test/functional/fixtures/tty-test.c +++ b/test/functional/fixtures/tty-test.c @@ -1,3 +1,6 @@ +// This is an open source non-commercial project. Dear PVS-Studio, please check +// it. PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com + #include #include #include -- cgit From 17052946c744abd53d8f3349f453964ffa818bea Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Thu, 20 Apr 2017 12:32:14 +0200 Subject: 'scrollback': Allow :setlocal -1 on normal buffers Avoids a spurious :loadview error. --- test/functional/terminal/scrollback_spec.lua | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'test/functional') diff --git a/test/functional/terminal/scrollback_spec.lua b/test/functional/terminal/scrollback_spec.lua index 32f25d4086..05f81295c2 100644 --- a/test/functional/terminal/scrollback_spec.lua +++ b/test/functional/terminal/scrollback_spec.lua @@ -451,6 +451,13 @@ describe("'scrollback' option", function() it(':setlocal in a normal buffer is an error', function() command('new') + + -- :setlocal to -1 is NOT an error. + feed_command('setlocal scrollback=-1') + eq(nil, string.match(eval("v:errmsg"), "E%d*:")) + feed('') + + -- :setlocal to anything except -1 is an error. feed_command('setlocal scrollback=42') feed('') eq('E474:', string.match(eval("v:errmsg"), "E%d*:")) -- cgit From 2c5751b9b2b22b8519aeda82088fe4525f2bd713 Mon Sep 17 00:00:00 2001 From: Björn Linse Date: Mon, 17 Apr 2017 13:32:22 +0200 Subject: ui: add tests for new cursor shape modes --- test/functional/terminal/ex_terminal_spec.lua | 2 +- test/functional/ui/cursor_spec.lua | 17 ++ test/functional/ui/mode_spec.lua | 227 ++++++++++++++++++++++++++ test/functional/ui/screen.lua | 5 +- test/functional/ui/screen_basic_spec.lua | 113 ------------- 5 files changed, 247 insertions(+), 117 deletions(-) create mode 100644 test/functional/ui/mode_spec.lua (limited to 'test/functional') diff --git a/test/functional/terminal/ex_terminal_spec.lua b/test/functional/terminal/ex_terminal_spec.lua index 154374cda9..1ed63adcfb 100644 --- a/test/functional/terminal/ex_terminal_spec.lua +++ b/test/functional/terminal/ex_terminal_spec.lua @@ -26,7 +26,7 @@ describe(':terminal', function() feed_command([[terminal while true; do echo X; done]]) helpers.feed([[]]) wait() - helpers.sleep(10) -- Let some terminal activity happen. + screen.sleep(10) -- Let some terminal activity happen. feed_command("messages") screen:expect([[ msg1 | diff --git a/test/functional/ui/cursor_spec.lua b/test/functional/ui/cursor_spec.lua index 02e9422781..e4c1b17ef3 100644 --- a/test/functional/ui/cursor_spec.lua +++ b/test/functional/ui/cursor_spec.lua @@ -20,9 +20,11 @@ describe('ui/cursor', function() it("'guicursor' is published as a UI event", function() local expected_cursor_style = { cmdline_hover = { + mode_idx = 9, mouse_shape = 0, short_name = 'e' }, cmdline_insert = { + mode_idx = 5, blinkoff = 250, blinkon = 400, blinkwait = 700, @@ -33,6 +35,7 @@ describe('ui/cursor', function() mouse_shape = 0, short_name = 'ci' }, cmdline_normal = { + mode_idx = 4, blinkoff = 250, blinkon = 400, blinkwait = 700, @@ -43,6 +46,7 @@ describe('ui/cursor', function() mouse_shape = 0, short_name = 'c' }, cmdline_replace = { + mode_idx = 6, blinkoff = 250, blinkon = 400, blinkwait = 700, @@ -53,6 +57,7 @@ describe('ui/cursor', function() mouse_shape = 0, short_name = 'cr' }, insert = { + mode_idx = 2, blinkoff = 250, blinkon = 400, blinkwait = 700, @@ -63,12 +68,15 @@ describe('ui/cursor', function() mouse_shape = 0, short_name = 'i' }, more = { + mode_idx = 14, mouse_shape = 0, short_name = 'm' }, more_lastline = { + mode_idx = 15, mouse_shape = 0, short_name = 'ml' }, normal = { + mode_idx = 0, blinkoff = 250, blinkon = 400, blinkwait = 700, @@ -79,6 +87,7 @@ describe('ui/cursor', function() mouse_shape = 0, short_name = 'n' }, operator = { + mode_idx = 7, blinkoff = 250, blinkon = 400, blinkwait = 700, @@ -89,6 +98,7 @@ describe('ui/cursor', function() mouse_shape = 0, short_name = 'o' }, replace = { + mode_idx = 3, blinkoff = 250, blinkon = 400, blinkwait = 700, @@ -99,6 +109,7 @@ describe('ui/cursor', function() mouse_shape = 0, short_name = 'r' }, showmatch = { + mode_idx = 16, blinkoff = 150, blinkon = 175, blinkwait = 175, @@ -108,12 +119,15 @@ describe('ui/cursor', function() id_lm = 46, short_name = 'sm' }, statusline_drag = { + mode_idx = 11, mouse_shape = 0, short_name = 'sd' }, statusline_hover = { + mode_idx = 10, mouse_shape = 0, short_name = 's' }, visual = { + mode_idx = 1, blinkoff = 250, blinkon = 400, blinkwait = 700, @@ -124,6 +138,7 @@ describe('ui/cursor', function() mouse_shape = 0, short_name = 'v' }, visual_select = { + mode_idx = 8, blinkoff = 250, blinkon = 400, blinkwait = 700, @@ -134,9 +149,11 @@ describe('ui/cursor', function() mouse_shape = 0, short_name = 've' }, vsep_drag = { + mode_idx = 13, mouse_shape = 0, short_name = 'vd' }, vsep_hover = { + mode_idx = 12, mouse_shape = 0, short_name = 'vs' } } diff --git a/test/functional/ui/mode_spec.lua b/test/functional/ui/mode_spec.lua new file mode 100644 index 0000000000..f0cedfeeb5 --- /dev/null +++ b/test/functional/ui/mode_spec.lua @@ -0,0 +1,227 @@ +local helpers = require('test.functional.helpers')(after_each) +local Screen = require('test.functional.ui.screen') + +local clear, feed, insert = helpers.clear, helpers.feed, helpers.insert +local command, eval = helpers.command, helpers.eval +local eq = helpers.eq + +describe('ui mode_change event', function() + local screen + + before_each(function() + clear() + screen = Screen.new(25, 4) + screen:attach({rgb= true}) + screen:set_default_attr_ids( { + [0] = {bold=true, foreground=255}, + [1] = {bold=true, reverse=true}, + [2] = {bold=true}, + [3] = {reverse=true}, + }) + end) + + it('works in normal mode', function() + screen:expect([[ + ^ | + {0:~ }| + {0:~ }| + | + ]],nil,nil,function () + eq("normal", screen.mode) + end) + + feed('d') + screen:expect([[ + ^ | + {0:~ }| + {0:~ }| + | + ]],nil,nil,function () + eq("operator", screen.mode) + end) + + feed('') + screen:expect([[ + ^ | + {0:~ }| + {0:~ }| + | + ]],nil,nil,function () + eq("normal", screen.mode) + end) + end) + + it('works in insert mode', function() + feed('i') + screen:expect([[ + ^ | + {0:~ }| + {0:~ }| + {2:-- INSERT --} | + ]],nil,nil,function () + eq("insert", screen.mode) + end) + + feed('word') + screen:expect([[ + wor^d | + {0:~ }| + {0:~ }| + | + ]], nil, nil, function () + eq("normal", screen.mode) + end) + + command("set showmatch") + eq(eval('&matchtime'), 5) -- tenths of seconds + feed('a(stuff') + screen:expect([[ + word(stuff^ | + {0:~ }| + {0:~ }| + {2:-- INSERT --} | + ]], nil, nil, function () + eq("insert", screen.mode) + end) + + feed(')') + screen:expect([[ + word^(stuff) | + {0:~ }| + {0:~ }| + {2:-- INSERT --} | + ]], nil, nil, function () + eq("showmatch", screen.mode) + end) + + screen:sleep(400) + screen:expect([[ + word(stuff)^ | + {0:~ }| + {0:~ }| + {2:-- INSERT --} | + ]], nil, nil, function () + eq("insert", screen.mode) + end) + end) + + it('works in replace mode', function() + feed('R') + screen:expect([[ + ^ | + {0:~ }| + {0:~ }| + {2:-- REPLACE --} | + ]], nil, nil, function () + eq("replace", screen.mode) + end) + + feed('word') + screen:expect([[ + wor^d | + {0:~ }| + {0:~ }| + | + ]], nil, nil, function () + eq("normal", screen.mode) + end) + end) + + it('works in cmdline mode', function() + feed(':') + screen:expect([[ + | + {0:~ }| + {0:~ }| + :^ | + ]],nil,nil,function () + eq("cmdline_normal", screen.mode) + end) + + feed('x') + screen:expect([[ + | + {0:~ }| + {0:~ }| + :^x | + ]],nil,nil,function () + eq("cmdline_insert", screen.mode) + end) + + feed('') + screen:expect([[ + | + {0:~ }| + {0:~ }| + :^x | + ]],nil,nil,function () + eq("cmdline_replace", screen.mode) + end) + + + feed('') + screen:expect([[ + | + {0:~ }| + {0:~ }| + :x^ | + ]],nil,nil,function () + eq("cmdline_normal", screen.mode) + end) + + feed('') + screen:expect([[ + ^ | + {0:~ }| + {0:~ }| + | + ]],nil,nil,function () + eq("normal", screen.mode) + end) + end) + + it('works in visal mode', function() + insert("text") + feed('v') + screen:expect([[ + tex^t | + {0:~ }| + {0:~ }| + {2:-- VISUAL --} | + ]],nil,nil,function () + eq("visual", screen.mode) + end) + + feed('') + screen:expect([[ + tex^t | + {0:~ }| + {0:~ }| + | + ]],nil,nil,function () + eq("normal", screen.mode) + end) + + command('set selection=exclusive') + feed('v') + screen:expect([[ + tex^t | + {0:~ }| + {0:~ }| + {2:-- VISUAL --} | + ]],nil,nil,function () + eq("visual_select", screen.mode) + end) + + feed('') + screen:expect([[ + tex^t | + {0:~ }| + {0:~ }| + | + ]],nil,nil,function () + eq("normal", screen.mode) + end) + end) +end) + diff --git a/test/functional/ui/screen.lua b/test/functional/ui/screen.lua index afbcd222c7..ceb82db98f 100644 --- a/test/functional/ui/screen.lua +++ b/test/functional/ui/screen.lua @@ -384,9 +384,8 @@ function Screen:_handle_mouse_off() self._mouse_enabled = false end -function Screen:_handle_mode_change(mode) - assert(mode == 'insert' or mode == 'replace' - or mode == 'normal' or mode == 'cmdline') +function Screen:_handle_mode_change(mode, idx) + assert(idx == self._cursor_style[mode].mode_idx) self.mode = mode end diff --git a/test/functional/ui/screen_basic_spec.lua b/test/functional/ui/screen_basic_spec.lua index 8182190b5f..d9cb3d7b6f 100644 --- a/test/functional/ui/screen_basic_spec.lua +++ b/test/functional/ui/screen_basic_spec.lua @@ -566,119 +566,6 @@ describe('Screen', function() end) end) - describe('mode change', function() - before_each(function() - screen:try_resize(25, 5) - end) - - it('works in normal mode', function() - screen:expect([[ - ^ | - {0:~ }| - {0:~ }| - {0:~ }| - | - ]],nil,nil,function () - eq("normal", screen.mode) - end) - end) - - it('works in insert mode', function() - feed('i') - screen:expect([[ - ^ | - {0:~ }| - {0:~ }| - {0:~ }| - {2:-- INSERT --} | - ]],nil,nil,function () - eq("insert", screen.mode) - end) - - feed('word') - screen:expect([[ - wor^d | - {0:~ }| - {0:~ }| - {0:~ }| - | - ]], nil, nil, function () - eq("normal", screen.mode) - end) - end) - - it('works in replace mode', function() - feed('R') - screen:expect([[ - ^ | - {0:~ }| - {0:~ }| - {0:~ }| - {2:-- REPLACE --} | - ]], nil, nil, function () - eq("replace", screen.mode) - end) - - feed('word') - screen:expect([[ - wor^d | - {0:~ }| - {0:~ }| - {0:~ }| - | - ]], nil, nil, function () - eq("normal", screen.mode) - end) - end) - - it('works in cmdline mode', function() - feed(':') - screen:expect([[ - | - {0:~ }| - {0:~ }| - {0:~ }| - :^ | - ]],nil,nil,function () - eq("cmdline", screen.mode) - end) - - feed('/') - screen:expect([[ - | - {0:~ }| - {0:~ }| - {0:~ }| - /^ | - ]],nil,nil,function () - eq("cmdline", screen.mode) - end) - - - feed('?') - screen:expect([[ - | - {0:~ }| - {0:~ }| - {0:~ }| - ?^ | - ]],nil,nil,function () - eq("cmdline", screen.mode) - end) - - feed('') - screen:expect([[ - ^ | - {0:~ }| - {0:~ }| - {0:~ }| - | - ]],nil,nil,function () - eq("normal", screen.mode) - end) - end) - end) - it('nvim_ui_attach() handles very large width/height #2180', function() screen:detach() screen = Screen.new(999, 999) -- cgit From 7ea5c78687168c07bfc4582c84145e86a5252f94 Mon Sep 17 00:00:00 2001 From: Björn Linse Date: Tue, 18 Apr 2017 13:42:04 +0200 Subject: ui: use an array for mode styles --- test/functional/ui/cursor_spec.lua | 186 +++++++++++++++++++------------------ test/functional/ui/screen.lua | 8 +- 2 files changed, 99 insertions(+), 95 deletions(-) (limited to 'test/functional') diff --git a/test/functional/ui/cursor_spec.lua b/test/functional/ui/cursor_spec.lua index e4c1b17ef3..abe0e0b1fd 100644 --- a/test/functional/ui/cursor_spec.lua +++ b/test/functional/ui/cursor_spec.lua @@ -18,155 +18,155 @@ describe('ui/cursor', function() end) it("'guicursor' is published as a UI event", function() - local expected_cursor_style = { - cmdline_hover = { - mode_idx = 9, - mouse_shape = 0, - short_name = 'e' }, - cmdline_insert = { - mode_idx = 5, + local expected_mode_info = { + [1] = { blinkoff = 250, blinkon = 400, blinkwait = 700, - cell_percentage = 25, - cursor_shape = 'vertical', + cell_percentage = 0, + cursor_shape = 'block', + name = 'normal', hl_id = 46, id_lm = 47, mouse_shape = 0, - short_name = 'ci' }, - cmdline_normal = { - mode_idx = 4, + short_name = 'n' }, + [2] = { blinkoff = 250, blinkon = 400, blinkwait = 700, cell_percentage = 0, cursor_shape = 'block', + name = 'visual', hl_id = 46, id_lm = 47, mouse_shape = 0, - short_name = 'c' }, - cmdline_replace = { - mode_idx = 6, + short_name = 'v' }, + [3] = { blinkoff = 250, blinkon = 400, blinkwait = 700, - cell_percentage = 20, - cursor_shape = 'horizontal', + cell_percentage = 25, + cursor_shape = 'vertical', + name = 'insert', hl_id = 46, id_lm = 47, mouse_shape = 0, - short_name = 'cr' }, - insert = { - mode_idx = 2, + short_name = 'i' }, + [4] = { blinkoff = 250, blinkon = 400, blinkwait = 700, - cell_percentage = 25, - cursor_shape = 'vertical', + cell_percentage = 20, + cursor_shape = 'horizontal', + name = 'replace', hl_id = 46, id_lm = 47, mouse_shape = 0, - short_name = 'i' }, - more = { - mode_idx = 14, - mouse_shape = 0, - short_name = 'm' }, - more_lastline = { - mode_idx = 15, - mouse_shape = 0, - short_name = 'ml' }, - normal = { - mode_idx = 0, + short_name = 'r' }, + [5] = { blinkoff = 250, blinkon = 400, blinkwait = 700, cell_percentage = 0, cursor_shape = 'block', + name = 'cmdline_normal', hl_id = 46, id_lm = 47, mouse_shape = 0, - short_name = 'n' }, - operator = { - mode_idx = 7, + short_name = 'c' }, + [6] = { blinkoff = 250, blinkon = 400, blinkwait = 700, - cell_percentage = 50, - cursor_shape = 'horizontal', + cell_percentage = 25, + cursor_shape = 'vertical', + name = 'cmdline_insert', hl_id = 46, - id_lm = 46, + id_lm = 47, mouse_shape = 0, - short_name = 'o' }, - replace = { - mode_idx = 3, + short_name = 'ci' }, + [7] = { blinkoff = 250, blinkon = 400, blinkwait = 700, cell_percentage = 20, cursor_shape = 'horizontal', + name = 'cmdline_replace', hl_id = 46, id_lm = 47, mouse_shape = 0, - short_name = 'r' }, - showmatch = { - mode_idx = 16, - blinkoff = 150, - blinkon = 175, - blinkwait = 175, - cell_percentage = 0, - cursor_shape = 'block', - hl_id = 46, - id_lm = 46, - short_name = 'sm' }, - statusline_drag = { - mode_idx = 11, - mouse_shape = 0, - short_name = 'sd' }, - statusline_hover = { - mode_idx = 10, - mouse_shape = 0, - short_name = 's' }, - visual = { - mode_idx = 1, + short_name = 'cr' }, + [8] = { blinkoff = 250, blinkon = 400, blinkwait = 700, - cell_percentage = 0, - cursor_shape = 'block', + cell_percentage = 50, + cursor_shape = 'horizontal', + name = 'operator', hl_id = 46, - id_lm = 47, + id_lm = 46, mouse_shape = 0, - short_name = 'v' }, - visual_select = { - mode_idx = 8, + short_name = 'o' }, + [9] = { blinkoff = 250, blinkon = 400, blinkwait = 700, cell_percentage = 35, cursor_shape = 'vertical', + name = 'visual_select', hl_id = 46, id_lm = 46, mouse_shape = 0, short_name = 've' }, - vsep_drag = { - mode_idx = 13, + [10] = { + name = 'cmdline_hover', + mouse_shape = 0, + short_name = 'e' }, + [11] = { + name = 'statusline_hover', + mouse_shape = 0, + short_name = 's' }, + [12] = { + name = 'statusline_drag', + mouse_shape = 0, + short_name = 'sd' }, + [13] = { + name = 'vsep_hover', + mouse_shape = 0, + short_name = 'vs' }, + [14] = { + name = 'vsep_drag', mouse_shape = 0, short_name = 'vd' }, - vsep_hover = { - mode_idx = 12, + [15] = { + name = 'more', mouse_shape = 0, - short_name = 'vs' } - } + short_name = 'm' }, + [16] = { + name = 'more_lastline', + mouse_shape = 0, + short_name = 'ml' }, + [17] = { + blinkoff = 150, + blinkon = 175, + blinkwait = 175, + cell_percentage = 0, + cursor_shape = 'block', + name = 'showmatch', + hl_id = 46, + id_lm = 46, + short_name = 'sm' }, + } screen:expect(function() -- Default 'guicursor' published on startup. - eq(expected_cursor_style, screen._cursor_style) + eq(expected_mode_info, screen._mode_info) eq(true, screen._cursor_style_enabled) eq('normal', screen.mode) end) -- Event is published ONLY if the cursor style changed. - screen._cursor_style = nil + screen._mode_info = nil command("echo 'test'") screen:expect([[ ^ | @@ -175,20 +175,24 @@ describe('ui/cursor', function() ~ | test | ]], nil, nil, function() - eq(nil, screen._cursor_style) + eq(nil, screen._mode_info) end) -- Change the cursor style. meths.set_option('guicursor', 'n-v-c:ver35-blinkwait171-blinkoff172-blinkon173,ve:hor35,o:ver50,i-ci:block,r-cr:hor90,sm:ver42') screen:expect(function() - eq('vertical', screen._cursor_style.normal.cursor_shape) - eq('horizontal', screen._cursor_style.visual_select.cursor_shape) - eq('vertical', screen._cursor_style.operator.cursor_shape) - eq('block', screen._cursor_style.insert.cursor_shape) - eq('vertical', screen._cursor_style.showmatch.cursor_shape) - eq(171, screen._cursor_style.normal.blinkwait) - eq(172, screen._cursor_style.normal.blinkoff) - eq(173, screen._cursor_style.normal.blinkon) + local named = {} + for _, m in ipairs(screen._mode_info) do + named[m.name] = m + end + eq('vertical', named.normal.cursor_shape) + eq('horizontal', named.visual_select.cursor_shape) + eq('vertical', named.operator.cursor_shape) + eq('block', named.insert.cursor_shape) + eq('vertical', named.showmatch.cursor_shape) + eq(171, named.normal.blinkwait) + eq(172, named.normal.blinkoff) + eq(173, named.normal.blinkon) end) end) @@ -197,11 +201,11 @@ describe('ui/cursor', function() screen:expect(function() -- Empty 'guicursor' sets enabled=false. eq(false, screen._cursor_style_enabled) - for _, m in ipairs({ 'cmdline_insert', 'cmdline_normal', 'cmdline_replace', 'insert', - 'showmatch', 'normal', 'replace', 'visual', - 'visual_select', }) do - eq('block', screen._cursor_style[m].cursor_shape) - eq(0, screen._cursor_style[m].blinkon) + for _, m in ipairs(screen._mode_info) do + if m['cursor_shape'] ~= nil then + eq('block', m.cursor_shape) + eq(0, m.blinkon) + end end end) end) diff --git a/test/functional/ui/screen.lua b/test/functional/ui/screen.lua index ceb82db98f..bcf2a2e3d6 100644 --- a/test/functional/ui/screen.lua +++ b/test/functional/ui/screen.lua @@ -348,9 +348,9 @@ function Screen:_handle_resize(width, height) } end -function Screen:_handle_cursor_style_set(enabled, style) - self._cursor_style_enabled = enabled - self._cursor_style = style +function Screen:_handle_mode_info_set(cursor_style_enabled, mode_info) + self._cursor_style_enabled = cursor_style_enabled + self._mode_info = mode_info end function Screen:_handle_clear() @@ -385,7 +385,7 @@ function Screen:_handle_mouse_off() end function Screen:_handle_mode_change(mode, idx) - assert(idx == self._cursor_style[mode].mode_idx) + assert(mode == self._mode_info[idx+1].name) self.mode = mode 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/ex_cmds/ctrl_c_spec.lua | 2 +- test/functional/helpers.lua | 11 ++++++++++- test/functional/terminal/ex_terminal_spec.lua | 2 +- 3 files changed, 12 insertions(+), 3 deletions(-) (limited to 'test/functional') diff --git a/test/functional/ex_cmds/ctrl_c_spec.lua b/test/functional/ex_cmds/ctrl_c_spec.lua index 993bfa0dba..091a008814 100644 --- a/test/functional/ex_cmds/ctrl_c_spec.lua +++ b/test/functional/ex_cmds/ctrl_c_spec.lua @@ -41,7 +41,7 @@ describe("CTRL-C (mapped)", function() local function test_ctrl_c(ms) feed(":global/^/p") - helpers.sleep(ms) + screen:sleep(ms) feed("") screen:expect([[Interrupt]], nil, nil, nil, true) end 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() diff --git a/test/functional/terminal/ex_terminal_spec.lua b/test/functional/terminal/ex_terminal_spec.lua index 1ed63adcfb..be0fd9f8ff 100644 --- a/test/functional/terminal/ex_terminal_spec.lua +++ b/test/functional/terminal/ex_terminal_spec.lua @@ -26,7 +26,7 @@ describe(':terminal', function() feed_command([[terminal while true; do echo X; done]]) helpers.feed([[]]) wait() - screen.sleep(10) -- Let some terminal activity happen. + screen:sleep(10) -- Let some terminal activity happen. feed_command("messages") screen:expect([[ msg1 | -- cgit From f50e03f2e35cf4bee8cedb2c95bf9619f3b57bc2 Mon Sep 17 00:00:00 2001 From: sander2 Date: Fri, 21 Apr 2017 15:45:51 +0200 Subject: ex_cmds.c: Fix bug in ex_z (#6557) vim-patch:8.0.0571 --- test/functional/ex_cmds/print_commands_spec.lua | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 test/functional/ex_cmds/print_commands_spec.lua (limited to 'test/functional') diff --git a/test/functional/ex_cmds/print_commands_spec.lua b/test/functional/ex_cmds/print_commands_spec.lua new file mode 100644 index 0000000000..98c0f74635 --- /dev/null +++ b/test/functional/ex_cmds/print_commands_spec.lua @@ -0,0 +1,12 @@ +local helpers = require('test.functional.helpers')(after_each) +local clear, eq, command, funcs = + helpers.clear, helpers.eq, helpers.command, helpers.funcs + +describe(':z^', function() + before_each(clear) + + it('correctly sets the cursor after :z^', function() + command('z^') + eq(1, funcs.line('.')) + end) +end) -- cgit From 45240538742d6276ab25abe0d8b02550e1c68179 Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Fri, 21 Apr 2017 14:58:52 +0200 Subject: test: api: Do not truncate errors <1 MB. --- test/functional/api/vim_spec.lua | 9 ++++++++- test/functional/ui/screen.lua | 5 +++-- 2 files changed, 11 insertions(+), 3 deletions(-) (limited to 'test/functional') diff --git a/test/functional/api/vim_spec.lua b/test/functional/api/vim_spec.lua index 8f9f155110..60f30dcfe6 100644 --- a/test/functional/api/vim_spec.lua +++ b/test/functional/api/vim_spec.lua @@ -412,7 +412,7 @@ describe('api', function() eq(5, meths.get_var('avar')) end) - it('throws error on malformated arguments', function() + it('throws error on malformed arguments', function() local req = { {'nvim_set_var', {'avar', 1}}, {'nvim_set_var'}, @@ -452,6 +452,13 @@ describe('api', function() ok(err:match('Invalid option name') ~= nil) end) + it('does not truncate error message <1 MB #5984', function() + local very_long_name = 'A'..('x'):rep(10000)..'Z' + local status, err = pcall(nvim, 'get_option', very_long_name) + eq(false, status) + eq(very_long_name, err:match('Ax+Z?')) + end) + it("doesn't leak memory on incorrect argument types", function() local status, err = pcall(nvim, 'set_current_dir',{'not', 'a', 'dir'}) eq(false, status) diff --git a/test/functional/ui/screen.lua b/test/functional/ui/screen.lua index bcf2a2e3d6..7d9cd6c026 100644 --- a/test/functional/ui/screen.lua +++ b/test/functional/ui/screen.lua @@ -312,12 +312,13 @@ function Screen:_redraw(updates) -- print(require('inspect')(update)) local method = update[1] for i = 2, #update do - local handler = self['_handle_'..method] + local handler_name = '_handle_'..method + local handler = self[handler_name] if handler ~= nil then handler(self, unpack(update[i])) else assert(self._on_event, - "Add Screen:_handle_XXX method or call Screen:set_on_event_handler") + "Add Screen:"..handler_name.." or call Screen:set_on_event_handler") self._on_event(method, update[i]) end end -- cgit From 5c9860a0a2bf27d409c986673f0a74542561c4c3 Mon Sep 17 00:00:00 2001 From: Sander Bosma Date: Wed, 1 Mar 2017 10:43:47 +0100 Subject: api: Do not truncate errors <1 MB. #6237 Closes #5984 --- test/functional/provider/python3_spec.lua | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'test/functional') diff --git a/test/functional/provider/python3_spec.lua b/test/functional/provider/python3_spec.lua index a4e9a49c8a..89a546675f 100644 --- a/test/functional/provider/python3_spec.lua +++ b/test/functional/provider/python3_spec.lua @@ -2,6 +2,7 @@ local helpers = require('test.functional.helpers')(after_each) local eval, command, feed = helpers.eval, helpers.command, helpers.feed local eq, clear, insert = helpers.eq, helpers.clear, helpers.insert local expect, write_file = helpers.expect, helpers.write_file +local feed_command = helpers.feed_command do clear() @@ -30,6 +31,15 @@ describe('python3 commands and functions', function() eq({100, 0}, eval('g:set_by_python3')) end) + it('does not truncate error message <1 MB', function() + -- XXX: Python limits the error name to 200 chars, so this test is + -- mostly bogus. + local very_long_symbol = string.rep('a', 1200) + feed_command(':silent! py3 print('..very_long_symbol..' b)') + -- Truncated error message would not contain this (last) line. + eq('SyntaxError: invalid syntax', eval('v:errmsg')) + end) + it('python3_execute with nested commands', function() command([[python3 vim.command('python3 vim.command("python3 vim.command(\'let set_by_nested_python3 = 555\')")')]]) eq(555, eval('g:set_by_nested_python3')) -- cgit From 086c354a0aad2769042dc91bf5bad021109f56e4 Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Sun, 23 Apr 2017 22:30:08 +0200 Subject: api: Do not translate error messages. Also re-word some error messages: - "Key does not exist: %s" - "Invalid channel: %" - "Request array size must be 4 (request) or 3 (notification)" - "String cannot contain newlines" References #6150 --- test/functional/api/buffer_spec.lua | 2 +- test/functional/api/tabpage_spec.lua | 2 +- test/functional/api/vim_spec.lua | 4 ++-- test/functional/api/window_spec.lua | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) (limited to 'test/functional') diff --git a/test/functional/api/buffer_spec.lua b/test/functional/api/buffer_spec.lua index c3002618b0..9699ea8f85 100644 --- a/test/functional/api/buffer_spec.lua +++ b/test/functional/api/buffer_spec.lua @@ -271,7 +271,7 @@ describe('api/buf', function() eq(1, funcs.exists('b:lua')) curbufmeths.del_var('lua') eq(0, funcs.exists('b:lua')) - eq({false, 'Key "lua" doesn\'t exist'}, meth_pcall(curbufmeths.del_var, 'lua')) + eq({false, 'Key does not exist: lua'}, meth_pcall(curbufmeths.del_var, 'lua')) curbufmeths.set_var('lua', 1) command('lockvar b:lua') eq({false, 'Key is locked: lua'}, meth_pcall(curbufmeths.del_var, 'lua')) diff --git a/test/functional/api/tabpage_spec.lua b/test/functional/api/tabpage_spec.lua index d7ef53a88f..260a91a80c 100644 --- a/test/functional/api/tabpage_spec.lua +++ b/test/functional/api/tabpage_spec.lua @@ -34,7 +34,7 @@ describe('api/tabpage', function() eq(1, funcs.exists('t:lua')) curtabmeths.del_var('lua') eq(0, funcs.exists('t:lua')) - eq({false, 'Key "lua" doesn\'t exist'}, meth_pcall(curtabmeths.del_var, 'lua')) + eq({false, 'Key does not exist: lua'}, meth_pcall(curtabmeths.del_var, 'lua')) curtabmeths.set_var('lua', 1) command('lockvar t:lua') eq({false, 'Key is locked: lua'}, meth_pcall(curtabmeths.del_var, 'lua')) diff --git a/test/functional/api/vim_spec.lua b/test/functional/api/vim_spec.lua index 60f30dcfe6..5b173f3196 100644 --- a/test/functional/api/vim_spec.lua +++ b/test/functional/api/vim_spec.lua @@ -119,7 +119,7 @@ describe('api', function() eq(1, funcs.exists('g:lua')) meths.del_var('lua') eq(0, funcs.exists('g:lua')) - eq({false, 'Key "lua" doesn\'t exist'}, meth_pcall(meths.del_var, 'lua')) + eq({false, 'Key does not exist: lua'}, meth_pcall(meths.del_var, 'lua')) meths.set_var('lua', 1) command('lockvar lua') eq({false, 'Key is locked: lua'}, meth_pcall(meths.del_var, 'lua')) @@ -439,7 +439,7 @@ describe('api', function() } status, err = pcall(meths.call_atomic, req) eq(false, status) - ok(err:match('args must be Array') ~= nil) + ok(err:match('Args must be Array') ~= nil) -- call before was done, but not after eq(1, meths.get_var('avar')) eq({''}, meths.buf_get_lines(0, 0, -1, true)) diff --git a/test/functional/api/window_spec.lua b/test/functional/api/window_spec.lua index deffc68994..6882f50a3e 100644 --- a/test/functional/api/window_spec.lua +++ b/test/functional/api/window_spec.lua @@ -139,7 +139,7 @@ describe('api/win', function() eq(1, funcs.exists('w:lua')) curwinmeths.del_var('lua') eq(0, funcs.exists('w:lua')) - eq({false, 'Key "lua" doesn\'t exist'}, meth_pcall(curwinmeths.del_var, 'lua')) + eq({false, 'Key does not exist: lua'}, meth_pcall(curwinmeths.del_var, 'lua')) curwinmeths.set_var('lua', 1) command('lockvar w:lua') eq({false, 'Key is locked: lua'}, meth_pcall(curwinmeths.del_var, 'lua')) -- cgit From 88023d51238698dd625c26300142d3dbe5770b73 Mon Sep 17 00:00:00 2001 From: Dongdong Zhou Date: Fri, 24 Feb 2017 09:35:27 +0000 Subject: api/ui: externalize tabline --- test/functional/ui/tabline_spec.lua | 58 +++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 test/functional/ui/tabline_spec.lua (limited to 'test/functional') diff --git a/test/functional/ui/tabline_spec.lua b/test/functional/ui/tabline_spec.lua new file mode 100644 index 0000000000..018e008e4a --- /dev/null +++ b/test/functional/ui/tabline_spec.lua @@ -0,0 +1,58 @@ +local helpers = require('test.functional.helpers')(after_each) +local Screen = require('test.functional.ui.screen') +local clear, feed, eq = helpers.clear, helpers.feed, helpers.eq + +if helpers.pending_win32(pending) then return end + +describe('External tab line', function() + local screen + local tabs, curtab + + before_each(function() + clear() + screen = Screen.new(25, 5) + screen:attach({rgb=true, tabline_external=true}) + screen:set_on_event_handler(function(name, data) + if name == "tabline_update" then + curtab, tabs = unpack(data) + end + end) + end) + + after_each(function() + screen:detach() + end) + + describe("'tabline'", function() + it('tabline', function() + local expected = { + {1, {['name'] = '[No Name]'}}, + {2, {['name'] = '[No Name]'}}, + } + feed(":tabnew") + screen:expect([[ + ^ | + ~ | + ~ | + ~ | + | + ]], nil, nil, function() + eq(2, curtab) + eq(expected, tabs) + end) + + feed(":tabNext") + screen:expect([[ + ^ | + ~ | + ~ | + ~ | + | + ]], nil, nil, function() + eq(1, curtab) + eq(expected, tabs) + end) + + end) + end) +end) -- cgit From 00843902d3472ac4e74106fc06fa60e599914496 Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Tue, 25 Apr 2017 02:17:15 +0200 Subject: api/ui: externalize tabline - Work with a bool[] array parallel to the UIWidget enum. - Rename some functions. - Documentation. --- test/functional/ui/screen_basic_spec.lua | 38 +++++++++++++++++++++++++++----- test/functional/ui/tabline_spec.lua | 10 ++++----- test/functional/viml/completion_spec.lua | 4 ++-- 3 files changed, 39 insertions(+), 13 deletions(-) (limited to 'test/functional') diff --git a/test/functional/ui/screen_basic_spec.lua b/test/functional/ui/screen_basic_spec.lua index d9cb3d7b6f..d6aa1aa993 100644 --- a/test/functional/ui/screen_basic_spec.lua +++ b/test/functional/ui/screen_basic_spec.lua @@ -6,7 +6,7 @@ local insert = helpers.insert local eq = helpers.eq local eval = helpers.eval -describe('Initial screen', function() +describe('screen', function() local screen local nvim_argv = {helpers.nvim_prog, '-u', 'NONE', '-i', 'NONE', '-N', '--cmd', 'set shortmess+=I background=light noswapfile belloff= noshowcmd noruler', @@ -27,7 +27,7 @@ describe('Initial screen', function() screen:detach() end) - it('is the default initial screen', function() + it('default initial screen', function() screen:expect([[ ^ | {0:~ }| @@ -565,12 +565,40 @@ describe('Screen', function() ]]) end) end) +end) - it('nvim_ui_attach() handles very large width/height #2180', function() - screen:detach() - screen = Screen.new(999, 999) +describe('nvim_ui_attach()', function() + before_each(function() + clear() + end) + it('handles very large width/height #2180', function() + local screen = Screen.new(999, 999) screen:attach() eq(999, eval('&lines')) eq(999, eval('&columns')) end) + it('"ui_ext" widgets', function() + local screen = Screen.new() + screen:attach({ui_ext={ + 'cmdline', + 'popupmenu', + 'tabline', + 'wildmenu', + }}) + end) + it('invalid "ui_ext" returns error', function() + local screen = Screen.new() + + local status, rv = pcall(function() screen:attach({ui_ext={'foo'}}) end) + eq(false, status) + eq('ui_ext: unknown widget: foo', rv:match("ui_ext:.*")) + + status, rv = pcall(function() screen:attach({ui_ext={'cmdline','foo'}}) end) + eq(false, status) + eq('ui_ext: unknown widget: foo', rv:match("ui_ext:.*")) + + status, rv = pcall(function() screen:attach({ui_ext={'cmdline',1}}) end) + eq(false, status) + eq('ui_ext: item must be a String', rv:match("ui_ext:.*")) + end) end) diff --git a/test/functional/ui/tabline_spec.lua b/test/functional/ui/tabline_spec.lua index 018e008e4a..c62dd0c94b 100644 --- a/test/functional/ui/tabline_spec.lua +++ b/test/functional/ui/tabline_spec.lua @@ -2,16 +2,14 @@ local helpers = require('test.functional.helpers')(after_each) local Screen = require('test.functional.ui.screen') local clear, feed, eq = helpers.clear, helpers.feed, helpers.eq -if helpers.pending_win32(pending) then return end - -describe('External tab line', function() +describe('ui/tabline', function() local screen local tabs, curtab before_each(function() clear() screen = Screen.new(25, 5) - screen:attach({rgb=true, tabline_external=true}) + screen:attach({rgb=true, ui_ext={'tabline'}}) screen:set_on_event_handler(function(name, data) if name == "tabline_update" then curtab, tabs = unpack(data) @@ -23,8 +21,8 @@ describe('External tab line', function() screen:detach() end) - describe("'tabline'", function() - it('tabline', function() + describe('externalized', function() + it('publishes UI events', function() local expected = { {1, {['name'] = '[No Name]'}}, {2, {['name'] = '[No Name]'}}, diff --git a/test/functional/viml/completion_spec.lua b/test/functional/viml/completion_spec.lua index b35e8d4f94..5f5e9437dc 100644 --- a/test/functional/viml/completion_spec.lua +++ b/test/functional/viml/completion_spec.lua @@ -868,13 +868,13 @@ describe('completion', function() end) end) -describe('External completion popupmenu', function() +describe('ui/externalized/popupmenu', function() local screen local items, selected, anchor before_each(function() clear() screen = Screen.new(60, 8) - screen:attach({rgb=true, popupmenu_external=true}) + screen:attach({rgb=true, ui_ext={'popupmenu'}}) screen:set_default_attr_ids({ [1] = {bold=true, foreground=Screen.colors.Blue}, [2] = {bold = true}, -- cgit From c8e1af93de90b2e23579f726fd4aa6a65f9387b6 Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Tue, 25 Apr 2017 10:14:29 +0200 Subject: api: nvim_ui_attach(): Flatten ext_* options. --- test/functional/ui/screen_basic_spec.lua | 24 +++--------------------- test/functional/ui/tabline_spec.lua | 2 +- test/functional/viml/completion_spec.lua | 2 +- 3 files changed, 5 insertions(+), 23 deletions(-) (limited to 'test/functional') diff --git a/test/functional/ui/screen_basic_spec.lua b/test/functional/ui/screen_basic_spec.lua index d6aa1aa993..5d89416e4a 100644 --- a/test/functional/ui/screen_basic_spec.lua +++ b/test/functional/ui/screen_basic_spec.lua @@ -577,28 +577,10 @@ describe('nvim_ui_attach()', function() eq(999, eval('&lines')) eq(999, eval('&columns')) end) - it('"ui_ext" widgets', function() + it('invalid option returns error', function() local screen = Screen.new() - screen:attach({ui_ext={ - 'cmdline', - 'popupmenu', - 'tabline', - 'wildmenu', - }}) - end) - it('invalid "ui_ext" returns error', function() - local screen = Screen.new() - - local status, rv = pcall(function() screen:attach({ui_ext={'foo'}}) end) - eq(false, status) - eq('ui_ext: unknown widget: foo', rv:match("ui_ext:.*")) - - status, rv = pcall(function() screen:attach({ui_ext={'cmdline','foo'}}) end) - eq(false, status) - eq('ui_ext: unknown widget: foo', rv:match("ui_ext:.*")) - - status, rv = pcall(function() screen:attach({ui_ext={'cmdline',1}}) end) + local status, rv = pcall(function() screen:attach({foo={'foo'}}) end) eq(false, status) - eq('ui_ext: item must be a String', rv:match("ui_ext:.*")) + eq('No such ui option', rv:match("No such .*")) end) end) diff --git a/test/functional/ui/tabline_spec.lua b/test/functional/ui/tabline_spec.lua index c62dd0c94b..aa7b432c09 100644 --- a/test/functional/ui/tabline_spec.lua +++ b/test/functional/ui/tabline_spec.lua @@ -9,7 +9,7 @@ describe('ui/tabline', function() before_each(function() clear() screen = Screen.new(25, 5) - screen:attach({rgb=true, ui_ext={'tabline'}}) + screen:attach({rgb=true, ext_tabline=true}) screen:set_on_event_handler(function(name, data) if name == "tabline_update" then curtab, tabs = unpack(data) diff --git a/test/functional/viml/completion_spec.lua b/test/functional/viml/completion_spec.lua index 5f5e9437dc..0e5278345c 100644 --- a/test/functional/viml/completion_spec.lua +++ b/test/functional/viml/completion_spec.lua @@ -874,7 +874,7 @@ describe('ui/externalized/popupmenu', function() before_each(function() clear() screen = Screen.new(60, 8) - screen:attach({rgb=true, ui_ext={'popupmenu'}}) + screen:attach({rgb=true, ext_popupmenu=true}) screen:set_default_attr_ids({ [1] = {bold=true, foreground=Screen.colors.Blue}, [2] = {bold = true}, -- cgit From 6944abad2f3f443027af1966a2a310034d2179b2 Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Tue, 25 Apr 2017 11:13:29 +0200 Subject: api/ext_tabline: List of Dicts. --- test/functional/ui/tabline_spec.lua | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) (limited to 'test/functional') diff --git a/test/functional/ui/tabline_spec.lua b/test/functional/ui/tabline_spec.lua index aa7b432c09..2d5faf394b 100644 --- a/test/functional/ui/tabline_spec.lua +++ b/test/functional/ui/tabline_spec.lua @@ -1,10 +1,10 @@ local helpers = require('test.functional.helpers')(after_each) local Screen = require('test.functional.ui.screen') -local clear, feed, eq = helpers.clear, helpers.feed, helpers.eq +local clear, command, eq = helpers.clear, helpers.command, helpers.eq describe('ui/tabline', function() local screen - local tabs, curtab + local event_tabs, event_curtab before_each(function() clear() @@ -12,7 +12,7 @@ describe('ui/tabline', function() screen:attach({rgb=true, ext_tabline=true}) screen:set_on_event_handler(function(name, data) if name == "tabline_update" then - curtab, tabs = unpack(data) + event_curtab, event_tabs = unpack(data) end end) end) @@ -23,11 +23,12 @@ describe('ui/tabline', function() describe('externalized', function() it('publishes UI events', function() - local expected = { - {1, {['name'] = '[No Name]'}}, - {2, {['name'] = '[No Name]'}}, + command("tabedit another-tab") + + local expected_tabs = { + {tab = { id = 1 }, name = '[No Name]'}, + {tab = { id = 2 }, name = 'another-tab'}, } - feed(":tabnew") screen:expect([[ ^ | ~ | @@ -35,11 +36,11 @@ describe('ui/tabline', function() ~ | | ]], nil, nil, function() - eq(2, curtab) - eq(expected, tabs) + eq(2, event_curtab) + eq(expected_tabs, event_tabs) end) - feed(":tabNext") + command("tabNext") screen:expect([[ ^ | ~ | @@ -47,8 +48,8 @@ describe('ui/tabline', function() ~ | | ]], nil, nil, function() - eq(1, curtab) - eq(expected, tabs) + eq(1, event_curtab) + eq(expected_tabs, event_tabs) end) end) -- cgit From 67552621943a18cb38db8dc38bfb7639807ebdf5 Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Wed, 26 Apr 2017 14:51:21 +0200 Subject: test: inccommand_spec: Avoid indeterminism. (#6592) --- test/functional/ui/inccommand_spec.lua | 1 + 1 file changed, 1 insertion(+) (limited to 'test/functional') diff --git a/test/functional/ui/inccommand_spec.lua b/test/functional/ui/inccommand_spec.lua index a7be1a9dc8..8bdc4601c0 100644 --- a/test/functional/ui/inccommand_spec.lua +++ b/test/functional/ui/inccommand_spec.lua @@ -805,6 +805,7 @@ describe(":substitute, inccommand=split", function() it('does not show split window for :s/', function() feed("2gg") feed(":s/tw") + screen:sleep(1) screen:expect([[ Inc substitution on | two lines | -- cgit From e20691ccb47731b378e029e1223d3e87744f25c6 Mon Sep 17 00:00:00 2001 From: James McCoy Date: Wed, 26 Apr 2017 16:50:36 -0400 Subject: defaults_spec: Test changing :filetype/:syntax in -c, after defaults --- test/functional/options/defaults_spec.lua | 41 ++++++++++++++++++++++++------- 1 file changed, 32 insertions(+), 9 deletions(-) (limited to 'test/functional') diff --git a/test/functional/options/defaults_spec.lua b/test/functional/options/defaults_spec.lua index f43d8eeafa..dc73679bb4 100644 --- a/test/functional/options/defaults_spec.lua +++ b/test/functional/options/defaults_spec.lua @@ -23,13 +23,13 @@ describe('startup defaults', function() if helpers.pending_win32(pending) then return end local function expect_filetype(expected) - local screen = Screen.new(48, 4) + local screen = Screen.new(50, 4) screen:attach() command('filetype') screen:expect([[ - ^ | - ~ | - ~ | + ^ | + ~ | + ~ | ]]..expected ) end @@ -37,31 +37,49 @@ describe('startup defaults', function() it('enabled by `-u NORC`', function() init_session('-u', 'NORC') expect_filetype( - 'filetype detection:ON plugin:ON indent:ON |') + 'filetype detection:ON plugin:ON indent:ON |') end) it('disabled by `-u NONE`', function() init_session('-u', 'NONE') expect_filetype( - 'filetype detection:OFF plugin:OFF indent:OFF |') + 'filetype detection:OFF plugin:OFF indent:OFF |') end) it('overridden by early `filetype on`', function() init_session('-u', 'NORC', '--cmd', 'filetype on') expect_filetype( - 'filetype detection:ON plugin:OFF indent:OFF |') + 'filetype detection:ON plugin:OFF indent:OFF |') end) it('overridden by early `filetype plugin on`', function() init_session('-u', 'NORC', '--cmd', 'filetype plugin on') expect_filetype( - 'filetype detection:ON plugin:ON indent:OFF |') + 'filetype detection:ON plugin:ON indent:OFF |') end) it('overridden by early `filetype indent on`', function() init_session('-u', 'NORC', '--cmd', 'filetype indent on') expect_filetype( - 'filetype detection:ON plugin:OFF indent:ON |') + 'filetype detection:ON plugin:OFF indent:ON |') + end) + + it('adjusted by late `filetype off`', function() + init_session('-u', 'NORC', '-c', 'filetype off') + expect_filetype( + 'filetype detection:OFF plugin:(on) indent:(on) |') + end) + + it('adjusted by late `filetype plugin off`', function() + init_session('-u', 'NORC', '-c', 'filetype plugin off') + expect_filetype( + 'filetype detection:ON plugin:OFF indent:ON |') + end) + + it('adjusted by late `filetype indent off`', function() + init_session('-u', 'NORC', '-c', 'filetype indent off') + expect_filetype( + 'filetype detection:ON plugin:ON indent:OFF |') end) end) @@ -80,6 +98,11 @@ describe('startup defaults', function() init_session('-u', 'NORC', '--cmd', 'syntax off') eq(0, eval('exists("g:syntax_on")')) end) + + it('adjusted by late `syntax off`', function() + init_session('-u', 'NORC', '-c', 'syntax off') + eq(0, eval('exists("g:syntax_on")')) + end) end) describe('packpath', function() -- cgit From 7044aa6e8256844bc1bd23eb61d4a41ca6d418d0 Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Fri, 28 Apr 2017 07:01:46 +0200 Subject: api/ext_tabline: `curtab` should be a Tabpage handle. --- test/functional/ui/tabline_spec.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'test/functional') diff --git a/test/functional/ui/tabline_spec.lua b/test/functional/ui/tabline_spec.lua index 2d5faf394b..56331a33b5 100644 --- a/test/functional/ui/tabline_spec.lua +++ b/test/functional/ui/tabline_spec.lua @@ -36,7 +36,7 @@ describe('ui/tabline', function() ~ | | ]], nil, nil, function() - eq(2, event_curtab) + eq({ id = 2 }, event_curtab) eq(expected_tabs, event_tabs) end) @@ -48,7 +48,7 @@ describe('ui/tabline', function() ~ | | ]], nil, nil, function() - eq(1, event_curtab) + eq({ id = 1 }, event_curtab) eq(expected_tabs, event_tabs) end) -- 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/api/vim_spec.lua | 106 ++++++++++++++++++++++++++++++++++++++- test/functional/helpers.lua | 4 +- 2 files changed, 107 insertions(+), 3 deletions(-) (limited to 'test/functional') diff --git a/test/functional/api/vim_spec.lua b/test/functional/api/vim_spec.lua index 5b173f3196..d06dd4c487 100644 --- a/test/functional/api/vim_spec.lua +++ b/test/functional/api/vim_spec.lua @@ -9,6 +9,7 @@ local funcs = helpers.funcs local request = helpers.request local meth_pcall = helpers.meth_pcall local command = helpers.command +local wait = helpers.wait describe('api', function() before_each(clear) @@ -221,6 +222,109 @@ describe('api', function() end) end) + local function appendfile(fname, text) + local file = io.open(fname, 'a') + file:write(text) + file:flush() + file:close() + end + + describe('nvim_get_mode', function() + it("during normal-mode `g` returns blocking=true", function() + nvim("input", "o") -- add a line + eq({mode='i', blocking=false}, nvim("get_mode")) + nvim("input", [[]]) + eq(2, nvim("eval", "line('.')")) + eq({mode='n', blocking=false}, nvim("get_mode")) + + nvim("input", "g") + eq({mode='n', blocking=true}, nvim("get_mode")) + + nvim("input", "k") -- complete the operator + eq(1, nvim("eval", "line('.')")) -- verify the completed operator + eq({mode='n', blocking=false}, nvim("get_mode")) + end) + + it("returns the correct result multiple consecutive times", function() + for _ = 1,5 do + eq({mode='n', blocking=false}, nvim("get_mode")) + end + nvim("input", "g") + for _ = 1,4 do + eq({mode='n', blocking=true}, nvim("get_mode")) + end + nvim("input", "g") + for _ = 1,7 do + eq({mode='n', blocking=false}, nvim("get_mode")) + end + end) + + it("during normal-mode CTRL-W, returns blocking=true", function() + nvim("input", "") + eq({mode='n', blocking=true}, nvim("get_mode")) + + nvim("input", "s") -- complete the operator + eq(2, nvim("eval", "winnr('$')")) -- verify the completed operator + eq({mode='n', blocking=false}, nvim("get_mode")) + end) + + it("during press-enter prompt returns blocking=true", function() + eq({mode='n', blocking=false}, nvim("get_mode")) + command("echom 'msg1'") + command("echom 'msg2'") + command("echom 'msg3'") + command("echom 'msg4'") + command("echom 'msg5'") + eq({mode='n', blocking=false}, nvim("get_mode")) + nvim("input", ":messages") + eq({mode='r', blocking=true}, nvim("get_mode")) + end) + + it("during getchar() returns blocking=false", function() + nvim("input", ":let g:test_input = nr2char(getchar())") + -- Events are enabled during getchar(), RPC calls are *not* blocked. #5384 + eq({mode='n', blocking=false}, nvim("get_mode")) + eq(0, nvim("eval", "exists('g:test_input')")) + nvim("input", "J") + eq("J", nvim("eval", "g:test_input")) + eq({mode='n', blocking=false}, nvim("get_mode")) + end) + + -- TODO: bug #6247#issuecomment-286403810 + it("batched with input", function() + eq({mode='n', blocking=false}, nvim("get_mode")) + command("echom 'msg1'") + command("echom 'msg2'") + command("echom 'msg3'") + command("echom 'msg4'") + command("echom 'msg5'") + + local req = { + {'nvim_get_mode', {}}, + {'nvim_input', {':messages'}}, + {'nvim_get_mode', {}}, + {'nvim_eval', {'1'}}, + } + eq({{{mode='n', blocking=false}, + 13, + {mode='n', blocking=false}, -- TODO: should be blocked=true + 1}, + NIL}, meths.call_atomic(req)) + eq({mode='r', blocking=true}, nvim("get_mode")) + end) + -- TODO: bug #6166 + it("during insert-mode map-pending, returns blocking=true #6166", function() + command("inoremap xx foo") + nvim("input", "ix") + eq({mode='i', blocking=true}, nvim("get_mode")) + end) + -- TODO: bug #6166 + it("during normal-mode gU, returns blocking=false #6166", function() + nvim("input", "gu") + eq({mode='no', blocking=false}, nvim("get_mode")) + end) + end) + describe('nvim_replace_termcodes', function() it('escapes K_SPECIAL as K_SPECIAL KS_SPECIAL KE_FILLER', function() eq('\128\254X', helpers.nvim('replace_termcodes', '\128', true, true, true)) @@ -459,7 +563,7 @@ describe('api', function() eq(very_long_name, err:match('Ax+Z?')) end) - it("doesn't leak memory on incorrect argument types", function() + it("does not leak memory on incorrect argument types", function() local status, err = pcall(nvim, 'set_current_dir',{'not', 'a', 'dir'}) eq(false, status) ok(err:match(': Wrong type for argument 1, expecting String') ~= nil) 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 From acfd2a2a29ae852ecc965ca888eb5049400bf39d Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Tue, 14 Mar 2017 00:44:03 +0100 Subject: input.c: Process only safe events before blocking. Introduce multiqueue_process_priority() to process only events at or above a certain priority. --- test/functional/api/vim_spec.lua | 8 -------- 1 file changed, 8 deletions(-) (limited to 'test/functional') diff --git a/test/functional/api/vim_spec.lua b/test/functional/api/vim_spec.lua index d06dd4c487..7c79d8832f 100644 --- a/test/functional/api/vim_spec.lua +++ b/test/functional/api/vim_spec.lua @@ -9,7 +9,6 @@ local funcs = helpers.funcs local request = helpers.request local meth_pcall = helpers.meth_pcall local command = helpers.command -local wait = helpers.wait describe('api', function() before_each(clear) @@ -222,13 +221,6 @@ describe('api', function() end) end) - local function appendfile(fname, text) - local file = io.open(fname, 'a') - file:write(text) - file:flush() - file:close() - end - describe('nvim_get_mode', function() it("during normal-mode `g` returns blocking=true", function() nvim("input", "o") -- add a line -- cgit From 4488bfcfb3c4abc71a78393595dc13f57a7cfbf0 Mon Sep 17 00:00:00 2001 From: James McCoy Date: Sat, 29 Apr 2017 22:28:21 -0400 Subject: oldfiles_spec: Set the shada file in the session --- test/functional/ex_cmds/oldfiles_spec.lua | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'test/functional') diff --git a/test/functional/ex_cmds/oldfiles_spec.lua b/test/functional/ex_cmds/oldfiles_spec.lua index 656b3f9bae..601ede366d 100644 --- a/test/functional/ex_cmds/oldfiles_spec.lua +++ b/test/functional/ex_cmds/oldfiles_spec.lua @@ -5,12 +5,13 @@ local buf, eq, feed_command = helpers.curbufmeths, helpers.eq, helpers.feed_comm local feed, nvim_prog, wait = helpers.feed, helpers.nvim_prog, helpers.wait local ok, set_session, spawn = helpers.ok, helpers.set_session, helpers.spawn -local shada_file = 'test.shada' +local shada_file = 'Xtest.shada' local function _clear() - set_session(spawn({nvim_prog, '--embed', '-u', 'NONE', '--cmd', + set_session(spawn({nvim_prog, '--embed', '-u', 'NONE', -- Need shada for these tests. - 'set noswapfile undodir=. directory=. viewdir=. backupdir=. belloff= noshowcmd noruler'})) + '-i', shada_file, + '--cmd', 'set noswapfile undodir=. directory=. viewdir=. backupdir=. belloff= noshowcmd noruler'})) end describe(':oldfiles', function() @@ -29,8 +30,8 @@ describe(':oldfiles', function() screen:attach() feed_command('edit testfile1') feed_command('edit testfile2') - feed_command('wshada ' .. shada_file) - feed_command('rshada! ' .. shada_file) + feed_command('wshada') + feed_command('rshada!') local oldfiles = helpers.meths.get_vvar('oldfiles') feed_command('oldfiles') screen:expect([[ @@ -54,10 +55,9 @@ describe(':browse oldfiles', function() filename = buf.get_name() feed_command('edit testfile2') filename2 = buf.get_name() - feed_command('wshada ' .. shada_file) + feed_command('wshada') wait() _clear() - feed_command('rshada! ' .. shada_file) -- Ensure nvim is out of "Press ENTER..." prompt. feed('') -- cgit From 35d817e68c9d1f2fd724bf00ad6f1958a0c815a9 Mon Sep 17 00:00:00 2001 From: James McCoy Date: Sat, 29 Apr 2017 23:46:57 -0400 Subject: oldfiles_spec: Add tests for ":filter ... oldfiles" --- test/functional/ex_cmds/oldfiles_spec.lua | 33 +++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) (limited to 'test/functional') diff --git a/test/functional/ex_cmds/oldfiles_spec.lua b/test/functional/ex_cmds/oldfiles_spec.lua index 601ede366d..4002855c24 100644 --- a/test/functional/ex_cmds/oldfiles_spec.lua +++ b/test/functional/ex_cmds/oldfiles_spec.lua @@ -4,6 +4,7 @@ local helpers = require('test.functional.helpers')(after_each) local buf, eq, feed_command = helpers.curbufmeths, helpers.eq, helpers.feed_command local feed, nvim_prog, wait = helpers.feed, helpers.nvim_prog, helpers.wait local ok, set_session, spawn = helpers.ok, helpers.set_session, helpers.spawn +local eval = helpers.eval local shada_file = 'Xtest.shada' @@ -42,6 +43,38 @@ describe(':oldfiles', function() Press ENTER or type command to continue^ | ]]) end) + + it('can be filtered with :filter', function() + feed_command('edit file_one.txt') + local file1 = buf.get_name() + feed_command('edit file_two.txt') + local file2 = buf.get_name() + feed_command('edit another.txt') + local another = buf.get_name() + feed_command('wshada') + feed_command('rshada!') + + local function get_oldfiles(cmd) + local t = eval([[split(execute(']]..cmd..[['), "\n")]]) + for i, _ in ipairs(t) do + t[i] = t[i]:gsub('^%d+:%s+', '') + end + table.sort(t) + return t + end + + local oldfiles = get_oldfiles('oldfiles') + eq({another, file1, file2}, oldfiles) + + oldfiles = get_oldfiles('filter file_ oldfiles') + eq({file1, file2}, oldfiles) + + oldfiles = get_oldfiles('filter /another/ oldfiles') + eq({another}, oldfiles) + + oldfiles = get_oldfiles('filter! file_ oldfiles') + eq({another}, oldfiles) + end) end) describe(':browse oldfiles', function() -- cgit From d349f610ac9010cecb550c33fbab632b4e7946ca Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Wed, 26 Apr 2017 01:43:03 +0200 Subject: 'guicursor': No color/blink by default Closes #6577 --- test/functional/ui/cursor_spec.lua | 141 +++++++++++++++++++++++-------------- 1 file changed, 87 insertions(+), 54 deletions(-) (limited to 'test/functional') diff --git a/test/functional/ui/cursor_spec.lua b/test/functional/ui/cursor_spec.lua index abe0e0b1fd..e6036a6b79 100644 --- a/test/functional/ui/cursor_spec.lua +++ b/test/functional/ui/cursor_spec.lua @@ -20,102 +20,102 @@ describe('ui/cursor', function() it("'guicursor' is published as a UI event", function() local expected_mode_info = { [1] = { - blinkoff = 250, - blinkon = 400, - blinkwait = 700, + blinkoff = 0, + blinkon = 0, + blinkwait = 0, cell_percentage = 0, cursor_shape = 'block', name = 'normal', - hl_id = 46, - id_lm = 47, + hl_id = 0, + id_lm = 0, mouse_shape = 0, short_name = 'n' }, [2] = { - blinkoff = 250, - blinkon = 400, - blinkwait = 700, + blinkoff = 0, + blinkon = 0, + blinkwait = 0, cell_percentage = 0, cursor_shape = 'block', name = 'visual', - hl_id = 46, - id_lm = 47, + hl_id = 0, + id_lm = 0, mouse_shape = 0, short_name = 'v' }, [3] = { - blinkoff = 250, - blinkon = 400, - blinkwait = 700, + blinkoff = 0, + blinkon = 0, + blinkwait = 0, cell_percentage = 25, cursor_shape = 'vertical', name = 'insert', - hl_id = 46, - id_lm = 47, + hl_id = 0, + id_lm = 0, mouse_shape = 0, short_name = 'i' }, [4] = { - blinkoff = 250, - blinkon = 400, - blinkwait = 700, + blinkoff = 0, + blinkon = 0, + blinkwait = 0, cell_percentage = 20, cursor_shape = 'horizontal', name = 'replace', - hl_id = 46, - id_lm = 47, + hl_id = 0, + id_lm = 0, mouse_shape = 0, short_name = 'r' }, [5] = { - blinkoff = 250, - blinkon = 400, - blinkwait = 700, + blinkoff = 0, + blinkon = 0, + blinkwait = 0, cell_percentage = 0, cursor_shape = 'block', name = 'cmdline_normal', - hl_id = 46, - id_lm = 47, + hl_id = 0, + id_lm = 0, mouse_shape = 0, short_name = 'c' }, [6] = { - blinkoff = 250, - blinkon = 400, - blinkwait = 700, + blinkoff = 0, + blinkon = 0, + blinkwait = 0, cell_percentage = 25, cursor_shape = 'vertical', name = 'cmdline_insert', - hl_id = 46, - id_lm = 47, + hl_id = 0, + id_lm = 0, mouse_shape = 0, short_name = 'ci' }, [7] = { - blinkoff = 250, - blinkon = 400, - blinkwait = 700, + blinkoff = 0, + blinkon = 0, + blinkwait = 0, cell_percentage = 20, cursor_shape = 'horizontal', name = 'cmdline_replace', - hl_id = 46, - id_lm = 47, + hl_id = 0, + id_lm = 0, mouse_shape = 0, short_name = 'cr' }, [8] = { - blinkoff = 250, - blinkon = 400, - blinkwait = 700, - cell_percentage = 50, + blinkoff = 0, + blinkon = 0, + blinkwait = 0, + cell_percentage = 20, cursor_shape = 'horizontal', name = 'operator', - hl_id = 46, - id_lm = 46, + hl_id = 0, + id_lm = 0, mouse_shape = 0, short_name = 'o' }, [9] = { - blinkoff = 250, - blinkon = 400, - blinkwait = 700, - cell_percentage = 35, + blinkoff = 0, + blinkon = 0, + blinkwait = 0, + cell_percentage = 25, cursor_shape = 'vertical', name = 'visual_select', - hl_id = 46, - id_lm = 46, + hl_id = 0, + id_lm = 0, mouse_shape = 0, short_name = 've' }, [10] = { @@ -147,19 +147,19 @@ describe('ui/cursor', function() mouse_shape = 0, short_name = 'ml' }, [17] = { - blinkoff = 150, - blinkon = 175, - blinkwait = 175, + blinkoff = 0, + blinkon = 0, + blinkwait = 0, cell_percentage = 0, cursor_shape = 'block', name = 'showmatch', - hl_id = 46, - id_lm = 46, + hl_id = 0, + id_lm = 0, short_name = 'sm' }, } screen:expect(function() - -- Default 'guicursor' published on startup. + -- Default 'guicursor', published on startup. eq(expected_mode_info, screen._mode_info) eq(true, screen._cursor_style_enabled) eq('normal', screen.mode) @@ -179,20 +179,53 @@ describe('ui/cursor', function() end) -- Change the cursor style. - meths.set_option('guicursor', 'n-v-c:ver35-blinkwait171-blinkoff172-blinkon173,ve:hor35,o:ver50,i-ci:block,r-cr:hor90,sm:ver42') + helpers.command('set guicursor=n-v-c:block,i-ci-ve:ver25,r-cr-o:hor20' + ..',a:blinkwait700-blinkoff400-blinkon250-Cursor/lCursor' + ..',sm:block-blinkwait175-blinkoff150-blinkon175') + + -- Update the expected values. + for _, m in ipairs(expected_mode_info) do + if m.name == 'showmatch' then + if m.blinkon then m.blinkon = 175 end + if m.blinkoff then m.blinkoff = 150 end + if m.blinkwait then m.blinkwait = 175 end + else + if m.blinkon then m.blinkon = 250 end + if m.blinkoff then m.blinkoff = 400 end + if m.blinkwait then m.blinkwait = 700 end + end + if m.hl_id then m.hl_id = 46 end + if m.id_lm then m.id_lm = 47 end + end + + -- Assert the new expectation. + screen:expect(function() + eq(expected_mode_info, screen._mode_info) + eq(true, screen._cursor_style_enabled) + eq('normal', screen.mode) + end) + + -- Another cursor style. + meths.set_option('guicursor', 'n-v-c:ver35-blinkwait171-blinkoff172-blinkon173' + ..',ve:hor35,o:ver50,i-ci:block,r-cr:hor90,sm:ver42') screen:expect(function() local named = {} for _, m in ipairs(screen._mode_info) do named[m.name] = m end eq('vertical', named.normal.cursor_shape) + eq(35, named.normal.cell_percentage) eq('horizontal', named.visual_select.cursor_shape) + eq(35, named.visual_select.cell_percentage) eq('vertical', named.operator.cursor_shape) + eq(50, named.operator.cell_percentage) eq('block', named.insert.cursor_shape) eq('vertical', named.showmatch.cursor_shape) + eq(90, named.cmdline_replace.cell_percentage) eq(171, named.normal.blinkwait) eq(172, named.normal.blinkoff) eq(173, named.normal.blinkon) + eq(42, named.showmatch.cell_percentage) end) end) -- cgit From 52727d98d76983f73e214369fe98ef541031395c Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Mon, 1 May 2017 18:59:02 +0200 Subject: NVIM v0.2.0 FEATURES: bc4a2e1576c6 help, man.vim: "outline" (TOC) feature #5169 58422f17d8e7 'guicursor' works in the TUI (and sends info to UIs) #6423 129f107c0c26 api: nvim_get_mode() #6247 0b59f988f447 api/ui: externalize tabline #6583 bc6d868d00a7 'listchars': `Whitespace` highlight group #6367 6afa7d66cd63 writefile() obeys 'fsync' option #6427 c60e409471c5 eval.c refactor (also improves some error messages) #5119 9d200cd0a3ef getcompletion("cmdline") #6376 2ea7bfc627e5 terminal: Support extra arguments in 'shell'. #4504 bf5110266ca9 DirChanged autocmd #5928 #6262 1743df82f900 'cpoptions': "_" flag to toggle `cw` behaviour #6235 22337b1c0144 CTRL-R omits trailing ^M when pasting to cmdline #6137 0e44916fff88 :edit allows unescaped spaces in filename #6119 abdbfd26bc7f eval: Add id() function and make printf("%p") useful #6095 bdfa1479d296 findfile(), :find, gf work in :terminal. #6009 2f38ed11c98a providers: Disable if `g:loaded_*` exists. b5560a69b12b setpos() can set lowercase marks in other buffers #5753 7c513d646d87 Throttle :! output, pulse "..." message. #5396 d2e8c76dc224 v:exiting #5651 :terminal improvements #6185 #6142 - cursor keeps position after leaving insert-mode. - 4ceec30cd0b4 Follows output only if cursor is at end of buffer. - e7bbd35c812d new option: 'scrollback' - fedb8443d58a quasi-support for undo and 'modifiable' - b45ddf731be5 disables 'list' by default - disables 'relativenumber' by default :help now contains full API documentation at `:help api`. man.vim saw numerous improvements. Windows support: - Windows is no longer "experimental", it is fully supported. - Windows package includes a GUI, curl.exe and other utilities. "Vim 8" features: partials, lambdas. SECURITY FIXES: CVE-2017-5953 CVE-2017-6349 CVE-2017-6350 #6485 CHANGES: NVIM_TUI_ENABLE_CURSOR_SHAPE was removed. Use 'guicursor' instead. See https://github.com/neovim/neovim/wiki/Following-HEAD#20170402 81525dc5c35c 'mouse=a' is no longer the default. (This will probably change again after it is improved.) #6022 0c1f7831649e defaults: 'showcmd', 'belloff', 'ruler' #6087 eb0e94f71b1f api: {get,set}_option update local options as appropriate #6405 bdcb2a38b366 "Reading from stdin..." message was removed. #6298 FIXES: 12fc1defd6a1 ops: fix i with multi-byte text #6524 dd391bfca1f3 Windows: system() and friends #6497 13352c00f190 Windows: os_get_hostname() #6413 16babc66870b tui: Less-noisy mouse seqs #6411 3a9dd13f9e64 (vim bug) folding edge-cases #6207 f6946c68aee9 job-control: set CLOEXEC on pty processes. #5986 d1afd434f302 rplugin: Call s:LoadRemotePlugins() on startup. 1215084676f0 backtick-expansion works with `shell=fish` #6224 e32ec03d67ee tui: Improved behavior after resize. #6202 86c2adc07463 edit.c: CTRL-SPC: Insert previously-inserted text. #6090 c318d8e672a3 b:changedtick now follows VimL rules #6112 34e24cb2f734 terminal: Initialize colors in reverse order #6160 e8899178ec34 undo: Don't set b_u_curhead in ex_undojoin() #5869 d25649fa0120 undo: :earlier, g-: Set b_u_seq_cur correctly. (#6016) 043d8ba422b4 'Visual-mode put from @. register' #5782 42c922b32c0a open_buffer(): Do `BufEnter` for directories. 50d0d891299c inccommand: Preview :sub commands only after delimiter #5932 1420e1047454 CheckHealth improvements #5519 c8d5e9230ee3 jobstart(): Return -1 if cmd is not executable. #5671 --- test/functional/fixtures/api_level_2.mpack | Bin 0 -> 16949 bytes 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 test/functional/fixtures/api_level_2.mpack (limited to 'test/functional') diff --git a/test/functional/fixtures/api_level_2.mpack b/test/functional/fixtures/api_level_2.mpack new file mode 100644 index 0000000000..0ca2ba8866 Binary files /dev/null and b/test/functional/fixtures/api_level_2.mpack differ -- cgit From de50c003d5b1097f93690a0d9dc5fb03a2818024 Mon Sep 17 00:00:00 2001 From: James McCoy Date: Wed, 3 May 2017 04:12:38 -0400 Subject: Use vim_strchr(s, c) when c may be NUL (#6656) As part of the refactoring in #5119, some vim_strchr() were changed to strchr(). However, vim_strchr() behaves differently than strchr() when c is NUL, returning NULL instead of a pointer to the NUL. Revert the strchr() calls where it isn't known whether c is NUL, since this causes a semantic change the surrounding code doesn't expect. In the case of #6650, this led to a heap overrun. Closes #6650 --- test/functional/ui/wildmode_spec.lua | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'test/functional') diff --git a/test/functional/ui/wildmode_spec.lua b/test/functional/ui/wildmode_spec.lua index 6639bf272d..052cdd55a1 100644 --- a/test/functional/ui/wildmode_spec.lua +++ b/test/functional/ui/wildmode_spec.lua @@ -31,6 +31,27 @@ describe("'wildmode'", function() :sign define^ | ]]) end) + + it('does not crash after cycling back to original text', function() + command('set wildmode=full') + feed(':j') + screen:expect([[ + | + ~ | + ~ | + join jumps | + :j^ | + ]]) + -- This would cause nvim to crash before #6650 + feed('') + screen:expect([[ + | + ~ | + ~ | + ! # & < = > @ > | + :!^ | + ]]) + end) end) end) -- cgit From 052c2d0a0f68a210038123608c00d4e0ff360161 Mon Sep 17 00:00:00 2001 From: Jonathan de Boyne Pollard Date: Wed, 3 May 2017 19:47:03 +0100 Subject: tui: Also fix "linux*" terminfo entries. #6673 The terminfo entry for linux only advertises 8 colours, but nvim tries to make it display 16 colours anyway, resulting in erroneous SGR control sequences for colours 8 and above. The Linux kernel terminal emulator itself has actually understood the 256-colour control sequences since version 4.8 and the 16-colour control sequences since version 4.9. Thus we apply the same terminfo fixup as we apply for *xterm* and *256*, to emit the 16-colour and 256-colour control sequences even if terminfo's setaf and setab do not advertise them. --- test/functional/terminal/tui_spec.lua | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'test/functional') diff --git a/test/functional/terminal/tui_spec.lua b/test/functional/terminal/tui_spec.lua index b14bceecdd..3ed63f68e9 100644 --- a/test/functional/terminal/tui_spec.lua +++ b/test/functional/terminal/tui_spec.lua @@ -356,9 +356,17 @@ describe("tui 't_Co' (terminal colors)", function() assert_term_colors("yet-another-term", "screen-256color", 256) end) - it("TERM=linux uses 8 colors", function() + it("TERM=linux uses 256 colors", function() if is_linux then - assert_term_colors("linux", nil, 8) + assert_term_colors("linux", nil, 256) + else + pending() + end + end) + + it("TERM=linux-16color uses 256 colors", function() + if is_linux then + assert_term_colors("linux-16color", nil, 256) else pending() end -- cgit