From 3d25200127bfec90982e82cb3d1fb65f8faff257 Mon Sep 17 00:00:00 2001 From: ZyX Date: Sun, 26 Mar 2017 04:04:23 +0300 Subject: functests: Start adding some tests --- test/functional/ui/cmdline_highlight_spec.lua | 101 ++++++++++++++++++++++++++ 1 file changed, 101 insertions(+) create mode 100644 test/functional/ui/cmdline_highlight_spec.lua (limited to 'test') diff --git a/test/functional/ui/cmdline_highlight_spec.lua b/test/functional/ui/cmdline_highlight_spec.lua new file mode 100644 index 0000000000..812841ab7e --- /dev/null +++ b/test/functional/ui/cmdline_highlight_spec.lua @@ -0,0 +1,101 @@ +local helpers = require('test.functional.helpers')(after_each) +local Screen = require('test.functional.ui.screen') + +local feed = helpers.feed +local clear = helpers.clear +local meths = helpers.meths +local source = helpers.source + +local screen + +before_each(function() + clear() + screen = Screen.new(40, 2) + screen:attach() + source([[ + highlight RBP1 guifg=Red + highlight RBP2 guifg=Yellow + highlight RBP3 guifg=Green + highlight RBP4 guifg=Blue + let g:NUM_LVLS = 4 + function Redraw() + redraw! + return '' + endfunction + cnoremap {REDRAW} Redraw() + function RainBowParens(cmdline) + let ret = [] + let i = 0 + let lvl = 0 + while i < len(a:cmdline) + if a:cmdline[i] is# '(' + call add(ret, [i, i + 1, 'RBP' . ((lvl % g:NUM_LVLS) + 1)]) + let lvl += 1 + elseif a:cmdline[i] is# ')' + let lvl -= 1 + call add(ret, [i, i + 1, 'RBP' . ((lvl % g:NUM_LVLS) + 1)]) + endif + let i += 1 + endwhile + return ret + endfunction + ]]) + screen:set_default_attr_ids({ + RBP1={foreground = Screen.colors.Red}, + RBP2={foreground = Screen.colors.Yellow}, + RBP3={foreground = Screen.colors.Green}, + RBP4={foreground = Screen.colors.Blue}, + }) +end) + +describe('Command-line coloring', function() + it('works', function() + meths.set_var('Nvim_color_cmdline', 'RainBowParens') + meths.set_option('more', false) + feed(':') + screen:expect([[ + | + :^ | + ]]) + feed('e') + screen:expect([[ + | + :e^ | + ]]) + feed('cho ') + screen:expect([[ + | + :echo ^ | + ]]) + feed('(') + screen:expect([[ + | + :echo {RBP1:(}^ | + ]]) + feed('(') + screen:expect([[ + | + :echo {RBP1:(}{RBP2:(}^ | + ]]) + feed('42') + screen:expect([[ + | + :echo {RBP1:(}{RBP2:(}42^ | + ]]) + feed('))') + screen:expect([[ + | + :echo {RBP1:(}{RBP2:(}42{RBP2:)}{RBP1:)}^ | + ]]) + feed('') + screen:expect([[ + | + :echo {RBP1:(}{RBP2:(}42{RBP2:)}^ | + ]]) + feed('{REDRAW}') + screen:expect([[ + | + :echo {RBP1:(}{RBP2:(}42{RBP2:)}^ | + ]]) + end) +end) -- cgit From d82741f8c04d003bb9925d9c46d7e07179810ed4 Mon Sep 17 00:00:00 2001 From: ZyX Date: Sun, 26 Mar 2017 17:25:03 +0300 Subject: ex_getln: Add some more tests, fix some found errors --- test/functional/ui/cmdline_highlight_spec.lua | 246 +++++++++++++++++++++++++- 1 file changed, 245 insertions(+), 1 deletion(-) (limited to 'test') diff --git a/test/functional/ui/cmdline_highlight_spec.lua b/test/functional/ui/cmdline_highlight_spec.lua index 812841ab7e..eb0a65bea7 100644 --- a/test/functional/ui/cmdline_highlight_spec.lua +++ b/test/functional/ui/cmdline_highlight_spec.lua @@ -1,16 +1,18 @@ local helpers = require('test.functional.helpers')(after_each) local Screen = require('test.functional.ui.screen') +local eq = helpers.eq local feed = helpers.feed local clear = helpers.clear local meths = helpers.meths +local funcs = helpers.funcs local source = helpers.source local screen before_each(function() clear() - screen = Screen.new(40, 2) + screen = Screen.new(40, 8) screen:attach() source([[ highlight RBP1 guifg=Red @@ -39,12 +41,74 @@ before_each(function() endwhile return ret endfunction + function SplittedMultibyteStart(cmdline) + let ret = [] + let i = 0 + while i < len(a:cmdline) + let char = nr2char(char2nr(a:cmdline[i:])) + if a:cmdline[i:i + len(char) - 1] is# char + if len(char) > 1 + call add(ret, [i + 1, i + len(char), 'RBP2']) + endif + let i += len(char) + else + let i += 1 + endif + endwhile + return ret + endfunction + function SplittedMultibyteEnd(cmdline) + let ret = [] + let i = 0 + while i < len(a:cmdline) + let char = nr2char(char2nr(a:cmdline[i:])) + if a:cmdline[i:i + len(char) - 1] is# char + if len(char) > 1 + call add(ret, [i, i + 1, 'RBP1']) + endif + let i += len(char) + else + let i += 1 + endif + endwhile + return ret + endfunction + function Echoing(cmdline) + echo 'HERE' + return v:_null_list + endfunction + function Echoning(cmdline) + echon 'HERE' + return v:_null_list + endfunction + function Echomsging(cmdline) + echomsg 'HERE' + return v:_null_list + endfunction + function Echoerring(cmdline) + echoerr 'HERE' + return v:_null_list + endfunction + function Redrawing(cmdline) + redraw! + return v:_null_list + endfunction + function Throwing(cmdline) + throw "ABC" + return v:_null_list + endfunction + function Halting(cmdline) + while 1 + endwhile + endfunction ]]) screen:set_default_attr_ids({ RBP1={foreground = Screen.colors.Red}, RBP2={foreground = Screen.colors.Yellow}, RBP3={foreground = Screen.colors.Green}, RBP4={foreground = Screen.colors.Blue}, + EOB={bold = true, foreground = Screen.colors.Blue1}, + ERR={foreground = Screen.colors.Grey100, background = Screen.colors.Red}, }) end) @@ -55,47 +119,227 @@ describe('Command-line coloring', function() feed(':') screen:expect([[ | + {EOB:~ }| + {EOB:~ }| + {EOB:~ }| + {EOB:~ }| + {EOB:~ }| + {EOB:~ }| :^ | ]]) feed('e') screen:expect([[ | + {EOB:~ }| + {EOB:~ }| + {EOB:~ }| + {EOB:~ }| + {EOB:~ }| + {EOB:~ }| :e^ | ]]) feed('cho ') screen:expect([[ | + {EOB:~ }| + {EOB:~ }| + {EOB:~ }| + {EOB:~ }| + {EOB:~ }| + {EOB:~ }| :echo ^ | ]]) feed('(') screen:expect([[ | + {EOB:~ }| + {EOB:~ }| + {EOB:~ }| + {EOB:~ }| + {EOB:~ }| + {EOB:~ }| :echo {RBP1:(}^ | ]]) feed('(') screen:expect([[ | + {EOB:~ }| + {EOB:~ }| + {EOB:~ }| + {EOB:~ }| + {EOB:~ }| + {EOB:~ }| :echo {RBP1:(}{RBP2:(}^ | ]]) feed('42') screen:expect([[ | + {EOB:~ }| + {EOB:~ }| + {EOB:~ }| + {EOB:~ }| + {EOB:~ }| + {EOB:~ }| :echo {RBP1:(}{RBP2:(}42^ | ]]) feed('))') screen:expect([[ | + {EOB:~ }| + {EOB:~ }| + {EOB:~ }| + {EOB:~ }| + {EOB:~ }| + {EOB:~ }| :echo {RBP1:(}{RBP2:(}42{RBP2:)}{RBP1:)}^ | ]]) feed('') screen:expect([[ | + {EOB:~ }| + {EOB:~ }| + {EOB:~ }| + {EOB:~ }| + {EOB:~ }| + {EOB:~ }| :echo {RBP1:(}{RBP2:(}42{RBP2:)}^ | ]]) feed('{REDRAW}') screen:expect([[ | + {EOB:~ }| + {EOB:~ }| + {EOB:~ }| + {EOB:~ }| + {EOB:~ }| + {EOB:~ }| :echo {RBP1:(}{RBP2:(}42{RBP2:)}^ | ]]) end) + for _, func_part in ipairs({'', 'n', 'msg'}) do + it('disables :echo' .. func_part .. ' messages', function() + meths.set_var('Nvim_color_cmdline', 'Echo' .. func_part .. 'ing') + feed(':echo') + screen:expect([[ + | + {EOB:~ }| + {EOB:~ }| + {EOB:~ }| + {EOB:~ }| + {EOB:~ }| + {EOB:~ }| + :echo^ | + ]]) + end) + end + it('does the right thing when hl start appears to split multibyte char', + function() + meths.set_var('Nvim_color_cmdline', 'SplittedMultibyteStart') + feed(':echo "«') + screen:expect([[ + {EOB:~ }| + :echo " | + {ERR:E5405: Chunk 0 start 7 splits multibyte }| + {ERR:character} | + :echo "« | + {ERR:E5405: Chunk 0 start 7 splits multibyte }| + {ERR:character} | + :echo "«^ | + ]]) + feed('»') + -- FIXME Does not work well with too much error messages: they overwrite + -- cmdline. + end) + it('does the right thing when hl end appears to split multibyte char', + function() + meths.set_var('Nvim_color_cmdline', 'SplittedMultibyteEnd') + feed(':echo "«') + screen:expect([[ + {EOB:~ }| + :echo " | + {ERR:E5406: Chunk 0 end 7 splits multibyte ch}| + {ERR:aracter} | + :echo "« | + {ERR:E5406: Chunk 0 end 7 splits multibyte ch}| + {ERR:aracter} | + :echo "«^ | + ]]) + end) + it('does the right thing when errorring', function() + meths.set_var('Nvim_color_cmdline', 'Echoerring') + feed(':e') + -- FIXME Does not work well with :echoerr: error message overwrites cmdline. + end) + it('does the right thing when throwing', function() + meths.set_var('Nvim_color_cmdline', 'Throwing') + feed(':e') + -- FIXME Does not work well with :throw: error message overwrites cmdline. + end) + it('still executes command-line even if errored out', function() + meths.set_var('Nvim_color_cmdline', 'SplittedMultibyteStart') + feed(':let x = "«"\n') + eq('«', meths.get_var('x')) + local msg = 'E5405: Chunk 0 start 10 splits multibyte character' + eq('\n'..msg..'\n'..msg, funcs.execute('messages')) + end) + it('stops executing callback after a number of errors', function() + meths.set_var('Nvim_color_cmdline', 'SplittedMultibyteStart') + feed(':let x = "«»«»«»«»«»"\n') + eq('«»«»«»«»«»', meths.get_var('x')) + local msg = '\nE5405: Chunk 0 start 10 splits multibyte character' + eq(msg:rep(5), funcs.execute('messages')) + end) + it('allows interrupting callback with ', function() + meths.set_var('Nvim_color_cmdline', 'Halting') + feed(':echo 42') + for i = 1, 6 do + screen:expect([[ + ^ | + {EOB:~ }| + {EOB:~ }| + {EOB:~ }| + {EOB:~ }| + {EOB:~ }| + {EOB:~ }| + | + ]]) + feed('') + end + screen:expect([[ + ^ | + {EOB:~ }| + {EOB:~ }| + {EOB:~ }| + {EOB:~ }| + {EOB:~ }| + {EOB:~ }| + Type :quit to exit Nvim | + ]]) + feed(':echo 42') + screen:expect([[ + ^ | + {EOB:~ }| + {EOB:~ }| + {EOB:~ }| + {EOB:~ }| + {EOB:~ }| + {EOB:~ }| + 42 | + ]]) + end) + it('works fine with NUL, NL, CR', function() + meths.set_var('Nvim_color_cmdline', 'RainBowParens') + feed(':echo ("")') + screen:expect([[ + | + {EOB:~ }| + {EOB:~ }| + {EOB:~ }| + {EOB:~ }| + {EOB:~ }| + {EOB:~ }| + :echo {RBP1:(}"{RBP4:^M^@^@}"{RBP1:)}^ | + ]]) + end) + -- TODO Check for all other errors end) -- cgit From 407abb3a6c5c1c706bf8797a1431e57e97a6b797 Mon Sep 17 00:00:00 2001 From: ZyX Date: Sun, 2 Apr 2017 01:00:40 +0300 Subject: eval,ex_getln: Add support for coloring input() prompts --- test/functional/eval/input_spec.lua | 57 +++++++++++++++++++++++++++ test/functional/ui/cmdline_highlight_spec.lua | 50 ++++++++++++++--------- 2 files changed, 88 insertions(+), 19 deletions(-) (limited to 'test') diff --git a/test/functional/eval/input_spec.lua b/test/functional/eval/input_spec.lua index 74ad32bc6c..f0c1314754 100644 --- a/test/functional/eval/input_spec.lua +++ b/test/functional/eval/input_spec.lua @@ -23,10 +23,41 @@ before_each(function() function CustomListCompl(...) return ['FOO'] endfunction + + highlight RBP1 guibg=Red + highlight RBP2 guibg=Yellow + highlight RBP3 guibg=Green + highlight RBP4 guibg=Blue + let g:NUM_LVLS = 4 + function Redraw() + redraw! + return '' + endfunction + cnoremap {REDRAW} Redraw() + function RainBowParens(cmdline) + let ret = [] + let i = 0 + let lvl = 0 + while i < len(a:cmdline) + if a:cmdline[i] is# '(' + call add(ret, [i, i + 1, 'RBP' . ((lvl % g:NUM_LVLS) + 1)]) + let lvl += 1 + elseif a:cmdline[i] is# ')' + let lvl -= 1 + call add(ret, [i, i + 1, 'RBP' . ((lvl % g:NUM_LVLS) + 1)]) + endif + let i += 1 + endwhile + return ret + endfunction ]]) screen:set_default_attr_ids({ EOB={bold = true, foreground = Screen.colors.Blue1}, T={foreground=Screen.colors.Red}, + RBP1={background=Screen.colors.Red}, + RBP2={background=Screen.colors.Yellow}, + RBP3={background=Screen.colors.Green}, + RBP4={background=Screen.colors.Blue}, }) end) @@ -196,6 +227,19 @@ describe('input()', function() eq('Vim(call):E118: Too many arguments for function: input', exc_exec('call input("prompt> ", "default", "file", "extra")')) end) + it('supports highlighting', function() + feed([[:call input({"highlight": "RainBowParens"})]]) + wait() + feed('(())') + wait() + screen:expect([[ + {EOB:~ }| + {EOB:~ }| + {EOB:~ }| + | + {RBP1:(}{RBP2:()}{RBP1:)}^ | + ]]) + end) end) describe('inputdialog()', function() it('works with multiline prompts', function() @@ -363,4 +407,17 @@ describe('inputdialog()', function() eq('Vim(call):E118: Too many arguments for function: inputdialog', exc_exec('call inputdialog("prompt> ", "default", "file", "extra")')) end) + it('supports highlighting', function() + feed([[:call inputdialog({"highlight": "RainBowParens"})]]) + wait() + feed('(())') + wait() + screen:expect([[ + {EOB:~ }| + {EOB:~ }| + {EOB:~ }| + | + {RBP1:(}{RBP2:()}{RBP1:)}^ | + ]]) + end) end) diff --git a/test/functional/ui/cmdline_highlight_spec.lua b/test/functional/ui/cmdline_highlight_spec.lua index eb0a65bea7..4ccfb44261 100644 --- a/test/functional/ui/cmdline_highlight_spec.lua +++ b/test/functional/ui/cmdline_highlight_spec.lua @@ -15,10 +15,10 @@ before_each(function() screen = Screen.new(40, 8) screen:attach() source([[ - highlight RBP1 guifg=Red - highlight RBP2 guifg=Yellow - highlight RBP3 guifg=Green - highlight RBP4 guifg=Blue + highlight RBP1 guibg=Red + highlight RBP2 guibg=Yellow + highlight RBP3 guibg=Green + highlight RBP4 guibg=Blue let g:NUM_LVLS = 4 function Redraw() redraw! @@ -103,12 +103,13 @@ before_each(function() endfunction ]]) screen:set_default_attr_ids({ - RBP1={foreground = Screen.colors.Red}, - RBP2={foreground = Screen.colors.Yellow}, - RBP3={foreground = Screen.colors.Green}, - RBP4={foreground = Screen.colors.Blue}, + RBP1={background = Screen.colors.Red}, + RBP2={background = Screen.colors.Yellow}, + RBP3={background = Screen.colors.Green}, + RBP4={background = Screen.colors.Blue}, EOB={bold = true, foreground = Screen.colors.Blue1}, ERR={foreground = Screen.colors.Grey100, background = Screen.colors.Red}, + SK={foreground = Screen.colors.Blue}, }) end) @@ -237,40 +238,50 @@ describe('Command-line coloring', function() meths.set_var('Nvim_color_cmdline', 'SplittedMultibyteStart') feed(':echo "«') screen:expect([[ + {EOB:~ }| + {EOB:~ }| + {EOB:~ }| {EOB:~ }| :echo " | {ERR:E5405: Chunk 0 start 7 splits multibyte }| {ERR:character} | - :echo "« | - {ERR:E5405: Chunk 0 start 7 splits multibyte }| - {ERR:character} | :echo "«^ | ]]) feed('»') - -- FIXME Does not work well with too much error messages: they overwrite - -- cmdline. + screen:expect([[ + {EOB:~ }| + {EOB:~ }| + {EOB:~ }| + {EOB:~ }| + :echo " | + {ERR:E5405: Chunk 0 start 7 splits multibyte }| + {ERR:character} | + :echo "«»^ | + ]]) end) it('does the right thing when hl end appears to split multibyte char', function() meths.set_var('Nvim_color_cmdline', 'SplittedMultibyteEnd') feed(':echo "«') screen:expect([[ + {EOB:~ }| + {EOB:~ }| + {EOB:~ }| {EOB:~ }| :echo " | {ERR:E5406: Chunk 0 end 7 splits multibyte ch}| {ERR:aracter} | - :echo "« | - {ERR:E5406: Chunk 0 end 7 splits multibyte ch}| - {ERR:aracter} | :echo "«^ | ]]) end) it('does the right thing when errorring', function() + if true then return pending('echoerr does not work well now') end meths.set_var('Nvim_color_cmdline', 'Echoerring') feed(':e') -- FIXME Does not work well with :echoerr: error message overwrites cmdline. end) it('does the right thing when throwing', function() + if true then return pending('Throwing does not work well now') end meths.set_var('Nvim_color_cmdline', 'Throwing') feed(':e') -- FIXME Does not work well with :throw: error message overwrites cmdline. @@ -280,16 +291,17 @@ describe('Command-line coloring', function() feed(':let x = "«"\n') eq('«', meths.get_var('x')) local msg = 'E5405: Chunk 0 start 10 splits multibyte character' - eq('\n'..msg..'\n'..msg, funcs.execute('messages')) + eq('\n'..msg, funcs.execute('messages')) end) it('stops executing callback after a number of errors', function() meths.set_var('Nvim_color_cmdline', 'SplittedMultibyteStart') feed(':let x = "«»«»«»«»«»"\n') eq('«»«»«»«»«»', meths.get_var('x')) local msg = '\nE5405: Chunk 0 start 10 splits multibyte character' - eq(msg:rep(5), funcs.execute('messages')) + eq(msg:rep(1), funcs.execute('messages')) end) it('allows interrupting callback with ', function() + if true then return pending(' does not work well enough now') end meths.set_var('Nvim_color_cmdline', 'Halting') feed(':echo 42') for i = 1, 6 do @@ -338,7 +350,7 @@ describe('Command-line coloring', function() {EOB:~ }| {EOB:~ }| {EOB:~ }| - :echo {RBP1:(}"{RBP4:^M^@^@}"{RBP1:)}^ | + :echo {RBP1:(}"{SK:^M^@^@}"{RBP1:)}^ | ]]) end) -- TODO Check for all other errors -- cgit From 95fe5614a02948bcd0993c751acede34d2acb3c8 Mon Sep 17 00:00:00 2001 From: ZyX Date: Mon, 22 May 2017 03:25:46 +0300 Subject: functests: Add missing wait() --- test/functional/eval/input_spec.lua | 1 + 1 file changed, 1 insertion(+) (limited to 'test') diff --git a/test/functional/eval/input_spec.lua b/test/functional/eval/input_spec.lua index f0c1314754..5b259d5440 100644 --- a/test/functional/eval/input_spec.lua +++ b/test/functional/eval/input_spec.lua @@ -2,6 +2,7 @@ local helpers = require('test.functional.helpers')(after_each) local Screen = require('test.functional.ui.screen') local eq = helpers.eq +local wait = helpers.wait local feed = helpers.feed local meths = helpers.meths local clear = helpers.clear -- cgit From 71616fce0b3db6618ef47e231f34853eef79fea0 Mon Sep 17 00:00:00 2001 From: ZyX Date: Tue, 27 Jun 2017 01:54:08 +0300 Subject: functests: Abstract away some ways to enter cmdline coloring mode Reason: should actually switch to using input() coloring because other coloring variants are eventually going away. --- test/functional/ui/cmdline_highlight_spec.lua | 49 +++++++++++++++------------ 1 file changed, 28 insertions(+), 21 deletions(-) (limited to 'test') diff --git a/test/functional/ui/cmdline_highlight_spec.lua b/test/functional/ui/cmdline_highlight_spec.lua index 4ccfb44261..278acf0bdf 100644 --- a/test/functional/ui/cmdline_highlight_spec.lua +++ b/test/functional/ui/cmdline_highlight_spec.lua @@ -113,11 +113,18 @@ before_each(function() }) end) +local function set_color_cb(funcname) + meths.set_var('Nvim_color_cmdline', funcname) +end +local function start_prompt(text) + feed(':' .. (text or '')) +end + describe('Command-line coloring', function() it('works', function() - meths.set_var('Nvim_color_cmdline', 'RainBowParens') + set_color_cb('RainBowParens') meths.set_option('more', false) - feed(':') + start_prompt() screen:expect([[ | {EOB:~ }| @@ -219,8 +226,8 @@ describe('Command-line coloring', function() end) for _, func_part in ipairs({'', 'n', 'msg'}) do it('disables :echo' .. func_part .. ' messages', function() - meths.set_var('Nvim_color_cmdline', 'Echo' .. func_part .. 'ing') - feed(':echo') + set_color_cb('Echo' .. func_part .. 'ing') + start_prompt('echo') screen:expect([[ | {EOB:~ }| @@ -235,8 +242,8 @@ describe('Command-line coloring', function() end it('does the right thing when hl start appears to split multibyte char', function() - meths.set_var('Nvim_color_cmdline', 'SplittedMultibyteStart') - feed(':echo "«') + set_color_cb('SplittedMultibyteStart') + start_prompt('echo "«') screen:expect([[ {EOB:~ }| {EOB:~ }| @@ -261,8 +268,8 @@ describe('Command-line coloring', function() end) it('does the right thing when hl end appears to split multibyte char', function() - meths.set_var('Nvim_color_cmdline', 'SplittedMultibyteEnd') - feed(':echo "«') + set_color_cb('SplittedMultibyteEnd') + start_prompt('echo "«') screen:expect([[ {EOB:~ }| {EOB:~ }| @@ -276,34 +283,34 @@ describe('Command-line coloring', function() end) it('does the right thing when errorring', function() if true then return pending('echoerr does not work well now') end - meths.set_var('Nvim_color_cmdline', 'Echoerring') - feed(':e') + set_color_cb('Echoerring') + start_prompt('e') -- FIXME Does not work well with :echoerr: error message overwrites cmdline. end) it('does the right thing when throwing', function() if true then return pending('Throwing does not work well now') end - meths.set_var('Nvim_color_cmdline', 'Throwing') - feed(':e') + set_color_cb('Throwing') + start_prompt('e') -- FIXME Does not work well with :throw: error message overwrites cmdline. end) it('still executes command-line even if errored out', function() - meths.set_var('Nvim_color_cmdline', 'SplittedMultibyteStart') - feed(':let x = "«"\n') + set_color_cb('SplittedMultibyteStart') + start_prompt('let x = "«"\n') eq('«', meths.get_var('x')) local msg = 'E5405: Chunk 0 start 10 splits multibyte character' eq('\n'..msg, funcs.execute('messages')) end) it('stops executing callback after a number of errors', function() - meths.set_var('Nvim_color_cmdline', 'SplittedMultibyteStart') - feed(':let x = "«»«»«»«»«»"\n') + set_color_cb('SplittedMultibyteStart') + start_prompt('let x = "«»«»«»«»«»"\n') eq('«»«»«»«»«»', meths.get_var('x')) local msg = '\nE5405: Chunk 0 start 10 splits multibyte character' eq(msg:rep(1), funcs.execute('messages')) end) it('allows interrupting callback with ', function() if true then return pending(' does not work well enough now') end - meths.set_var('Nvim_color_cmdline', 'Halting') - feed(':echo 42') + set_color_cb('Halting') + start_prompt('echo 42') for i = 1, 6 do screen:expect([[ ^ | @@ -327,7 +334,7 @@ describe('Command-line coloring', function() {EOB:~ }| Type :quit to exit Nvim | ]]) - feed(':echo 42') + start_prompt('echo 42') screen:expect([[ ^ | {EOB:~ }| @@ -340,8 +347,8 @@ describe('Command-line coloring', function() ]]) end) it('works fine with NUL, NL, CR', function() - meths.set_var('Nvim_color_cmdline', 'RainBowParens') - feed(':echo ("")') + set_color_cb('RainBowParens') + start_prompt('echo ("")') screen:expect([[ | {EOB:~ }| -- cgit From 8e5134784c8e15aabd458480bee1e445e8a04e94 Mon Sep 17 00:00:00 2001 From: ZyX Date: Tue, 27 Jun 2017 01:55:21 +0300 Subject: functests: Comment out failing test --- test/functional/ui/cmdline_highlight_spec.lua | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) (limited to 'test') diff --git a/test/functional/ui/cmdline_highlight_spec.lua b/test/functional/ui/cmdline_highlight_spec.lua index 278acf0bdf..a30489ec97 100644 --- a/test/functional/ui/cmdline_highlight_spec.lua +++ b/test/functional/ui/cmdline_highlight_spec.lua @@ -212,17 +212,18 @@ describe('Command-line coloring', function() {EOB:~ }| :echo {RBP1:(}{RBP2:(}42{RBP2:)}^ | ]]) - feed('{REDRAW}') - screen:expect([[ - | - {EOB:~ }| - {EOB:~ }| - {EOB:~ }| - {EOB:~ }| - {EOB:~ }| - {EOB:~ }| - :echo {RBP1:(}{RBP2:(}42{RBP2:)}^ | - ]]) + -- FIXME + -- feed('{REDRAW}') + -- screen:expect([[ + -- | + -- {EOB:~ }| + -- {EOB:~ }| + -- {EOB:~ }| + -- {EOB:~ }| + -- {EOB:~ }| + -- {EOB:~ }| + -- :echo {RBP1:(}{RBP2:(}42{RBP2:)}^ | + -- ]]) end) for _, func_part in ipairs({'', 'n', 'msg'}) do it('disables :echo' .. func_part .. ' messages', function() -- cgit From edc2a7ee460b9a77705c87ecccc41a22f6134bf8 Mon Sep 17 00:00:00 2001 From: ZyX Date: Tue, 27 Jun 2017 02:15:49 +0300 Subject: functests: Make tests work with input() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit There are still some issues: specifically, new “pending” test hangs busted. --- test/functional/ui/cmdline_highlight_spec.lua | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) (limited to 'test') diff --git a/test/functional/ui/cmdline_highlight_spec.lua b/test/functional/ui/cmdline_highlight_spec.lua index a30489ec97..6bb06b2ed3 100644 --- a/test/functional/ui/cmdline_highlight_spec.lua +++ b/test/functional/ui/cmdline_highlight_spec.lua @@ -25,6 +25,7 @@ before_each(function() return '' endfunction cnoremap {REDRAW} Redraw() + nnoremap {PROMPT} input({"prompt": ":", "highlight": g:Nvim_color_input})[1:0] function RainBowParens(cmdline) let ret = [] let i = 0 @@ -114,10 +115,10 @@ before_each(function() end) local function set_color_cb(funcname) - meths.set_var('Nvim_color_cmdline', funcname) + meths.set_var('Nvim_color_input', funcname) end local function start_prompt(text) - feed(':' .. (text or '')) + feed('{PROMPT}' .. (text or '')) end describe('Command-line coloring', function() @@ -294,20 +295,13 @@ describe('Command-line coloring', function() start_prompt('e') -- FIXME Does not work well with :throw: error message overwrites cmdline. end) - it('still executes command-line even if errored out', function() - set_color_cb('SplittedMultibyteStart') - start_prompt('let x = "«"\n') - eq('«', meths.get_var('x')) - local msg = 'E5405: Chunk 0 start 10 splits multibyte character' - eq('\n'..msg, funcs.execute('messages')) - end) - it('stops executing callback after a number of errors', function() + pending('stops executing callback after a number of errors'--[[, function() set_color_cb('SplittedMultibyteStart') start_prompt('let x = "«»«»«»«»«»"\n') eq('«»«»«»«»«»', meths.get_var('x')) local msg = '\nE5405: Chunk 0 start 10 splits multibyte character' eq(msg:rep(1), funcs.execute('messages')) - end) + end]]) it('allows interrupting callback with ', function() if true then return pending(' does not work well enough now') end set_color_cb('Halting') @@ -363,3 +357,14 @@ describe('Command-line coloring', function() end) -- TODO Check for all other errors end) +describe('Ex commands coloring support', function() + it('still executes command-line even if errored out', function() + meths.set_var('Nvim_color_cmdline', 'SplittedMultibyteStart') + feed(':let x = "«"\n') + eq('«', meths.get_var('x')) + local msg = 'E5405: Chunk 0 start 10 splits multibyte character' + eq('\n'..msg, funcs.execute('messages')) + end) +end) + +-- TODO Specifically test for coloring in cmdline and expr modes -- cgit From 36a84d8f4ab104050e6ec52da9ca6e10f9361a0c Mon Sep 17 00:00:00 2001 From: ZyX Date: Wed, 28 Jun 2017 13:54:04 +0300 Subject: functests: Fix typo --- test/functional/ui/screen.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test') diff --git a/test/functional/ui/screen.lua b/test/functional/ui/screen.lua index 5408e1e195..a6b7fb2997 100644 --- a/test/functional/ui/screen.lua +++ b/test/functional/ui/screen.lua @@ -251,7 +251,7 @@ function Screen:expect(expected, attr_ids, attr_ignore, condition, any) ..'Expected:\n |'..table.concat(msg_expected_rows, '|\n |')..'|\n' ..'Actual:\n |'..table.concat(actual_rows, '|\n |')..'|\n\n'..[[ To print the expect() call that would assert the current screen state, use -screen:snaphot_util(). In case of non-deterministic failures, use +screen:snapshot_util(). In case of non-deterministic failures, use screen:redraw_debug() to show all intermediate screen states. ]]) end end -- cgit From 493d250446e5323e64c80399f0c5a15621c4f15c Mon Sep 17 00:00:00 2001 From: ZyX Date: Wed, 28 Jun 2017 13:58:51 +0300 Subject: functests: Make “stops executing callback” test work MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Needed to be adjusted to use input() (previously relied on side-effects of executing `:cmd`) and dismiss something (hidden “Press ENTER” message?). --- test/functional/ui/cmdline_highlight_spec.lua | 30 +++++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-) (limited to 'test') diff --git a/test/functional/ui/cmdline_highlight_spec.lua b/test/functional/ui/cmdline_highlight_spec.lua index 6bb06b2ed3..12577a4db4 100644 --- a/test/functional/ui/cmdline_highlight_spec.lua +++ b/test/functional/ui/cmdline_highlight_spec.lua @@ -24,8 +24,9 @@ before_each(function() redraw! return '' endfunction + let g:EMPTY = '' cnoremap {REDRAW} Redraw() - nnoremap {PROMPT} input({"prompt": ":", "highlight": g:Nvim_color_input})[1:0] + nnoremap {PROMPT} extend(g:, {"out": input({"prompt": ":", "highlight": g:Nvim_color_input})}).EMPTY function RainBowParens(cmdline) let ret = [] let i = 0 @@ -295,13 +296,34 @@ describe('Command-line coloring', function() start_prompt('e') -- FIXME Does not work well with :throw: error message overwrites cmdline. end) - pending('stops executing callback after a number of errors'--[[, function() + it('stops executing callback after a number of errors', function() set_color_cb('SplittedMultibyteStart') start_prompt('let x = "«»«»«»«»«»"\n') - eq('«»«»«»«»«»', meths.get_var('x')) + screen:expect([[ + {EOB:~ }| + {EOB:~ }| + {EOB:~ }| + {EOB:~ }| + :let x = " | + {ERR:E5405: Chunk 0 start 10 splits multibyte}| + {ERR: character} | + ^:let x = "«»«»«»«»«»" | + ]]) + feed('\n') + screen:expect([[ + ^ | + {EOB:~ }| + {EOB:~ }| + {EOB:~ }| + {EOB:~ }| + {EOB:~ }| + {EOB:~ }| + | + ]]) + eq('let x = "«»«»«»«»«»"', meths.get_var('out')) local msg = '\nE5405: Chunk 0 start 10 splits multibyte character' eq(msg:rep(1), funcs.execute('messages')) - end]]) + end) it('allows interrupting callback with ', function() if true then return pending(' does not work well enough now') end set_color_cb('Halting') -- cgit From 0ed95423de714edac11ccff177b8aee6b7987bac Mon Sep 17 00:00:00 2001 From: ZyX Date: Wed, 28 Jun 2017 14:26:23 +0300 Subject: ex_getln: Call highlight callback inside :try --- test/functional/ui/cmdline_highlight_spec.lua | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) (limited to 'test') diff --git a/test/functional/ui/cmdline_highlight_spec.lua b/test/functional/ui/cmdline_highlight_spec.lua index 12577a4db4..8207a903f4 100644 --- a/test/functional/ui/cmdline_highlight_spec.lua +++ b/test/functional/ui/cmdline_highlight_spec.lua @@ -285,16 +285,23 @@ describe('Command-line coloring', function() ]]) end) it('does the right thing when errorring', function() - if true then return pending('echoerr does not work well now') end set_color_cb('Echoerring') start_prompt('e') - -- FIXME Does not work well with :echoerr: error message overwrites cmdline. + -- FIXME Does not work well with :echoerr: error message not shown. end) it('does the right thing when throwing', function() - if true then return pending('Throwing does not work well now') end set_color_cb('Throwing') start_prompt('e') - -- FIXME Does not work well with :throw: error message overwrites cmdline. + screen:expect([[ + {EOB:~ }| + {EOB:~ }| + {EOB:~ }| + {EOB:~ }| + : | + {ERR:E5407: Callback has thrown an exception:}| + {ERR: ABC} | + :e^ | + ]]) end) it('stops executing callback after a number of errors', function() set_color_cb('SplittedMultibyteStart') -- cgit From 5e4976559a0f3e104b3f349593ad184d08c56a89 Mon Sep 17 00:00:00 2001 From: ZyX Date: Wed, 28 Jun 2017 14:34:12 +0300 Subject: functests: Partially uncomment test --- test/functional/ui/cmdline_highlight_spec.lua | 40 +++++++++++++++++---------- 1 file changed, 26 insertions(+), 14 deletions(-) (limited to 'test') diff --git a/test/functional/ui/cmdline_highlight_spec.lua b/test/functional/ui/cmdline_highlight_spec.lua index 8207a903f4..f356db88b5 100644 --- a/test/functional/ui/cmdline_highlight_spec.lua +++ b/test/functional/ui/cmdline_highlight_spec.lua @@ -332,22 +332,34 @@ describe('Command-line coloring', function() eq(msg:rep(1), funcs.execute('messages')) end) it('allows interrupting callback with ', function() - if true then return pending(' does not work well enough now') end set_color_cb('Halting') start_prompt('echo 42') - for i = 1, 6 do - screen:expect([[ - ^ | - {EOB:~ }| - {EOB:~ }| - {EOB:~ }| - {EOB:~ }| - {EOB:~ }| - {EOB:~ }| - | - ]]) - feed('') - end + screen:expect([[ + ^ | + {EOB:~ }| + {EOB:~ }| + {EOB:~ }| + {EOB:~ }| + {EOB:~ }| + {EOB:~ }| + | + ]]) + feed('') + screen:expect([[ + {EOB:~ }| + {EOB:~ }| + {EOB:~ }| + {EOB:~ }| + : | + {ERR:E5407: Callback has thrown an exception:}| + {ERR: Keyboard interrupt} | + ^ | + ]]) + if true then return pending(' should only cancel callback, not input()') end + feed('{REDRAW}') + screen:snapshot_util() + feed('') + eq('echo 42', meths.get_var('out')) screen:expect([[ ^ | {EOB:~ }| -- cgit From 9ccb3abbb55ec8ed7f3b4d2d2516fd451eca9a68 Mon Sep 17 00:00:00 2001 From: ZyX Date: Wed, 28 Jun 2017 14:39:52 +0300 Subject: functests: Uncomment `{REDRAW}` part of “works” test MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test/functional/ui/cmdline_highlight_spec.lua | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) (limited to 'test') diff --git a/test/functional/ui/cmdline_highlight_spec.lua b/test/functional/ui/cmdline_highlight_spec.lua index f356db88b5..a3dc9af360 100644 --- a/test/functional/ui/cmdline_highlight_spec.lua +++ b/test/functional/ui/cmdline_highlight_spec.lua @@ -214,18 +214,20 @@ describe('Command-line coloring', function() {EOB:~ }| :echo {RBP1:(}{RBP2:(}42{RBP2:)}^ | ]]) - -- FIXME - -- feed('{REDRAW}') - -- screen:expect([[ - -- | - -- {EOB:~ }| - -- {EOB:~ }| - -- {EOB:~ }| - -- {EOB:~ }| - -- {EOB:~ }| - -- {EOB:~ }| - -- :echo {RBP1:(}{RBP2:(}42{RBP2:)}^ | - -- ]]) + -- Bug in input() handling: {REDRAW} will erase the whole prompt up until + -- user types something. It exists in Vim as well, so using `h` as + -- a workaround. + feed('{REDRAW}h') + screen:expect([[ + | + {EOB:~ }| + {EOB:~ }| + {EOB:~ }| + {EOB:~ }| + {EOB:~ }| + {EOB:~ }| + :echo {RBP1:(}{RBP2:(}42{RBP2:)}^ | + ]]) end) for _, func_part in ipairs({'', 'n', 'msg'}) do it('disables :echo' .. func_part .. ' messages', function() -- cgit From 3da49cd68e7d5c968cc99a926819038ff57f488f Mon Sep 17 00:00:00 2001 From: ZyX Date: Wed, 28 Jun 2017 22:09:10 +0300 Subject: ex_getln: Fix “echoerr msg not shown” problem MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This also attempted to fix problem with cancelling input() on error by avoiding standard error printing facilities (assumed thrown error message is the problem), but with no luck so far. --- test/functional/ui/cmdline_highlight_spec.lua | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'test') diff --git a/test/functional/ui/cmdline_highlight_spec.lua b/test/functional/ui/cmdline_highlight_spec.lua index a3dc9af360..dbabf65b68 100644 --- a/test/functional/ui/cmdline_highlight_spec.lua +++ b/test/functional/ui/cmdline_highlight_spec.lua @@ -289,7 +289,16 @@ describe('Command-line coloring', function() it('does the right thing when errorring', function() set_color_cb('Echoerring') start_prompt('e') - -- FIXME Does not work well with :echoerr: error message not shown. + screen:expect([[ + {EOB:~ }| + {EOB:~ }| + {EOB:~ }| + {EOB:~ }| + : | + {ERR:E5407: Callback has thrown an exception:}| + {ERR: Vim(echoerr):HERE} | + :e^ | + ]]) end) it('does the right thing when throwing', function() set_color_cb('Throwing') -- cgit From ea75966e4232dc4a3693cbc4a572f2116c49b138 Mon Sep 17 00:00:00 2001 From: ZyX Date: Wed, 28 Jun 2017 22:54:13 +0300 Subject: ex_getln: Do not make interrupt input() after interrupting hl cb --- test/functional/ui/cmdline_highlight_spec.lua | 42 ++++++++++++++++++--------- 1 file changed, 28 insertions(+), 14 deletions(-) (limited to 'test') diff --git a/test/functional/ui/cmdline_highlight_spec.lua b/test/functional/ui/cmdline_highlight_spec.lua index dbabf65b68..671490e668 100644 --- a/test/functional/ui/cmdline_highlight_spec.lua +++ b/test/functional/ui/cmdline_highlight_spec.lua @@ -10,6 +10,13 @@ local source = helpers.source local screen +-- Bug in input() handling: {REDRAW} will erase the whole prompt up until +-- user types something. It exists in Vim as well, so using `h` as +-- a workaround. +local function redraw_input() + feed('{REDRAW}h') +end + before_each(function() clear() screen = Screen.new(40, 8) @@ -214,10 +221,7 @@ describe('Command-line coloring', function() {EOB:~ }| :echo {RBP1:(}{RBP2:(}42{RBP2:)}^ | ]]) - -- Bug in input() handling: {REDRAW} will erase the whole prompt up until - -- user types something. It exists in Vim as well, so using `h` as - -- a workaround. - feed('{REDRAW}h') + redraw_input() screen:expect([[ | {EOB:~ }| @@ -364,24 +368,33 @@ describe('Command-line coloring', function() : | {ERR:E5407: Callback has thrown an exception:}| {ERR: Keyboard interrupt} | - ^ | + :echo 42^ | ]]) - if true then return pending(' should only cancel callback, not input()') end - feed('{REDRAW}') - screen:snapshot_util() - feed('') - eq('echo 42', meths.get_var('out')) + redraw_input() screen:expect([[ - ^ | + | {EOB:~ }| {EOB:~ }| {EOB:~ }| {EOB:~ }| {EOB:~ }| {EOB:~ }| - Type :quit to exit Nvim | + :echo 42^ | ]]) - start_prompt('echo 42') + feed('\n') + screen:expect([[ + | + {EOB:~ }| + {EOB:~ }| + {EOB:~ }| + {EOB:~ }| + {EOB:~ }| + {EOB:~ }| + ^:echo 42 | + ]]) + feed('\n') + eq('echo 42', meths.get_var('out')) + feed('') screen:expect([[ ^ | {EOB:~ }| @@ -390,7 +403,7 @@ describe('Command-line coloring', function() {EOB:~ }| {EOB:~ }| {EOB:~ }| - 42 | + Type :quit to exit Nvim | ]]) end) it('works fine with NUL, NL, CR', function() @@ -420,3 +433,4 @@ describe('Ex commands coloring support', function() end) -- TODO Specifically test for coloring in cmdline and expr modes +-- TODO Check using highlighted input() from inside highlighted input() -- cgit From 7ab152aaa58f493e54d03a15960b8a288196e588 Mon Sep 17 00:00:00 2001 From: ZyX Date: Sat, 1 Jul 2017 15:34:25 +0300 Subject: ex_getln: Save and restore try state MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Problem: when processing cycle such as :for pat in [' \ze*', ' \zs*'] : try : let l = matchlist('x x', pat) : $put ='E888 NOT detected for ' . pat : catch : $put ='E888 detected for ' . pat : endtry :endfor `:let l = …` throwing an error causes this error to be caught after color_cmdline attempts to get callback for highlighting next line (the one with `$put = 'E888 NOT…`). Saving/restoring state prevents this from happening. --- test/functional/ui/cmdline_highlight_spec.lua | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'test') diff --git a/test/functional/ui/cmdline_highlight_spec.lua b/test/functional/ui/cmdline_highlight_spec.lua index 671490e668..62c0694c8c 100644 --- a/test/functional/ui/cmdline_highlight_spec.lua +++ b/test/functional/ui/cmdline_highlight_spec.lua @@ -7,6 +7,8 @@ local clear = helpers.clear local meths = helpers.meths local funcs = helpers.funcs local source = helpers.source +local dedent = helpers.dedent +local curbufmeths = helpers.curbufmeths local screen @@ -421,6 +423,8 @@ describe('Command-line coloring', function() ]]) end) -- TODO Check for all other errors + -- TODO Check for colored input() called in a cycle which previously errorred + -- out end) describe('Ex commands coloring support', function() it('still executes command-line even if errored out', function() @@ -430,7 +434,27 @@ describe('Ex commands coloring support', function() local msg = 'E5405: Chunk 0 start 10 splits multibyte character' eq('\n'..msg, funcs.execute('messages')) end) + it('does not error out when called from a errorred out cycle', function() + -- Apparently when there is a cycle in which one of the commands errors out + -- this error may be caught by color_cmdline before it is presented to the + -- user. + feed(dedent([[ + :set regexpengine=2 + :for pat in [' \ze*', ' \zs*'] + : try + : let l = matchlist('x x', pat) + : $put ='E888 NOT detected for ' . pat + : catch + : $put ='E888 detected for ' . pat + : endtry + :endfor + ]])) + eq({'', 'E888 detected for \\ze*', 'E888 detected for \\zs*'}, + curbufmeths.get_lines(0, -1, false)) + eq('', funcs.execute('messages')) + end) end) -- TODO Specifically test for coloring in cmdline and expr modes +-- TODO Check for errors from tv_dict_get_callback() -- TODO Check using highlighted input() from inside highlighted input() -- cgit From f4744e18219726d2eaa57b26198166ea255c62a4 Mon Sep 17 00:00:00 2001 From: ZyX Date: Mon, 17 Jul 2017 01:55:10 +0300 Subject: ex_getln: Do not goto color_cmdline_end without first cleaning up MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The issue with debug mode was actually not cleaning up after `try_enter`: location `&tstate` was pointing to got invalidated and received some “garbage” (actually, values that got stored on the stack afterwards). But pointer to that garbage was still stored in `msg_list`, so next attempt to check it resulted in a crash. --- test/functional/ui/cmdline_highlight_spec.lua | 36 +++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) (limited to 'test') diff --git a/test/functional/ui/cmdline_highlight_spec.lua b/test/functional/ui/cmdline_highlight_spec.lua index 62c0694c8c..0621b990de 100644 --- a/test/functional/ui/cmdline_highlight_spec.lua +++ b/test/functional/ui/cmdline_highlight_spec.lua @@ -121,6 +121,7 @@ before_each(function() EOB={bold = true, foreground = Screen.colors.Blue1}, ERR={foreground = Screen.colors.Grey100, background = Screen.colors.Red}, SK={foreground = Screen.colors.Blue}, + PE={bold = true, foreground = Screen.colors.SeaGreen4} }) end) @@ -453,6 +454,41 @@ describe('Ex commands coloring support', function() curbufmeths.get_lines(0, -1, false)) eq('', funcs.execute('messages')) end) + it('does not crash when using `n` in debug mode', function() + feed(':debug execute "echo 1"\n') + screen:expect([[ + {EOB:~ }| + {EOB:~ }| + {EOB:~ }| + {EOB:~ }| + Entering Debug mode. Type "cont" to con| + tinue. | + cmd: execute "echo 1" | + >^ | + ]]) + feed('n\n') + screen:expect([[ + {EOB:~ }| + {EOB:~ }| + Entering Debug mode. Type "cont" to con| + tinue. | + cmd: execute "echo 1" | + >n | + 1 | + {PE:Press ENTER or type command to continue}^ | + ]]) + feed('\n') + screen:expect([[ + ^ | + {EOB:~ }| + {EOB:~ }| + {EOB:~ }| + {EOB:~ }| + {EOB:~ }| + {EOB:~ }| + | + ]]) + end) end) -- TODO Specifically test for coloring in cmdline and expr modes -- cgit From cfb1d937a64fcec836fdf26d6ea67024aeafabeb Mon Sep 17 00:00:00 2001 From: ZyX Date: Tue, 18 Jul 2017 00:08:57 +0300 Subject: api helpers: Also save and restore did_emsg --- test/functional/ui/cmdline_highlight_spec.lua | 38 +++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) (limited to 'test') diff --git a/test/functional/ui/cmdline_highlight_spec.lua b/test/functional/ui/cmdline_highlight_spec.lua index 0621b990de..6698ced596 100644 --- a/test/functional/ui/cmdline_highlight_spec.lua +++ b/test/functional/ui/cmdline_highlight_spec.lua @@ -489,6 +489,44 @@ describe('Ex commands coloring support', function() | ]]) end) + it('does not prevent mapping error from cancelling prompt', function() + meths.command("cnoremap x execute('throw 42')[-1]") + feed(':#x') + screen:expect([[ + {EOB:~ }| + {EOB:~ }| + {EOB:~ }| + {EOB:~ }| + :# | + {ERR:Error detected while processing :} | + {ERR:E605: Exception not caught: 42} | + :#^ | + ]]) + feed('') + screen:expect([[ + ^ | + {EOB:~ }| + {EOB:~ }| + {EOB:~ }| + {EOB:~ }| + {EOB:~ }| + {EOB:~ }| + | + ]]) + feed('') + screen:expect([[ + ^ | + {EOB:~ }| + {EOB:~ }| + {EOB:~ }| + {EOB:~ }| + {EOB:~ }| + {EOB:~ }| + | + ]]) + eq('\nError detected while processing :\nE605: Exception not caught: 42', + meths.command_output('messages')) + end) end) -- TODO Specifically test for coloring in cmdline and expr modes -- cgit From 8a581b918b339b84b5abd80919416a84932eb13f Mon Sep 17 00:00:00 2001 From: ZyX Date: Tue, 18 Jul 2017 00:20:21 +0300 Subject: ex_getln: Check prev_prompt_errors before running redrawcmdline Otherwise there will be infinite recursion and shortly a crash. Running redrawcmdline recursively occurs under color_cmdline_error label. --- test/functional/ui/cmdline_highlight_spec.lua | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'test') diff --git a/test/functional/ui/cmdline_highlight_spec.lua b/test/functional/ui/cmdline_highlight_spec.lua index 6698ced596..e12961039a 100644 --- a/test/functional/ui/cmdline_highlight_spec.lua +++ b/test/functional/ui/cmdline_highlight_spec.lua @@ -527,6 +527,22 @@ describe('Ex commands coloring support', function() eq('\nError detected while processing :\nE605: Exception not caught: 42', meths.command_output('messages')) end) + it('errors out when failing to get callback', function() + meths.set_var('Nvim_color_cmdline', 42) + feed(':#') + screen:expect([[ + {EOB:~ }| + {EOB:~ }| + {EOB:~ }| + : | + {ERR:E5408: Unable to get Nvim_color_cmdline }| + {ERR:callback from g:: Vim:E6000: Argument is}| + {ERR: not a function or function name} | + :#^ | + ]]) + end) +end) +describe('Expressions coloring support', function() end) -- TODO Specifically test for coloring in cmdline and expr modes -- cgit From 759f71d50e506112f63d3db80ce823e013681476 Mon Sep 17 00:00:00 2001 From: ZyX Date: Tue, 18 Jul 2017 00:34:39 +0300 Subject: functests: Check for previously unchecked errors --- test/functional/ui/cmdline_highlight_spec.lua | 100 +++++++++++++++++++++++++- 1 file changed, 97 insertions(+), 3 deletions(-) (limited to 'test') diff --git a/test/functional/ui/cmdline_highlight_spec.lua b/test/functional/ui/cmdline_highlight_spec.lua index e12961039a..8bfeaf35ab 100644 --- a/test/functional/ui/cmdline_highlight_spec.lua +++ b/test/functional/ui/cmdline_highlight_spec.lua @@ -8,6 +8,7 @@ local meths = helpers.meths local funcs = helpers.funcs local source = helpers.source local dedent = helpers.dedent +local command = helpers.command local curbufmeths = helpers.curbufmeths local screen @@ -112,6 +113,12 @@ before_each(function() while 1 endwhile endfunction + function ReturningGlobal(cmdline) + return g:callback_return + endfunction + function ReturningGlobal2(cmdline) + return g:callback_return[:len(a:cmdline)-1] + endfunction ]]) screen:set_default_attr_ids({ RBP1={background = Screen.colors.Red}, @@ -125,8 +132,11 @@ before_each(function() }) end) -local function set_color_cb(funcname) +local function set_color_cb(funcname, callback_return) meths.set_var('Nvim_color_input', funcname) + if callback_return then + meths.set_var('callback_return', callback_return) + end end local function start_prompt(text) feed('{PROMPT}' .. (text or '')) @@ -423,7 +433,77 @@ describe('Command-line coloring', function() :echo {RBP1:(}"{SK:^M^@^@}"{RBP1:)}^ | ]]) end) - -- TODO Check for all other errors + it('errors out when callback returns something wrong', function() + command('cnoremap + ++') + set_color_cb('ReturningGlobal', '') + start_prompt('#') + screen:expect([[ + {EOB:~ }| + {EOB:~ }| + {EOB:~ }| + {EOB:~ }| + {EOB:~ }| + : | + {ERR:E5400: Callback should return list} | + :#^ | + ]]) + + feed('') + set_color_cb('ReturningGlobal', {{0, 1, 'Normal'}, 42}) + start_prompt('#') + screen:expect([[ + {EOB:~ }| + {EOB:~ }| + {EOB:~ }| + {EOB:~ }| + {EOB:~ }| + : | + {ERR:E5401: List item 1 is not a List} | + :#^ | + ]]) + + feed('') + set_color_cb('ReturningGlobal2', {{0, 1, 'Normal'}, {1}}) + start_prompt('+') + screen:expect([[ + {EOB:~ }| + {EOB:~ }| + {EOB:~ }| + {EOB:~ }| + :+ | + {ERR:E5402: List item 1 has incorrect length:}| + {ERR: 1 /= 3} | + :++^ | + ]]) + + feed('') + set_color_cb('ReturningGlobal2', {{0, 1, 'Normal'}, {2, 3, 'Normal'}}) + start_prompt('+') + screen:expect([[ + {EOB:~ }| + {EOB:~ }| + {EOB:~ }| + {EOB:~ }| + :+ | + {ERR:E5403: Chunk 1 start 2 not in range [1, }| + {ERR:2)} | + :++^ | + ]]) + + feed('') + set_color_cb('ReturningGlobal2', {{0, 1, 'Normal'}, {1, 3, 'Normal'}}) + start_prompt('+') + screen:expect([[ + {EOB:~ }| + {EOB:~ }| + {EOB:~ }| + {EOB:~ }| + :+ | + {ERR:E5404: Chunk 1 end 3 not in range (1, 2]}| + | + :++^ | + ]]) + end) -- TODO Check for colored input() called in a cycle which previously errorred -- out end) @@ -490,7 +570,7 @@ describe('Ex commands coloring support', function() ]]) end) it('does not prevent mapping error from cancelling prompt', function() - meths.command("cnoremap x execute('throw 42')[-1]") + command("cnoremap x execute('throw 42')[-1]") feed(':#x') screen:expect([[ {EOB:~ }| @@ -543,6 +623,20 @@ describe('Ex commands coloring support', function() end) end) describe('Expressions coloring support', function() + it('errors out when failing to get callback', function() + meths.set_var('Nvim_color_expr', 42) + feed(':=1') + screen:expect([[ + {EOB:~ }| + {EOB:~ }| + {EOB:~ }| + = | + {ERR:E5409: Unable to get Nvim_color_expr cal}| + {ERR:lback from g:: Vim:E6000: Argument is no}| + {ERR:t a function or function name} | + =1^ | + ]]) + end) end) -- TODO Specifically test for coloring in cmdline and expr modes -- cgit From 25f669049cced029e1530a74e9490e61432433ac Mon Sep 17 00:00:00 2001 From: ZyX Date: Tue, 18 Jul 2017 01:16:38 +0300 Subject: functests: Test input() nesting support --- test/functional/ui/cmdline_highlight_spec.lua | 196 ++++++++++++++++++++++++-- 1 file changed, 184 insertions(+), 12 deletions(-) (limited to 'test') diff --git a/test/functional/ui/cmdline_highlight_spec.lua b/test/functional/ui/cmdline_highlight_spec.lua index 8bfeaf35ab..82d4fdffd2 100644 --- a/test/functional/ui/cmdline_highlight_spec.lua +++ b/test/functional/ui/cmdline_highlight_spec.lua @@ -34,9 +34,17 @@ before_each(function() redraw! return '' endfunction - let g:EMPTY = '' + let g:id = '' cnoremap {REDRAW} Redraw() - nnoremap {PROMPT} extend(g:, {"out": input({"prompt": ":", "highlight": g:Nvim_color_input})}).EMPTY + function DoPrompt(do_return) abort + let id = g:id + let Cb = g:Nvim_color_input{g:id} + let out = input({'prompt': ':', 'highlight': Cb}) + let g:out{id} = out + return (a:do_return ? out : '') + endfunction + nnoremap {PROMPT} DoPrompt(0) + cnoremap {PROMPT} DoPrompt(1) function RainBowParens(cmdline) let ret = [] let i = 0 @@ -119,6 +127,9 @@ before_each(function() function ReturningGlobal2(cmdline) return g:callback_return[:len(a:cmdline)-1] endfunction + function ReturningGlobalN(n, cmdline) + return g:callback_return{a:n} + endfunction ]]) screen:set_default_attr_ids({ RBP1={background = Screen.colors.Red}, @@ -132,10 +143,19 @@ before_each(function() }) end) -local function set_color_cb(funcname, callback_return) - meths.set_var('Nvim_color_input', funcname) - if callback_return then - meths.set_var('callback_return', callback_return) +local function set_color_cb(funcname, callback_return, id) + meths.set_var('id', id or '') + if id and id ~= '' and funcs.exists('*' .. funcname .. 'N') then + command(('let g:Nvim_color_input%s = {cmdline -> %sN(%s, cmdline)}'):format( + id, funcname, id)) + if callback_return then + meths.set_var('callback_return' .. id, callback_return) + end + else + meths.set_var('Nvim_color_input', funcname) + if callback_return then + meths.set_var('callback_return', callback_return) + end end end local function start_prompt(text) @@ -504,10 +524,152 @@ describe('Command-line coloring', function() :++^ | ]]) end) - -- TODO Check for colored input() called in a cycle which previously errorred - -- out + it('does not error out when called from a errorred out cycle', function() + set_color_cb('ReturningGlobal', {{0, 1, 'Normal'}}) + feed(dedent([[ + :set regexpengine=2 + :for pat in [' \ze*', ' \zs*'] + : try + : let l = matchlist('x x', pat) + : $put =input({'prompt':'>','highlight':'ReturningGlobal'}) + : + : $put ='E888 NOT detected for ' . pat + : catch + : $put =input({'prompt':'>','highlight':'ReturningGlobal'}) + : + : $put ='E888 detected for ' . pat + : endtry + :endfor + : + : + : + : + : + : + ]])) + eq({'', ':', 'E888 detected for \\ze*', ':', 'E888 detected for \\zs*'}, + curbufmeths.get_lines(0, -1, false)) + eq('', funcs.execute('messages')) + end) + it('allows nesting input()s', function() + set_color_cb('ReturningGlobal', {{0, 1, 'RBP1'}}, '') + start_prompt('1') + screen:expect([[ + | + {EOB:~ }| + {EOB:~ }| + {EOB:~ }| + {EOB:~ }| + {EOB:~ }| + {EOB:~ }| + :{RBP1:1}^ | + ]]) + + set_color_cb('ReturningGlobal', {{0, 1, 'RBP2'}}, '1') + start_prompt('2') + screen:expect([[ + | + {EOB:~ }| + {EOB:~ }| + {EOB:~ }| + {EOB:~ }| + {EOB:~ }| + {EOB:~ }| + :{RBP2:2}^ | + ]]) + + set_color_cb('ReturningGlobal', {{0, 1, 'RBP3'}}, '2') + start_prompt('3') + screen:expect([[ + | + {EOB:~ }| + {EOB:~ }| + {EOB:~ }| + {EOB:~ }| + {EOB:~ }| + {EOB:~ }| + :{RBP3:3}^ | + ]]) + + set_color_cb('ReturningGlobal', {{0, 1, 'RBP4'}}, '3') + start_prompt('4') + screen:expect([[ + | + {EOB:~ }| + {EOB:~ }| + {EOB:~ }| + {EOB:~ }| + {EOB:~ }| + {EOB:~ }| + :{RBP4:4}^ | + ]]) + + feed('') + screen:expect([[ + | + {EOB:~ }| + {EOB:~ }| + {EOB:~ }| + {EOB:~ }| + {EOB:~ }| + {EOB:~ }| + :{RBP3:3}4^ | + ]]) + feed('') + screen:expect([[ + | + {EOB:~ }| + {EOB:~ }| + {EOB:~ }| + {EOB:~ }| + {EOB:~ }| + {EOB:~ }| + :{RBP2:2}34^ | + ]]) + feed('') + screen:expect([[ + | + {EOB:~ }| + {EOB:~ }| + {EOB:~ }| + {EOB:~ }| + {EOB:~ }| + {EOB:~ }| + :{RBP1:1}234^ | + ]]) + feed('') + screen:expect([[ + ^ | + {EOB:~ }| + {EOB:~ }| + {EOB:~ }| + {EOB:~ }| + {EOB:~ }| + {EOB:~ }| + | + ]]) + eq('1234', meths.get_var('out')) + eq('234', meths.get_var('out1')) + eq('34', meths.get_var('out2')) + eq('4', meths.get_var('out3')) + eq(0, funcs.exists('g:out4')) + end) end) describe('Ex commands coloring support', function() + it('works', function() + meths.set_var('Nvim_color_cmdline', 'RainBowParens') + feed(':echo (((1)))') + screen:expect([[ + | + {EOB:~ }| + {EOB:~ }| + {EOB:~ }| + {EOB:~ }| + {EOB:~ }| + {EOB:~ }| + :echo {RBP1:(}{RBP2:(}{RBP3:(}1{RBP3:)}{RBP2:)}{RBP1:)}^ | + ]]) + end) it('still executes command-line even if errored out', function() meths.set_var('Nvim_color_cmdline', 'SplittedMultibyteStart') feed(':let x = "«"\n') @@ -623,6 +785,20 @@ describe('Ex commands coloring support', function() end) end) describe('Expressions coloring support', function() + it('works', function() + meths.set_var('Nvim_color_expr', 'RainBowParens') + feed(':echo =(((1)))') + screen:expect([[ + | + {EOB:~ }| + {EOB:~ }| + {EOB:~ }| + {EOB:~ }| + {EOB:~ }| + {EOB:~ }| + ={RBP1:(}{RBP2:(}{RBP3:(}1{RBP3:)}{RBP2:)}{RBP1:)}^ | + ]]) + end) it('errors out when failing to get callback', function() meths.set_var('Nvim_color_expr', 42) feed(':=1') @@ -638,7 +814,3 @@ describe('Expressions coloring support', function() ]]) end) end) - --- TODO Specifically test for coloring in cmdline and expr modes --- TODO Check for errors from tv_dict_get_callback() --- TODO Check using highlighted input() from inside highlighted input() -- cgit From 0a46ae3c0a7b2ca53ce16c3f5c5ecb8ae7bfee80 Mon Sep 17 00:00:00 2001 From: ZyX Date: Tue, 18 Jul 2017 01:29:41 +0300 Subject: functests: Add sleep to test --- test/functional/ui/cmdline_highlight_spec.lua | 1 + 1 file changed, 1 insertion(+) (limited to 'test') diff --git a/test/functional/ui/cmdline_highlight_spec.lua b/test/functional/ui/cmdline_highlight_spec.lua index 82d4fdffd2..a81d671119 100644 --- a/test/functional/ui/cmdline_highlight_spec.lua +++ b/test/functional/ui/cmdline_highlight_spec.lua @@ -392,6 +392,7 @@ describe('Command-line coloring', function() {EOB:~ }| | ]]) + screen:sleep(500) feed('') screen:expect([[ {EOB:~ }| -- cgit From 1ba21b4a31ea5853673ba3d1baae3e862c1ef04a Mon Sep 17 00:00:00 2001 From: ZyX Date: Wed, 26 Jul 2017 13:02:45 +0300 Subject: functests: Remove unneeded wait()s --- test/functional/eval/input_spec.lua | 2 -- 1 file changed, 2 deletions(-) (limited to 'test') diff --git a/test/functional/eval/input_spec.lua b/test/functional/eval/input_spec.lua index 5b259d5440..0571043efe 100644 --- a/test/functional/eval/input_spec.lua +++ b/test/functional/eval/input_spec.lua @@ -232,7 +232,6 @@ describe('input()', function() feed([[:call input({"highlight": "RainBowParens"})]]) wait() feed('(())') - wait() screen:expect([[ {EOB:~ }| {EOB:~ }| @@ -412,7 +411,6 @@ describe('inputdialog()', function() feed([[:call inputdialog({"highlight": "RainBowParens"})]]) wait() feed('(())') - wait() screen:expect([[ {EOB:~ }| {EOB:~ }| -- cgit From e129607988b88719935bc4af517e7ee2689f5871 Mon Sep 17 00:00:00 2001 From: ZyX Date: Wed, 26 Jul 2017 22:04:39 +0300 Subject: functests: Replace wait() with nvim_async --- test/functional/eval/input_spec.lua | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'test') diff --git a/test/functional/eval/input_spec.lua b/test/functional/eval/input_spec.lua index 0571043efe..cfb91983c1 100644 --- a/test/functional/eval/input_spec.lua +++ b/test/functional/eval/input_spec.lua @@ -2,13 +2,13 @@ local helpers = require('test.functional.helpers')(after_each) local Screen = require('test.functional.ui.screen') local eq = helpers.eq -local wait = helpers.wait local feed = helpers.feed local meths = helpers.meths local clear = helpers.clear local source = helpers.source local command = helpers.command local exc_exec = helpers.exc_exec +local nvim_async = helpers.nvim_async local screen @@ -229,16 +229,16 @@ describe('input()', function() exc_exec('call input("prompt> ", "default", "file", "extra")')) end) it('supports highlighting', function() - feed([[:call input({"highlight": "RainBowParens"})]]) - wait() + nvim_async('command', 'call input({"highlight": "RainBowParens"})') feed('(())') screen:expect([[ + | {EOB:~ }| {EOB:~ }| {EOB:~ }| - | {RBP1:(}{RBP2:()}{RBP1:)}^ | ]]) + feed('') end) end) describe('inputdialog()', function() @@ -408,15 +408,15 @@ describe('inputdialog()', function() exc_exec('call inputdialog("prompt> ", "default", "file", "extra")')) end) it('supports highlighting', function() - feed([[:call inputdialog({"highlight": "RainBowParens"})]]) - wait() + nvim_async('command', 'call inputdialog({"highlight": "RainBowParens"})') feed('(())') screen:expect([[ + | {EOB:~ }| {EOB:~ }| {EOB:~ }| - | {RBP1:(}{RBP2:()}{RBP1:)}^ | ]]) + feed('') end) end) -- cgit From c5857e3f3807d305598d7639949793d44b380e23 Mon Sep 17 00:00:00 2001 From: ZyX Date: Wed, 26 Jul 2017 22:56:48 +0300 Subject: ex_getln: Cache highlight callback calling results --- test/functional/ui/cmdline_highlight_spec.lua | 31 +++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) (limited to 'test') diff --git a/test/functional/ui/cmdline_highlight_spec.lua b/test/functional/ui/cmdline_highlight_spec.lua index a81d671119..b6288b746e 100644 --- a/test/functional/ui/cmdline_highlight_spec.lua +++ b/test/functional/ui/cmdline_highlight_spec.lua @@ -130,6 +130,11 @@ before_each(function() function ReturningGlobalN(n, cmdline) return g:callback_return{a:n} endfunction + let g:recording_calls = [] + function Recording(cmdline) + call add(g:recording_calls, a:cmdline) + return [] + endfunction ]]) screen:set_default_attr_ids({ RBP1={background = Screen.colors.Red}, @@ -655,6 +660,32 @@ describe('Command-line coloring', function() eq('4', meths.get_var('out3')) eq(0, funcs.exists('g:out4')) end) + it('runs callback with the same data only once', function() + local function new_recording_calls(...) + eq({...}, meths.get_var('recording_calls')) + meths.set_var('recording_calls', {}) + end + set_color_cb('Recording') + start_prompt('') + -- Regression test. Disambiguation: + -- + -- new_recording_calls(expected_result) -- (actual_before_fix) + -- + feed('a') + new_recording_calls('a') -- ('a', 'a') + feed('b') + new_recording_calls('ab') -- ('a', 'ab', 'ab') + feed('c') + new_recording_calls('abc') -- ('ab', 'abc', 'abc') + feed('') + new_recording_calls('ab') -- ('abc', 'ab', 'ab') + feed('') + new_recording_calls('a') -- ('ab', 'a', 'a') + feed('') + new_recording_calls() -- ('a') + feed('') + eq('', meths.get_var('out')) + end) end) describe('Ex commands coloring support', function() it('works', function() -- cgit From 1011462b40502e6039494e70a870f0360f152b1b Mon Sep 17 00:00:00 2001 From: ZyX Date: Thu, 27 Jul 2017 18:49:13 +0300 Subject: Revert "functests: Replace wait() with nvim_async" This reverts commit e129607988b88719935bc4af517e7ee2689f5871. Tests stopped working in CI. --- test/functional/eval/input_spec.lua | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'test') diff --git a/test/functional/eval/input_spec.lua b/test/functional/eval/input_spec.lua index cfb91983c1..0571043efe 100644 --- a/test/functional/eval/input_spec.lua +++ b/test/functional/eval/input_spec.lua @@ -2,13 +2,13 @@ local helpers = require('test.functional.helpers')(after_each) local Screen = require('test.functional.ui.screen') local eq = helpers.eq +local wait = helpers.wait local feed = helpers.feed local meths = helpers.meths local clear = helpers.clear local source = helpers.source local command = helpers.command local exc_exec = helpers.exc_exec -local nvim_async = helpers.nvim_async local screen @@ -229,16 +229,16 @@ describe('input()', function() exc_exec('call input("prompt> ", "default", "file", "extra")')) end) it('supports highlighting', function() - nvim_async('command', 'call input({"highlight": "RainBowParens"})') + feed([[:call input({"highlight": "RainBowParens"})]]) + wait() feed('(())') screen:expect([[ - | {EOB:~ }| {EOB:~ }| {EOB:~ }| + | {RBP1:(}{RBP2:()}{RBP1:)}^ | ]]) - feed('') end) end) describe('inputdialog()', function() @@ -408,15 +408,15 @@ describe('inputdialog()', function() exc_exec('call inputdialog("prompt> ", "default", "file", "extra")')) end) it('supports highlighting', function() - nvim_async('command', 'call inputdialog({"highlight": "RainBowParens"})') + feed([[:call inputdialog({"highlight": "RainBowParens"})]]) + wait() feed('(())') screen:expect([[ - | {EOB:~ }| {EOB:~ }| {EOB:~ }| + | {RBP1:(}{RBP2:()}{RBP1:)}^ | ]]) - feed('') end) end) -- cgit From efb03903eb667bc14992dffcd77d04385371abed Mon Sep 17 00:00:00 2001 From: ZyX Date: Sun, 6 Aug 2017 14:43:46 +0300 Subject: functests: Remove wait() from input_spec --- test/functional/eval/input_spec.lua | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) (limited to 'test') diff --git a/test/functional/eval/input_spec.lua b/test/functional/eval/input_spec.lua index 0571043efe..5ae23e17d0 100644 --- a/test/functional/eval/input_spec.lua +++ b/test/functional/eval/input_spec.lua @@ -2,7 +2,6 @@ local helpers = require('test.functional.helpers')(after_each) local Screen = require('test.functional.ui.screen') local eq = helpers.eq -local wait = helpers.wait local feed = helpers.feed local meths = helpers.meths local clear = helpers.clear @@ -229,14 +228,14 @@ describe('input()', function() exc_exec('call input("prompt> ", "default", "file", "extra")')) end) it('supports highlighting', function() - feed([[:call input({"highlight": "RainBowParens"})]]) - wait() + command('nnoremap X input({"highlight": "RainBowParens"})[-1]') + feed([[X]]) feed('(())') screen:expect([[ + | {EOB:~ }| {EOB:~ }| {EOB:~ }| - | {RBP1:(}{RBP2:()}{RBP1:)}^ | ]]) end) @@ -408,14 +407,14 @@ describe('inputdialog()', function() exc_exec('call inputdialog("prompt> ", "default", "file", "extra")')) end) it('supports highlighting', function() - feed([[:call inputdialog({"highlight": "RainBowParens"})]]) - wait() + command('nnoremap X inputdialog({"highlight": "RainBowParens"})[-1]') + feed([[X]]) feed('(())') screen:expect([[ + | {EOB:~ }| {EOB:~ }| {EOB:~ }| - | {RBP1:(}{RBP2:()}{RBP1:)}^ | ]]) end) -- cgit From a5449f79ac21919d45544c1e9ce86ae003e04298 Mon Sep 17 00:00:00 2001 From: ZyX Date: Mon, 14 Aug 2017 01:17:16 +0300 Subject: functests: Check that input is correctly silenced --- test/functional/ui/cmdline_highlight_spec.lua | 45 +++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) (limited to 'test') diff --git a/test/functional/ui/cmdline_highlight_spec.lua b/test/functional/ui/cmdline_highlight_spec.lua index b6288b746e..262d706e4e 100644 --- a/test/functional/ui/cmdline_highlight_spec.lua +++ b/test/functional/ui/cmdline_highlight_spec.lua @@ -342,6 +342,51 @@ describe('Command-line coloring', function() :e^ | ]]) end) + it('silences :echo', function() + set_color_cb('Echoing') + start_prompt('e') + screen:expect([[ + | + {EOB:~ }| + {EOB:~ }| + {EOB:~ }| + {EOB:~ }| + {EOB:~ }| + {EOB:~ }| + :e^ | + ]]) + eq('', meths.command_output('messages')) + end) + it('silences :echon', function() + set_color_cb('Echoning') + start_prompt('e') + screen:expect([[ + | + {EOB:~ }| + {EOB:~ }| + {EOB:~ }| + {EOB:~ }| + {EOB:~ }| + {EOB:~ }| + :e^ | + ]]) + eq('', meths.command_output('messages')) + end) + it('silences :echomsg', function() + set_color_cb('Echomsging') + start_prompt('e') + screen:expect([[ + | + {EOB:~ }| + {EOB:~ }| + {EOB:~ }| + {EOB:~ }| + {EOB:~ }| + {EOB:~ }| + :e^ | + ]]) + eq('', meths.command_output('messages')) + end) it('does the right thing when throwing', function() set_color_cb('Throwing') start_prompt('e') -- cgit From 0571b8cb0eba8f8ec10b33910bb5164a123af44d Mon Sep 17 00:00:00 2001 From: ZyX Date: Mon, 14 Aug 2017 01:22:10 +0300 Subject: functests: Alter comment --- test/functional/ui/cmdline_highlight_spec.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test') diff --git a/test/functional/ui/cmdline_highlight_spec.lua b/test/functional/ui/cmdline_highlight_spec.lua index 262d706e4e..1d2a06b7f0 100644 --- a/test/functional/ui/cmdline_highlight_spec.lua +++ b/test/functional/ui/cmdline_highlight_spec.lua @@ -13,7 +13,7 @@ local curbufmeths = helpers.curbufmeths local screen --- Bug in input() handling: {REDRAW} will erase the whole prompt up until +-- Bug in input() handling: :redraw! will erase the whole prompt up until -- user types something. It exists in Vim as well, so using `h` as -- a workaround. local function redraw_input() -- cgit From 19a28352a925b0a8502d57ec4f42b1412639aa6c Mon Sep 17 00:00:00 2001 From: ZyX Date: Mon, 14 Aug 2017 01:56:48 +0300 Subject: ex_getln: Make error messages look better --- test/functional/ui/cmdline_highlight_spec.lua | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'test') diff --git a/test/functional/ui/cmdline_highlight_spec.lua b/test/functional/ui/cmdline_highlight_spec.lua index 1d2a06b7f0..d87ce72599 100644 --- a/test/functional/ui/cmdline_highlight_spec.lua +++ b/test/functional/ui/cmdline_highlight_spec.lua @@ -854,9 +854,9 @@ describe('Ex commands coloring support', function() {EOB:~ }| {EOB:~ }| : | - {ERR:E5408: Unable to get Nvim_color_cmdline }| - {ERR:callback from g:: Vim:E6000: Argument is}| - {ERR: not a function or function name} | + {ERR:E5408: Unable to get g:Nvim_color_cmdlin}| + {ERR:e callback: Vim:E6000: Argument is not a}| + {ERR: function or function name} | :#^ | ]]) end) @@ -884,9 +884,9 @@ describe('Expressions coloring support', function() {EOB:~ }| {EOB:~ }| = | - {ERR:E5409: Unable to get Nvim_color_expr cal}| - {ERR:lback from g:: Vim:E6000: Argument is no}| - {ERR:t a function or function name} | + {ERR:E5409: Unable to get g:Nvim_color_expr c}| + {ERR:allback: Vim:E6000: Argument is not a fu}| + {ERR:nction or function name} | =1^ | ]]) end) -- cgit From 4b1f21de75f9981007d80aca8355239e8615d6bd Mon Sep 17 00:00:00 2001 From: erw7 Date: Tue, 28 Mar 2017 18:07:58 +0900 Subject: win: support :terminal --- test/functional/fixtures/tty-test.c | 44 +++++++++++------- test/functional/terminal/buffer_spec.lua | 6 +-- test/functional/terminal/cursor_spec.lua | 2 - test/functional/terminal/ex_terminal_spec.lua | 11 +++-- test/functional/terminal/helpers.lua | 7 ++- test/functional/terminal/highlight_spec.lua | 5 ++- test/functional/terminal/mouse_spec.lua | 5 ++- test/functional/terminal/scrollback_spec.lua | 64 ++++++++++++++++++++++++--- test/functional/terminal/window_spec.lua | 2 - 9 files changed, 107 insertions(+), 39 deletions(-) (limited to 'test') diff --git a/test/functional/fixtures/tty-test.c b/test/functional/fixtures/tty-test.c index 7ba21d652a..dd94d1a256 100644 --- a/test/functional/fixtures/tty-test.c +++ b/test/functional/fixtures/tty-test.c @@ -15,10 +15,12 @@ uv_tty_t tty; #include bool owns_tty(void) { - HWND consoleWnd = GetConsoleWindow(); - DWORD dwProcessId; - GetWindowThreadProcessId(consoleWnd, &dwProcessId); - return GetCurrentProcessId() == dwProcessId; + /* XXX: We need to make proper detect owns tty */ + /* HWND consoleWnd = GetConsoleWindow(); */ + /* DWORD dwProcessId; */ + /* GetWindowThreadProcessId(consoleWnd, &dwProcessId); */ + /* return GetCurrentProcessId() == dwProcessId; */ + return true; } #else #include @@ -54,16 +56,18 @@ static void sig_handler(int signum) return; } } +#else +static void sigwinch_cb(uv_signal_t *handle, int signum) +{ + int width, height; + uv_tty_t out; + uv_tty_init(uv_default_loop(), &out, fileno(stdout), 0); + uv_tty_get_winsize(&out, &width, &height); + fprintf(stderr, "rows: %d, cols: %d\n", height, width); + uv_close((uv_handle_t *)&out, NULL); +} #endif -// static void sigwinch_cb(uv_signal_t *handle, int signum) -// { -// int width, height; -// uv_tty_t *tty = handle->data; -// uv_tty_get_winsize(tty, &width, &height); -// fprintf(stderr, "rows: %d, cols: %d\n", height, width); -// } - static void alloc_cb(uv_handle_t *handle, size_t suggested, uv_buf_t *buf) { buf->len = BUF_SIZE; @@ -88,7 +92,7 @@ static void read_cb(uv_stream_t *stream, ssize_t cnt, const uv_buf_t *buf) uv_loop_t write_loop; uv_loop_init(&write_loop); uv_tty_t out; - uv_tty_init(&write_loop, &out, 1, 0); + uv_tty_init(&write_loop, &out, fileno(stdout), 0); uv_write_t req; uv_buf_t b = {.base = buf->base, .len = (size_t)cnt}; uv_write(&req, STRUCT_CAST(uv_stream_t, &out), &b, 1, NULL); @@ -149,7 +153,11 @@ int main(int argc, char **argv) uv_prepare_init(uv_default_loop(), &prepare); uv_prepare_start(&prepare, prepare_cb); // uv_tty_t tty; +#ifndef WIN32 uv_tty_init(uv_default_loop(), &tty, fileno(stderr), 1); +#else + uv_tty_init(uv_default_loop(), &tty, fileno(stdin), 1); +#endif uv_tty_set_mode(&tty, UV_TTY_MODE_RAW); tty.data = &interrupted; uv_read_start(STRUCT_CAST(uv_stream_t, &tty), alloc_cb, read_cb); @@ -160,15 +168,17 @@ int main(int argc, char **argv) sa.sa_handler = sig_handler; sigaction(SIGHUP, &sa, NULL); sigaction(SIGWINCH, &sa, NULL); - // uv_signal_t sigwinch_watcher; - // uv_signal_init(uv_default_loop(), &sigwinch_watcher); - // sigwinch_watcher.data = &tty; - // uv_signal_start(&sigwinch_watcher, sigwinch_cb, SIGWINCH); +#else + uv_signal_t sigwinch_watcher; + uv_signal_init(uv_default_loop(), &sigwinch_watcher); + uv_signal_start(&sigwinch_watcher, sigwinch_cb, SIGWINCH); #endif uv_run(uv_default_loop(), UV_RUN_DEFAULT); +#ifndef WIN32 // XXX: Without this the SIGHUP handler is skipped on some systems. sleep(100); +#endif return 0; } diff --git a/test/functional/terminal/buffer_spec.lua b/test/functional/terminal/buffer_spec.lua index 48b8512bf0..22ab0a8c21 100644 --- a/test/functional/terminal/buffer_spec.lua +++ b/test/functional/terminal/buffer_spec.lua @@ -6,8 +6,6 @@ local eval, feed_command, source = helpers.eval, helpers.feed_command, helpers.s local eq, neq = helpers.eq, helpers.neq local write_file = helpers.write_file -if helpers.pending_win32(pending) then return end - describe('terminal buffer', function() local screen @@ -72,6 +70,7 @@ describe('terminal buffer', function() end) it('cannot be modified directly', function() + if helpers.pending_win32(pending) then return end feed('dd') screen:expect([[ tty ready | @@ -160,6 +159,7 @@ describe('terminal buffer', function() end) it('handles loss of focus gracefully', function() + if helpers.pending_win32(pending) then return end -- Change the statusline to avoid printing the file name, which varies. nvim('set_option', 'statusline', '==========') feed_command('set laststatus=0') @@ -205,7 +205,7 @@ describe('terminal buffer', function() end) describe('No heap-buffer-overflow when using', function() - + if helpers.pending_win32(pending) then return end local testfilename = 'Xtestfile-functional-terminal-buffers_spec' before_each(function() diff --git a/test/functional/terminal/cursor_spec.lua b/test/functional/terminal/cursor_spec.lua index 84d0322f12..d49f1bfc23 100644 --- a/test/functional/terminal/cursor_spec.lua +++ b/test/functional/terminal/cursor_spec.lua @@ -7,8 +7,6 @@ local feed_command = helpers.feed_command local hide_cursor = thelpers.hide_cursor local show_cursor = thelpers.show_cursor -if helpers.pending_win32(pending) then return end - describe('terminal cursor', function() local screen diff --git a/test/functional/terminal/ex_terminal_spec.lua b/test/functional/terminal/ex_terminal_spec.lua index be0fd9f8ff..5eb6a5f18c 100644 --- a/test/functional/terminal/ex_terminal_spec.lua +++ b/test/functional/terminal/ex_terminal_spec.lua @@ -3,10 +3,10 @@ local Screen = require('test.functional.ui.screen') local clear, wait, nvim = helpers.clear, helpers.wait, helpers.nvim local nvim_dir, source, eq = helpers.nvim_dir, helpers.source, helpers.eq local feed_command, eval = helpers.feed_command, helpers.eval - -if helpers.pending_win32(pending) then return end +local iswin = helpers.iswin describe(':terminal', function() + if helpers.pending_win32(pending) then return end local screen before_each(function() @@ -174,10 +174,15 @@ describe(':terminal (with fake shell)', function() eq('term://', string.match(eval('bufname("%")'), "^term://")) helpers.feed([[]]) feed_command([[find */shadacat.py]]) - eq('scripts/shadacat.py', eval('bufname("%")')) + if iswin() then + eq('scripts\\shadacat.py', eval('bufname("%")')) + else + eq('scripts/shadacat.py', eval('bufname("%")')) + end end) it('works with gf', function() + if helpers.pending_win32(pending) then return end terminal_with_fake_shell([[echo "scripts/shadacat.py"]]) wait() screen:expect([[ diff --git a/test/functional/terminal/helpers.lua b/test/functional/terminal/helpers.lua index 3b04d17705..29381ab4f0 100644 --- a/test/functional/terminal/helpers.lua +++ b/test/functional/terminal/helpers.lua @@ -30,10 +30,14 @@ local function clear_attrs() feed_termcode('[0;10m') end -- mouse local function enable_mouse() feed_termcode('[?1002h') end local function disable_mouse() feed_termcode('[?1002l') end +local function wait_sigwinch() + helpers.sleep(1000) + hide_cursor() + show_cursor() +end local default_command = '["'..nvim_dir..'/tty-test'..'"]' - local function screen_setup(extra_rows, command, cols) extra_rows = extra_rows and extra_rows or 0 command = command and command or default_command @@ -112,5 +116,6 @@ return { clear_attrs = clear_attrs, enable_mouse = enable_mouse, disable_mouse = disable_mouse, + wait_sigwinch = wait_sigwinch, screen_setup = screen_setup } diff --git a/test/functional/terminal/highlight_spec.lua b/test/functional/terminal/highlight_spec.lua index bb40770235..fddc0bbb71 100644 --- a/test/functional/terminal/highlight_spec.lua +++ b/test/functional/terminal/highlight_spec.lua @@ -5,8 +5,6 @@ local feed, clear, nvim = helpers.feed, helpers.clear, helpers.nvim local nvim_dir, command = helpers.nvim_dir, helpers.command local eq, eval = helpers.eq, helpers.eval -if helpers.pending_win32(pending) then return end - describe('terminal window highlighting', function() local screen @@ -55,6 +53,7 @@ describe('terminal window highlighting', function() end) local function pass_attrs() + if helpers.pending_win32(pending) then return end screen:expect(sub([[ tty ready | {NUM:text}text{10: } | @@ -69,6 +68,7 @@ describe('terminal window highlighting', function() it('will pass the corresponding attributes', pass_attrs) it('will pass the corresponding attributes on scrollback', function() + if helpers.pending_win32(pending) then return end pass_attrs() local lines = {} for i = 1, 8 do @@ -145,6 +145,7 @@ describe('terminal window highlighting with custom palette', function() end) it('will use the custom color', function() + if helpers.pending_win32(pending) then return end thelpers.set_fg(3) thelpers.feed_data('text') thelpers.clear_attrs() diff --git a/test/functional/terminal/mouse_spec.lua b/test/functional/terminal/mouse_spec.lua index 9239c2ad31..29c62d7be7 100644 --- a/test/functional/terminal/mouse_spec.lua +++ b/test/functional/terminal/mouse_spec.lua @@ -4,8 +4,6 @@ local clear, eq, eval = helpers.clear, helpers.eq, helpers.eval local feed, nvim = helpers.feed, helpers.nvim local feed_data = thelpers.feed_data -if helpers.pending_win32(pending) then return end - describe('terminal mouse', function() local screen @@ -67,6 +65,7 @@ describe('terminal mouse', function() end) it('will forward mouse clicks to the program', function() + if helpers.pending_win32(pending) then return end feed('<1,2>') screen:expect([[ line27 | @@ -80,6 +79,7 @@ describe('terminal mouse', function() end) it('will forward mouse scroll to the program', function() + if helpers.pending_win32(pending) then return end feed('<0,0>') screen:expect([[ line27 | @@ -94,6 +94,7 @@ describe('terminal mouse', function() end) describe('with a split window and other buffer', function() + if helpers.pending_win32(pending) then return end before_each(function() feed(':vsp') screen:expect([[ diff --git a/test/functional/terminal/scrollback_spec.lua b/test/functional/terminal/scrollback_spec.lua index 05f81295c2..649bb4373b 100644 --- a/test/functional/terminal/scrollback_spec.lua +++ b/test/functional/terminal/scrollback_spec.lua @@ -3,6 +3,7 @@ local helpers = require('test.functional.helpers')(after_each) local thelpers = require('test.functional.terminal.helpers') local clear, eq, curbuf = helpers.clear, helpers.eq, helpers.curbuf local feed, nvim_dir, feed_command = helpers.feed, helpers.nvim_dir, helpers.feed_command +local iswin, wait_sigwinch = helpers.iswin, thelpers.wait_sigwinch local eval = helpers.eval local command = helpers.command local wait = helpers.wait @@ -11,8 +12,6 @@ local curbufmeths = helpers.curbufmeths local nvim = helpers.nvim local feed_data = thelpers.feed_data -if helpers.pending_win32(pending) then return end - describe('terminal scrollback', function() local screen @@ -142,6 +141,9 @@ describe('terminal scrollback', function() describe('and the height is decreased by 1', function() local function will_hide_top_line() screen:try_resize(screen._width, screen._height - 1) + if iswin() then + wait_sigwinch() + end screen:expect([[ line2 | line3 | @@ -158,6 +160,9 @@ describe('terminal scrollback', function() before_each(function() will_hide_top_line() screen:try_resize(screen._width, screen._height - 2) + if iswin() then + wait_sigwinch() + end end) it('will hide the top 3 lines', function() @@ -184,9 +189,13 @@ describe('terminal scrollback', function() describe('and the height is decreased by 2', function() before_each(function() screen:try_resize(screen._width, screen._height - 2) + if iswin() then + wait_sigwinch() + end end) local function will_delete_last_two_lines() + if helpers.pending_win32(pending) then return end screen:expect([[ tty ready | rows: 4, cols: 30 | @@ -200,9 +209,13 @@ describe('terminal scrollback', function() it('will delete the last two empty lines', will_delete_last_two_lines) describe('and then decreased by 1', function() + if helpers.pending_win32(pending) then return end before_each(function() will_delete_last_two_lines() screen:try_resize(screen._width, screen._height - 1) + if iswin() then + wait_sigwinch() + end end) it('will delete the last line and hide the first', function() @@ -245,6 +258,9 @@ describe('terminal scrollback', function() {3:-- TERMINAL --} | ]]) screen:try_resize(screen._width, screen._height - 3) + if iswin() then + wait_sigwinch() + end screen:expect([[ line4 | rows: 3, cols: 30 | @@ -257,6 +273,9 @@ describe('terminal scrollback', function() describe('and the height is increased by 1', function() local function pop_then_push() screen:try_resize(screen._width, screen._height + 1) + if iswin() then + wait_sigwinch() + end screen:expect([[ line4 | rows: 3, cols: 30 | @@ -273,6 +292,9 @@ describe('terminal scrollback', function() pop_then_push() eq(8, curbuf('line_count')) screen:try_resize(screen._width, screen._height + 3) + if iswin() then + wait_sigwinch() + end end) local function pop3_then_push1() @@ -303,10 +325,14 @@ describe('terminal scrollback', function() it('will pop 3 lines and then push one back', pop3_then_push1) describe('and then by 4', function() + if helpers.pending_win32(pending) then return end before_each(function() pop3_then_push1() feed('Gi') screen:try_resize(screen._width, screen._height + 4) + if iswin() then + wait_sigwinch() + end end) it('will show all lines and leave a blank one at the end', function() @@ -384,10 +410,20 @@ describe("'scrollback' option", function() end it('set to 0 behaves as 1', function() - local screen = thelpers.screen_setup(nil, "['sh']", 30) + local screen + if iswin() then + screen = thelpers.screen_setup(nil, + "['powershell.exe', '-NoLogo', '-NoProfile', '-NoExit', '-Command', 'function global:prompt {return "..'"$"'.."}']", 30) + else + screen = thelpers.screen_setup(nil, "['sh']", 30) + end curbufmeths.set_option('scrollback', 0) - feed_data('for i in $(seq 1 30); do echo "line$i"; done\n') + if iswin() then + feed_data('for($i=1;$i -le 30;$i++){Write-Host \"line$i\"}\r') + else + feed_data('for i in $(seq 1 30); do echo "line$i"; done\n') + end screen:expect('line30 ', nil, nil, nil, true) retry(nil, nil, function() expect_lines(7) end) @@ -395,7 +431,13 @@ describe("'scrollback' option", function() end) it('deletes lines (only) if necessary', function() - local screen = thelpers.screen_setup(nil, "['sh']", 30) + local screen + if iswin() then + screen = thelpers.screen_setup(nil, + "['powershell.exe', '-NoLogo', '-NoProfile', '-NoExit', '-Command', 'function global:prompt {return "..'"$"'.."}']", 30) + else + screen = thelpers.screen_setup(nil, "['sh']", 30) + end curbufmeths.set_option('scrollback', 200) @@ -403,7 +445,11 @@ describe("'scrollback' option", function() screen:expect('$', nil, nil, nil, true) wait() - feed_data('for i in $(seq 1 30); do echo "line$i"; done\n') + if iswin() then + feed_data('for($i=1;$i -le 30;$i++){Write-Host \"line$i\"}\r') + else + feed_data('for i in $(seq 1 30); do echo "line$i"; done\n') + end screen:expect('line30 ', nil, nil, nil, true) @@ -416,7 +462,11 @@ describe("'scrollback' option", function() -- Terminal job data is received asynchronously, may happen before the -- 'scrollback' option is synchronized with the internal sb_buffer. command('sleep 100m') - feed_data('for i in $(seq 1 40); do echo "line$i"; done\n') + if iswin() then + feed_data('for($i=1;$i -le 40;$i++){Write-Host \"line$i\"}\r') + else + feed_data('for i in $(seq 1 40); do echo "line$i"; done\n') + end screen:expect('line40 ', nil, nil, nil, true) diff --git a/test/functional/terminal/window_spec.lua b/test/functional/terminal/window_spec.lua index 888b1e1328..0f705cfe40 100644 --- a/test/functional/terminal/window_spec.lua +++ b/test/functional/terminal/window_spec.lua @@ -3,8 +3,6 @@ local thelpers = require('test.functional.terminal.helpers') local feed, clear = helpers.feed, helpers.clear local wait = helpers.wait -if helpers.pending_win32(pending) then return end - describe('terminal window', function() local screen -- cgit From 1614e805b33bf159a7af06ed54a0fb5823d8e407 Mon Sep 17 00:00:00 2001 From: erw7 Date: Fri, 31 Mar 2017 05:40:37 +0900 Subject: win/test: tty-test: print screen size explicitly with CTRL-Q tty-test.exe causes abnormal termination with low repeatability, try changing it so as not to use SIGWINCH. --- test/functional/fixtures/tty-test.c | 53 +++++++++++++++++----------- test/functional/terminal/helpers.lua | 7 ++-- test/functional/terminal/scrollback_spec.lua | 18 +++++----- 3 files changed, 44 insertions(+), 34 deletions(-) (limited to 'test') diff --git a/test/functional/fixtures/tty-test.c b/test/functional/fixtures/tty-test.c index dd94d1a256..3e71ca209b 100644 --- a/test/functional/fixtures/tty-test.c +++ b/test/functional/fixtures/tty-test.c @@ -15,11 +15,11 @@ uv_tty_t tty; #include bool owns_tty(void) { - /* XXX: We need to make proper detect owns tty */ - /* HWND consoleWnd = GetConsoleWindow(); */ - /* DWORD dwProcessId; */ - /* GetWindowThreadProcessId(consoleWnd, &dwProcessId); */ - /* return GetCurrentProcessId() == dwProcessId; */ + // XXX: We need to make proper detect owns tty + // HWND consoleWnd = GetConsoleWindow(); + // DWORD dwProcessId; + // GetWindowThreadProcessId(consoleWnd, &dwProcessId); + // return GetCurrentProcessId() == dwProcessId; return true; } #else @@ -57,15 +57,15 @@ static void sig_handler(int signum) } } #else -static void sigwinch_cb(uv_signal_t *handle, int signum) -{ - int width, height; - uv_tty_t out; - uv_tty_init(uv_default_loop(), &out, fileno(stdout), 0); - uv_tty_get_winsize(&out, &width, &height); - fprintf(stderr, "rows: %d, cols: %d\n", height, width); - uv_close((uv_handle_t *)&out, NULL); -} +// static void sigwinch_cb(uv_signal_t *handle, int signum) +// { +// int width, height; +// uv_tty_t out; +// uv_tty_init(uv_default_loop(), &out, fileno(stdout), 0); +// uv_tty_get_winsize(&out, &width, &height); +// fprintf(stderr, "rows: %d, cols: %d\n", height, width); +// uv_close((uv_handle_t *)&out, NULL); +// } #endif static void alloc_cb(uv_handle_t *handle, size_t suggested, uv_buf_t *buf) @@ -82,10 +82,14 @@ static void read_cb(uv_stream_t *stream, ssize_t cnt, const uv_buf_t *buf) } int *interrupted = stream->data; + bool prsz = false; + int width, height; for (int i = 0; i < cnt; i++) { if (buf->base[i] == 3) { (*interrupted)++; + } else if (buf->base[i] == 17) { + prsz = true; } } @@ -93,10 +97,17 @@ static void read_cb(uv_stream_t *stream, ssize_t cnt, const uv_buf_t *buf) uv_loop_init(&write_loop); uv_tty_t out; uv_tty_init(&write_loop, &out, fileno(stdout), 0); - uv_write_t req; - uv_buf_t b = {.base = buf->base, .len = (size_t)cnt}; - uv_write(&req, STRUCT_CAST(uv_stream_t, &out), &b, 1, NULL); - uv_run(&write_loop, UV_RUN_DEFAULT); + + if (prsz) { + uv_tty_get_winsize(&out, &width, &height); + fprintf(stderr, "rows: %d, cols: %d\n", height, width); + } else { + uv_write_t req; + uv_buf_t b = {.base = buf->base, .len = (size_t)cnt}; + uv_write(&req, STRUCT_CAST(uv_stream_t, &out), &b, 1, NULL); + uv_run(&write_loop, UV_RUN_DEFAULT); + } + uv_close(STRUCT_CAST(uv_handle_t, &out), NULL); uv_run(&write_loop, UV_RUN_DEFAULT); if (uv_loop_close(&write_loop)) { @@ -169,9 +180,9 @@ int main(int argc, char **argv) sigaction(SIGHUP, &sa, NULL); sigaction(SIGWINCH, &sa, NULL); #else - uv_signal_t sigwinch_watcher; - uv_signal_init(uv_default_loop(), &sigwinch_watcher); - uv_signal_start(&sigwinch_watcher, sigwinch_cb, SIGWINCH); + // uv_signal_t sigwinch_watcher; + // uv_signal_init(uv_default_loop(), &sigwinch_watcher); + // uv_signal_start(&sigwinch_watcher, sigwinch_cb, SIGWINCH); #endif uv_run(uv_default_loop(), UV_RUN_DEFAULT); diff --git a/test/functional/terminal/helpers.lua b/test/functional/terminal/helpers.lua index 29381ab4f0..c67640f048 100644 --- a/test/functional/terminal/helpers.lua +++ b/test/functional/terminal/helpers.lua @@ -30,10 +30,9 @@ local function clear_attrs() feed_termcode('[0;10m') end -- mouse local function enable_mouse() feed_termcode('[?1002h') end local function disable_mouse() feed_termcode('[?1002l') end -local function wait_sigwinch() +local function print_screen_size() helpers.sleep(1000) - hide_cursor() - show_cursor() + nvim('command', 'call jobsend(b:terminal_job_id, "\\")') end local default_command = '["'..nvim_dir..'/tty-test'..'"]' @@ -116,6 +115,6 @@ return { clear_attrs = clear_attrs, enable_mouse = enable_mouse, disable_mouse = disable_mouse, - wait_sigwinch = wait_sigwinch, + print_screen_size = print_screen_size, screen_setup = screen_setup } diff --git a/test/functional/terminal/scrollback_spec.lua b/test/functional/terminal/scrollback_spec.lua index 649bb4373b..1333736376 100644 --- a/test/functional/terminal/scrollback_spec.lua +++ b/test/functional/terminal/scrollback_spec.lua @@ -3,7 +3,7 @@ local helpers = require('test.functional.helpers')(after_each) local thelpers = require('test.functional.terminal.helpers') local clear, eq, curbuf = helpers.clear, helpers.eq, helpers.curbuf local feed, nvim_dir, feed_command = helpers.feed, helpers.nvim_dir, helpers.feed_command -local iswin, wait_sigwinch = helpers.iswin, thelpers.wait_sigwinch +local iswin, print_screen_size = helpers.iswin, thelpers.print_screen_size local eval = helpers.eval local command = helpers.command local wait = helpers.wait @@ -142,7 +142,7 @@ describe('terminal scrollback', function() local function will_hide_top_line() screen:try_resize(screen._width, screen._height - 1) if iswin() then - wait_sigwinch() + print_screen_size() end screen:expect([[ line2 | @@ -161,7 +161,7 @@ describe('terminal scrollback', function() will_hide_top_line() screen:try_resize(screen._width, screen._height - 2) if iswin() then - wait_sigwinch() + print_screen_size() end end) @@ -190,7 +190,7 @@ describe('terminal scrollback', function() before_each(function() screen:try_resize(screen._width, screen._height - 2) if iswin() then - wait_sigwinch() + print_screen_size() end end) @@ -214,7 +214,7 @@ describe('terminal scrollback', function() will_delete_last_two_lines() screen:try_resize(screen._width, screen._height - 1) if iswin() then - wait_sigwinch() + print_screen_size() end end) @@ -259,7 +259,7 @@ describe('terminal scrollback', function() ]]) screen:try_resize(screen._width, screen._height - 3) if iswin() then - wait_sigwinch() + print_screen_size() end screen:expect([[ line4 | @@ -274,7 +274,7 @@ describe('terminal scrollback', function() local function pop_then_push() screen:try_resize(screen._width, screen._height + 1) if iswin() then - wait_sigwinch() + print_screen_size() end screen:expect([[ line4 | @@ -293,7 +293,7 @@ describe('terminal scrollback', function() eq(8, curbuf('line_count')) screen:try_resize(screen._width, screen._height + 3) if iswin() then - wait_sigwinch() + print_screen_size() end end) @@ -331,7 +331,7 @@ describe('terminal scrollback', function() feed('Gi') screen:try_resize(screen._width, screen._height + 4) if iswin() then - wait_sigwinch() + print_screen_size() end end) -- cgit From d3a8c4f99289f7b65a68bf9ed5eeab34aa688e0e Mon Sep 17 00:00:00 2001 From: erw7 Date: Sun, 2 Apr 2017 18:32:23 +0900 Subject: win/pty: log errors --- test/functional/fixtures/tty-test.c | 60 +++++++++++++++++++++++----- test/functional/terminal/helpers.lua | 5 --- test/functional/terminal/scrollback_spec.lua | 36 +++-------------- test/functional/ui/screen.lua | 13 ++++++ 4 files changed, 68 insertions(+), 46 deletions(-) (limited to 'test') diff --git a/test/functional/fixtures/tty-test.c b/test/functional/fixtures/tty-test.c index 3e71ca209b..60d6f5485b 100644 --- a/test/functional/fixtures/tty-test.c +++ b/test/functional/fixtures/tty-test.c @@ -4,15 +4,34 @@ #include #include #include + #include +#ifdef _WIN32 +#include +#endif // -V:STRUCT_CAST:641 #define STRUCT_CAST(Type, obj) ((Type *)(obj)) +#define is_terminal(stream) (uv_guess_handle(fileno(stream)) == UV_TTY) +#define BUF_SIZE 0xfff +#define CTRL_C 0x03 +#ifdef _WIN32 +#define CTRL_Q 0x11 +#endif + +#ifdef _WIN32 +typedef struct screen_size { + int width; + int height; +} ScreenSize; +#endif uv_tty_t tty; +#ifdef _WIN32 +ScreenSize screen_rect; +#endif #ifdef _WIN32 -#include bool owns_tty(void) { // XXX: We need to make proper detect owns tty @@ -30,10 +49,8 @@ bool owns_tty(void) } #endif -#define is_terminal(stream) (uv_guess_handle(fileno(stream)) == UV_TTY) -#define BUF_SIZE 0xfff - -static void walk_cb(uv_handle_t *handle, void *arg) { +static void walk_cb(uv_handle_t *handle, void *arg) +{ if (!uv_is_closing(handle)) { uv_close(handle, NULL); } @@ -42,7 +59,7 @@ static void walk_cb(uv_handle_t *handle, void *arg) { #ifndef WIN32 static void sig_handler(int signum) { - switch(signum) { + switch (signum) { case SIGWINCH: { int width, height; uv_tty_get_winsize(&tty, &width, &height); @@ -82,14 +99,19 @@ static void read_cb(uv_stream_t *stream, ssize_t cnt, const uv_buf_t *buf) } int *interrupted = stream->data; +#ifdef _WIN32 bool prsz = false; - int width, height; + int width; + int height; +#endif for (int i = 0; i < cnt; i++) { - if (buf->base[i] == 3) { + if (buf->base[i] == CTRL_C) { (*interrupted)++; - } else if (buf->base[i] == 17) { +#ifdef _WIN32 + } else if (buf->base[i] == CTRL_Q) { prsz = true; +#endif } } @@ -98,15 +120,23 @@ static void read_cb(uv_stream_t *stream, ssize_t cnt, const uv_buf_t *buf) uv_tty_t out; uv_tty_init(&write_loop, &out, fileno(stdout), 0); +#ifdef _WIN32 if (prsz) { uv_tty_get_winsize(&out, &width, &height); - fprintf(stderr, "rows: %d, cols: %d\n", height, width); + if (screen_rect.width != width || screen_rect.height != height) { + screen_rect.width = width; + screen_rect.height = height; + fprintf(stderr, "rows: %d, cols: %d\n", height, width); + } } else { +#endif uv_write_t req; uv_buf_t b = {.base = buf->base, .len = (size_t)cnt}; uv_write(&req, STRUCT_CAST(uv_stream_t, &out), &b, 1, NULL); uv_run(&write_loop, UV_RUN_DEFAULT); +#ifdef _WIN32 } +#endif uv_close(STRUCT_CAST(uv_handle_t, &out), NULL); uv_run(&write_loop, UV_RUN_DEFAULT); @@ -152,7 +182,7 @@ int main(int argc, char **argv) if (argc > 1) { int count = atoi(argv[1]); - for (int i = 0; i < count; ++i) { + for (int i = 0; i < count; i++) { printf("line%d\n", i); } fflush(stdout); @@ -168,6 +198,14 @@ int main(int argc, char **argv) uv_tty_init(uv_default_loop(), &tty, fileno(stderr), 1); #else uv_tty_init(uv_default_loop(), &tty, fileno(stdin), 1); + uv_tty_t out; + uv_tty_init(uv_default_loop(), &out, fileno(stdout), 0); + int width; + int height; + uv_tty_get_winsize(&out, &width, &height); + screen_rect.width = width; + screen_rect.height = height; + uv_close((uv_handle_t *)&out, NULL); #endif uv_tty_set_mode(&tty, UV_TTY_MODE_RAW); tty.data = &interrupted; diff --git a/test/functional/terminal/helpers.lua b/test/functional/terminal/helpers.lua index c67640f048..bd24b9785d 100644 --- a/test/functional/terminal/helpers.lua +++ b/test/functional/terminal/helpers.lua @@ -30,10 +30,6 @@ local function clear_attrs() feed_termcode('[0;10m') end -- mouse local function enable_mouse() feed_termcode('[?1002h') end local function disable_mouse() feed_termcode('[?1002l') end -local function print_screen_size() - helpers.sleep(1000) - nvim('command', 'call jobsend(b:terminal_job_id, "\\")') -end local default_command = '["'..nvim_dir..'/tty-test'..'"]' @@ -115,6 +111,5 @@ return { clear_attrs = clear_attrs, enable_mouse = enable_mouse, disable_mouse = disable_mouse, - print_screen_size = print_screen_size, screen_setup = screen_setup } diff --git a/test/functional/terminal/scrollback_spec.lua b/test/functional/terminal/scrollback_spec.lua index 1333736376..f39335bfd0 100644 --- a/test/functional/terminal/scrollback_spec.lua +++ b/test/functional/terminal/scrollback_spec.lua @@ -3,7 +3,7 @@ local helpers = require('test.functional.helpers')(after_each) local thelpers = require('test.functional.terminal.helpers') local clear, eq, curbuf = helpers.clear, helpers.eq, helpers.curbuf local feed, nvim_dir, feed_command = helpers.feed, helpers.nvim_dir, helpers.feed_command -local iswin, print_screen_size = helpers.iswin, thelpers.print_screen_size +local iswin = helpers.iswin local eval = helpers.eval local command = helpers.command local wait = helpers.wait @@ -141,10 +141,7 @@ describe('terminal scrollback', function() describe('and the height is decreased by 1', function() local function will_hide_top_line() screen:try_resize(screen._width, screen._height - 1) - if iswin() then - print_screen_size() - end - screen:expect([[ + screen:expect_after_resize([[ line2 | line3 | line4 | @@ -160,13 +157,10 @@ describe('terminal scrollback', function() before_each(function() will_hide_top_line() screen:try_resize(screen._width, screen._height - 2) - if iswin() then - print_screen_size() - end end) it('will hide the top 3 lines', function() - screen:expect([[ + screen:expect_after_resize([[ rows: 5, cols: 30 | rows: 3, cols: 30 | {1: } | @@ -189,9 +183,6 @@ describe('terminal scrollback', function() describe('and the height is decreased by 2', function() before_each(function() screen:try_resize(screen._width, screen._height - 2) - if iswin() then - print_screen_size() - end end) local function will_delete_last_two_lines() @@ -213,9 +204,6 @@ describe('terminal scrollback', function() before_each(function() will_delete_last_two_lines() screen:try_resize(screen._width, screen._height - 1) - if iswin() then - print_screen_size() - end end) it('will delete the last line and hide the first', function() @@ -258,10 +246,7 @@ describe('terminal scrollback', function() {3:-- TERMINAL --} | ]]) screen:try_resize(screen._width, screen._height - 3) - if iswin() then - print_screen_size() - end - screen:expect([[ + screen:expect_after_resize([[ line4 | rows: 3, cols: 30 | {1: } | @@ -273,10 +258,7 @@ describe('terminal scrollback', function() describe('and the height is increased by 1', function() local function pop_then_push() screen:try_resize(screen._width, screen._height + 1) - if iswin() then - print_screen_size() - end - screen:expect([[ + screen:expect_after_resize([[ line4 | rows: 3, cols: 30 | rows: 4, cols: 30 | @@ -292,13 +274,10 @@ describe('terminal scrollback', function() pop_then_push() eq(8, curbuf('line_count')) screen:try_resize(screen._width, screen._height + 3) - if iswin() then - print_screen_size() - end end) local function pop3_then_push1() - screen:expect([[ + screen:expect_after_resize([[ line2 | line3 | line4 | @@ -330,9 +309,6 @@ describe('terminal scrollback', function() pop3_then_push1() feed('Gi') screen:try_resize(screen._width, screen._height + 4) - if iswin() then - print_screen_size() - end end) it('will show all lines and leave a blank one at the end', function() diff --git a/test/functional/ui/screen.lua b/test/functional/ui/screen.lua index a6b7fb2997..77b69041e0 100644 --- a/test/functional/ui/screen.lua +++ b/test/functional/ui/screen.lua @@ -73,6 +73,8 @@ local helpers = require('test.functional.helpers')(nil) local request, run, uimeths = helpers.request, helpers.run, helpers.uimeths +local iswin, nvim, retry = helpers.iswin, helpers.nvim, helpers.retry + local dedent = helpers.dedent local Screen = {} @@ -259,6 +261,17 @@ screen:redraw_debug() to show all intermediate screen states. ]]) end) end +function Screen:expect_after_resize(expected) + if iswin() then + retry(nil, nil, function() + nvim('command', 'call jobsend(b:terminal_job_id, "\\")') + self:expect(expected) + end) + else + self:expect(expected) + end +end + function Screen:wait(check, timeout) local err, checked = false local success_seen = false -- cgit From 6a90f53862d9f75f7aeea350944c466aa85f11a2 Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Sun, 6 Aug 2017 14:26:17 +0200 Subject: test: cleanup --- test/functional/fixtures/tty-test.c | 48 ++++++++++------------------ test/functional/terminal/scrollback_spec.lua | 20 ++++++++---- test/functional/ui/screen.lua | 21 ++++++------ 3 files changed, 39 insertions(+), 50 deletions(-) (limited to 'test') diff --git a/test/functional/fixtures/tty-test.c b/test/functional/fixtures/tty-test.c index 60d6f5485b..2b22352cda 100644 --- a/test/functional/fixtures/tty-test.c +++ b/test/functional/fixtures/tty-test.c @@ -4,10 +4,11 @@ #include #include #include - #include #ifdef _WIN32 -#include +# include +#else +# include #endif // -V:STRUCT_CAST:641 @@ -15,39 +16,31 @@ #define is_terminal(stream) (uv_guess_handle(fileno(stream)) == UV_TTY) #define BUF_SIZE 0xfff #define CTRL_C 0x03 -#ifdef _WIN32 #define CTRL_Q 0x11 -#endif + +uv_tty_t tty; #ifdef _WIN32 typedef struct screen_size { int width; int height; } ScreenSize; -#endif - -uv_tty_t tty; -#ifdef _WIN32 ScreenSize screen_rect; #endif -#ifdef _WIN32 bool owns_tty(void) { +#ifdef _WIN32 // XXX: We need to make proper detect owns tty // HWND consoleWnd = GetConsoleWindow(); // DWORD dwProcessId; // GetWindowThreadProcessId(consoleWnd, &dwProcessId); // return GetCurrentProcessId() == dwProcessId; return true; -} #else -#include -bool owns_tty(void) -{ return getsid(0) == getpid(); -} #endif +} static void walk_cb(uv_handle_t *handle, void *arg) { @@ -56,7 +49,6 @@ static void walk_cb(uv_handle_t *handle, void *arg) } } -#ifndef WIN32 static void sig_handler(int signum) { switch (signum) { @@ -73,17 +65,6 @@ static void sig_handler(int signum) return; } } -#else -// static void sigwinch_cb(uv_signal_t *handle, int signum) -// { -// int width, height; -// uv_tty_t out; -// uv_tty_init(uv_default_loop(), &out, fileno(stdout), 0); -// uv_tty_get_winsize(&out, &width, &height); -// fprintf(stderr, "rows: %d, cols: %d\n", height, width); -// uv_close((uv_handle_t *)&out, NULL); -// } -#endif static void alloc_cb(uv_handle_t *handle, size_t suggested, uv_buf_t *buf) { @@ -100,9 +81,9 @@ static void read_cb(uv_stream_t *stream, ssize_t cnt, const uv_buf_t *buf) int *interrupted = stream->data; #ifdef _WIN32 - bool prsz = false; - int width; - int height; + // HACK: Special-case to avoid relying on SIGWINCH on Windows. + // See note at Screen:try_resize(). + bool invoke_sigwinch_handler = false; #endif for (int i = 0; i < cnt; i++) { @@ -110,7 +91,7 @@ static void read_cb(uv_stream_t *stream, ssize_t cnt, const uv_buf_t *buf) (*interrupted)++; #ifdef _WIN32 } else if (buf->base[i] == CTRL_Q) { - prsz = true; + invoke_sigwinch_handler = true; #endif } } @@ -121,12 +102,15 @@ static void read_cb(uv_stream_t *stream, ssize_t cnt, const uv_buf_t *buf) uv_tty_init(&write_loop, &out, fileno(stdout), 0); #ifdef _WIN32 - if (prsz) { + if (invoke_sigwinch_handler) { + int width, height; uv_tty_get_winsize(&out, &width, &height); if (screen_rect.width != width || screen_rect.height != height) { screen_rect.width = width; screen_rect.height = height; - fprintf(stderr, "rows: %d, cols: %d\n", height, width); + // HACK: Invoke directly. See note at Screen:try_resize(). + sig_handler(SIGWINCH); + uv_run(&write_loop, UV_RUN_NOWAIT); } } else { #endif diff --git a/test/functional/terminal/scrollback_spec.lua b/test/functional/terminal/scrollback_spec.lua index f39335bfd0..b6b0228513 100644 --- a/test/functional/terminal/scrollback_spec.lua +++ b/test/functional/terminal/scrollback_spec.lua @@ -141,7 +141,8 @@ describe('terminal scrollback', function() describe('and the height is decreased by 1', function() local function will_hide_top_line() screen:try_resize(screen._width, screen._height - 1) - screen:expect_after_resize([[ + retry(nil, 100000, function() + screen:expect([[ line2 | line3 | line4 | @@ -149,6 +150,7 @@ describe('terminal scrollback', function() {1: } | {3:-- TERMINAL --} | ]]) + end) end it('will hide top line', will_hide_top_line) @@ -160,7 +162,8 @@ describe('terminal scrollback', function() end) it('will hide the top 3 lines', function() - screen:expect_after_resize([[ + retry(nil, 100000, function() + screen:expect([[ rows: 5, cols: 30 | rows: 3, cols: 30 | {1: } | @@ -174,19 +177,21 @@ describe('terminal scrollback', function() rows: 3, cols: 30 | | ]]) + end) end) end) end) end) describe('with empty lines after the cursor', function() + if helpers.pending_win32(pending) then return end + describe('and the height is decreased by 2', function() before_each(function() screen:try_resize(screen._width, screen._height - 2) end) local function will_delete_last_two_lines() - if helpers.pending_win32(pending) then return end screen:expect([[ tty ready | rows: 4, cols: 30 | @@ -200,7 +205,6 @@ describe('terminal scrollback', function() it('will delete the last two empty lines', will_delete_last_two_lines) describe('and then decreased by 1', function() - if helpers.pending_win32(pending) then return end before_each(function() will_delete_last_two_lines() screen:try_resize(screen._width, screen._height - 1) @@ -246,19 +250,21 @@ describe('terminal scrollback', function() {3:-- TERMINAL --} | ]]) screen:try_resize(screen._width, screen._height - 3) - screen:expect_after_resize([[ + retry(nil, 100000, function() + screen:expect([[ line4 | rows: 3, cols: 30 | {1: } | {3:-- TERMINAL --} | ]]) eq(7, curbuf('line_count')) + end) end) describe('and the height is increased by 1', function() local function pop_then_push() screen:try_resize(screen._width, screen._height + 1) - screen:expect_after_resize([[ + screen:expect([[ line4 | rows: 3, cols: 30 | rows: 4, cols: 30 | @@ -277,7 +283,7 @@ describe('terminal scrollback', function() end) local function pop3_then_push1() - screen:expect_after_resize([[ + screen:expect([[ line2 | line3 | line4 | diff --git a/test/functional/ui/screen.lua b/test/functional/ui/screen.lua index 77b69041e0..c1df7ede43 100644 --- a/test/functional/ui/screen.lua +++ b/test/functional/ui/screen.lua @@ -176,6 +176,16 @@ function Screen:try_resize(columns, rows) -- Give ourselves a chance to _handle_resize, which requires using -- self.sleep() (for the resize notification) rather than run() self:sleep(0.1) + + -- XXX: On Windows we don't bother to handle SIGWINCH. + -- CTRL-Q invokes the handler in tty-test.c directly. + -- uv_tty_update_virtual_window() _does_ emit SIGWINCH, but: + -- "SIGWINCH may not always be delivered in a timely manner; libuv + -- will only detect size changes when the cursor is being moved." + -- http://docs.libuv.org/en/v1.x/signal.html + if iswin() and 0 ~= nvim('eval', "exists('b:terminal_job_id')") then + nvim('command', [[call jobsend(b:terminal_job_id, "\")]]) + end end -- Asserts that `expected` eventually matches the screen state. @@ -261,17 +271,6 @@ screen:redraw_debug() to show all intermediate screen states. ]]) end) end -function Screen:expect_after_resize(expected) - if iswin() then - retry(nil, nil, function() - nvim('command', 'call jobsend(b:terminal_job_id, "\\")') - self:expect(expected) - end) - else - self:expect(expected) - end -end - function Screen:wait(check, timeout) local err, checked = false local success_seen = false -- cgit From e0763e94ade67c99f9d9f46cd51299b174969927 Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Mon, 7 Aug 2017 00:26:43 +0200 Subject: test: tty-test.c: restore win32 SIGWINCH handler --- test/functional/fixtures/tty-test.c | 50 +++++++++++++++++----------- test/functional/terminal/scrollback_spec.lua | 14 ++++---- test/functional/ui/screen.lua | 12 ------- 3 files changed, 38 insertions(+), 38 deletions(-) (limited to 'test') diff --git a/test/functional/fixtures/tty-test.c b/test/functional/fixtures/tty-test.c index 2b22352cda..9373e2d7ed 100644 --- a/test/functional/fixtures/tty-test.c +++ b/test/functional/fixtures/tty-test.c @@ -49,6 +49,7 @@ static void walk_cb(uv_handle_t *handle, void *arg) } } +#ifndef WIN32 static void sig_handler(int signum) { switch (signum) { @@ -65,6 +66,17 @@ static void sig_handler(int signum) return; } } +#else +static void sigwinch_cb(uv_signal_t *handle, int signum) +{ + int width, height; + uv_tty_t out; + uv_tty_init(uv_default_loop(), &out, fileno(stdout), 0); + uv_tty_get_winsize(&out, &width, &height); + fprintf(stderr, "rows: %d, cols: %d\n", height, width); + uv_close((uv_handle_t *)&out, NULL); +} +#endif static void alloc_cb(uv_handle_t *handle, size_t suggested, uv_buf_t *buf) { @@ -101,26 +113,26 @@ static void read_cb(uv_stream_t *stream, ssize_t cnt, const uv_buf_t *buf) uv_tty_t out; uv_tty_init(&write_loop, &out, fileno(stdout), 0); -#ifdef _WIN32 - if (invoke_sigwinch_handler) { - int width, height; - uv_tty_get_winsize(&out, &width, &height); - if (screen_rect.width != width || screen_rect.height != height) { - screen_rect.width = width; - screen_rect.height = height; - // HACK: Invoke directly. See note at Screen:try_resize(). - sig_handler(SIGWINCH); - uv_run(&write_loop, UV_RUN_NOWAIT); - } - } else { -#endif +// #ifdef _WIN32 +// if (invoke_sigwinch_handler) { +// int width, height; +// uv_tty_get_winsize(&out, &width, &height); +// if (screen_rect.width != width || screen_rect.height != height) { +// screen_rect.width = width; +// screen_rect.height = height; +// // HACK: Invoke directly. See note at Screen:try_resize(). +// sig_handler(SIGWINCH); +// uv_run(&write_loop, UV_RUN_NOWAIT); +// } +// } else { +// #endif uv_write_t req; uv_buf_t b = {.base = buf->base, .len = (size_t)cnt}; uv_write(&req, STRUCT_CAST(uv_stream_t, &out), &b, 1, NULL); uv_run(&write_loop, UV_RUN_DEFAULT); -#ifdef _WIN32 - } -#endif +// #ifdef _WIN32 +// } +// #endif uv_close(STRUCT_CAST(uv_handle_t, &out), NULL); uv_run(&write_loop, UV_RUN_DEFAULT); @@ -202,9 +214,9 @@ int main(int argc, char **argv) sigaction(SIGHUP, &sa, NULL); sigaction(SIGWINCH, &sa, NULL); #else - // uv_signal_t sigwinch_watcher; - // uv_signal_init(uv_default_loop(), &sigwinch_watcher); - // uv_signal_start(&sigwinch_watcher, sigwinch_cb, SIGWINCH); + uv_signal_t sigwinch_watcher; + uv_signal_init(uv_default_loop(), &sigwinch_watcher); + uv_signal_start(&sigwinch_watcher, sigwinch_cb, SIGWINCH); #endif uv_run(uv_default_loop(), UV_RUN_DEFAULT); diff --git a/test/functional/terminal/scrollback_spec.lua b/test/functional/terminal/scrollback_spec.lua index b6b0228513..f804862996 100644 --- a/test/functional/terminal/scrollback_spec.lua +++ b/test/functional/terminal/scrollback_spec.lua @@ -141,7 +141,6 @@ describe('terminal scrollback', function() describe('and the height is decreased by 1', function() local function will_hide_top_line() screen:try_resize(screen._width, screen._height - 1) - retry(nil, 100000, function() screen:expect([[ line2 | line3 | @@ -150,7 +149,6 @@ describe('terminal scrollback', function() {1: } | {3:-- TERMINAL --} | ]]) - end) end it('will hide top line', will_hide_top_line) @@ -162,7 +160,6 @@ describe('terminal scrollback', function() end) it('will hide the top 3 lines', function() - retry(nil, 100000, function() screen:expect([[ rows: 5, cols: 30 | rows: 3, cols: 30 | @@ -177,13 +174,15 @@ describe('terminal scrollback', function() rows: 3, cols: 30 | | ]]) - end) end) end) end) end) describe('with empty lines after the cursor', function() + -- XXX: Can't test this reliably on Windows unless the cursor is _moved_ + -- by the resize. http://docs.libuv.org/en/v1.x/signal.html + -- See also: https://github.com/rprichard/winpty/issues/110 if helpers.pending_win32(pending) then return end describe('and the height is decreased by 2', function() @@ -250,7 +249,6 @@ describe('terminal scrollback', function() {3:-- TERMINAL --} | ]]) screen:try_resize(screen._width, screen._height - 3) - retry(nil, 100000, function() screen:expect([[ line4 | rows: 3, cols: 30 | @@ -258,10 +256,13 @@ describe('terminal scrollback', function() {3:-- TERMINAL --} | ]]) eq(7, curbuf('line_count')) - end) end) describe('and the height is increased by 1', function() + -- XXX: Can't test this reliably on Windows unless the cursor is _moved_ + -- by the resize. http://docs.libuv.org/en/v1.x/signal.html + -- See also: https://github.com/rprichard/winpty/issues/110 + if helpers.pending_win32(pending) then return end local function pop_then_push() screen:try_resize(screen._width, screen._height + 1) screen:expect([[ @@ -310,7 +311,6 @@ describe('terminal scrollback', function() it('will pop 3 lines and then push one back', pop3_then_push1) describe('and then by 4', function() - if helpers.pending_win32(pending) then return end before_each(function() pop3_then_push1() feed('Gi') diff --git a/test/functional/ui/screen.lua b/test/functional/ui/screen.lua index c1df7ede43..a6b7fb2997 100644 --- a/test/functional/ui/screen.lua +++ b/test/functional/ui/screen.lua @@ -73,8 +73,6 @@ local helpers = require('test.functional.helpers')(nil) local request, run, uimeths = helpers.request, helpers.run, helpers.uimeths -local iswin, nvim, retry = helpers.iswin, helpers.nvim, helpers.retry - local dedent = helpers.dedent local Screen = {} @@ -176,16 +174,6 @@ function Screen:try_resize(columns, rows) -- Give ourselves a chance to _handle_resize, which requires using -- self.sleep() (for the resize notification) rather than run() self:sleep(0.1) - - -- XXX: On Windows we don't bother to handle SIGWINCH. - -- CTRL-Q invokes the handler in tty-test.c directly. - -- uv_tty_update_virtual_window() _does_ emit SIGWINCH, but: - -- "SIGWINCH may not always be delivered in a timely manner; libuv - -- will only detect size changes when the cursor is being moved." - -- http://docs.libuv.org/en/v1.x/signal.html - if iswin() and 0 ~= nvim('eval', "exists('b:terminal_job_id')") then - nvim('command', [[call jobsend(b:terminal_job_id, "\")]]) - end end -- Asserts that `expected` eventually matches the screen state. -- cgit From d2d76882f74875d6c1ee10f31524b104eab6375d Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Tue, 8 Aug 2017 02:26:25 +0200 Subject: win/test: enable more :terminal tests To deal with SIGWINCH limitations on Windows, change some resize tests to _shrink_ the screen width. ... But this didn't work, so still ignoring those tests on Windows. --- test/functional/terminal/buffer_spec.lua | 2 -- test/functional/terminal/ex_terminal_spec.lua | 2 -- test/functional/terminal/window_split_tab_spec.lua | 42 ++++++++++------------ 3 files changed, 18 insertions(+), 28 deletions(-) (limited to 'test') diff --git a/test/functional/terminal/buffer_spec.lua b/test/functional/terminal/buffer_spec.lua index 22ab0a8c21..4ce33fef7b 100644 --- a/test/functional/terminal/buffer_spec.lua +++ b/test/functional/terminal/buffer_spec.lua @@ -70,7 +70,6 @@ describe('terminal buffer', function() end) it('cannot be modified directly', function() - if helpers.pending_win32(pending) then return end feed('dd') screen:expect([[ tty ready | @@ -205,7 +204,6 @@ describe('terminal buffer', function() end) describe('No heap-buffer-overflow when using', function() - if helpers.pending_win32(pending) then return end local testfilename = 'Xtestfile-functional-terminal-buffers_spec' before_each(function() diff --git a/test/functional/terminal/ex_terminal_spec.lua b/test/functional/terminal/ex_terminal_spec.lua index 5eb6a5f18c..9930efc402 100644 --- a/test/functional/terminal/ex_terminal_spec.lua +++ b/test/functional/terminal/ex_terminal_spec.lua @@ -182,9 +182,7 @@ describe(':terminal (with fake shell)', function() end) it('works with gf', function() - if helpers.pending_win32(pending) then return end terminal_with_fake_shell([[echo "scripts/shadacat.py"]]) - wait() screen:expect([[ ready $ echo "scripts/shadacat.py" | | diff --git a/test/functional/terminal/window_split_tab_spec.lua b/test/functional/terminal/window_split_tab_spec.lua index 4867e0d9fa..27c6c54d19 100644 --- a/test/functional/terminal/window_split_tab_spec.lua +++ b/test/functional/terminal/window_split_tab_spec.lua @@ -4,8 +4,6 @@ local clear = helpers.clear local feed, nvim = helpers.feed, helpers.nvim local feed_command = helpers.feed_command -if helpers.pending_win32(pending) then return end - describe('terminal', function() local screen @@ -25,6 +23,7 @@ describe('terminal', function() end) it('resets its size when entering terminal window', function() + if helpers.pending_win32(pending) then return end feed('') feed_command('2split') screen:expect([[ @@ -69,31 +68,26 @@ describe('terminal', function() describe('when the screen is resized', function() it('will forward a resize request to the program', function() - screen:try_resize(screen._width + 3, screen._height + 5) + if helpers.pending_win32(pending) then return end + feed([[:]]) -- Go to cmdline-mode, so cursor is at bottom. + screen:try_resize(screen._width - 3, screen._height - 2) screen:expect([[ - tty ready | - rows: 14, cols: 53 | - {1: } | - | - | - | - | - | - | - | - | - | - | - | - {3:-- TERMINAL --} | + tty ready | + rows: 7, cols: 47 | + {2: } | + | + | + | + | + :^ | ]]) - screen:try_resize(screen._width - 6, screen._height - 10) + screen:try_resize(screen._width - 6, screen._height - 3) screen:expect([[ - tty ready | - rows: 14, cols: 53 | - rows: 4, cols: 47 | - {1: } | - {3:-- TERMINAL --} | + tty ready | + rows: 7, cols: 47 | + rows: 4, cols: 41 | + {2: } | + :^ | ]]) end) end) -- cgit From 91c85a6378e93b6ef0415c47ca7cb03bf1d57e2d Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Sun, 13 Aug 2017 15:24:25 +0200 Subject: test: tty-test.c: keep `tty_out` handle around Now the window_split_tab_spec.lua test seems to work. Also do some cleanup. --- test/functional/fixtures/tty-test.c | 64 ++++------------------ test/functional/terminal/window_split_tab_spec.lua | 1 - 2 files changed, 11 insertions(+), 54 deletions(-) (limited to 'test') diff --git a/test/functional/fixtures/tty-test.c b/test/functional/fixtures/tty-test.c index 9373e2d7ed..edcbe23f86 100644 --- a/test/functional/fixtures/tty-test.c +++ b/test/functional/fixtures/tty-test.c @@ -16,17 +16,9 @@ #define is_terminal(stream) (uv_guess_handle(fileno(stream)) == UV_TTY) #define BUF_SIZE 0xfff #define CTRL_C 0x03 -#define CTRL_Q 0x11 uv_tty_t tty; - -#ifdef _WIN32 -typedef struct screen_size { - int width; - int height; -} ScreenSize; -ScreenSize screen_rect; -#endif +uv_tty_t tty_out; bool owns_tty(void) { @@ -49,7 +41,6 @@ static void walk_cb(uv_handle_t *handle, void *arg) } } -#ifndef WIN32 static void sig_handler(int signum) { switch (signum) { @@ -66,15 +57,13 @@ static void sig_handler(int signum) return; } } -#else + +#ifdef WIN32 static void sigwinch_cb(uv_signal_t *handle, int signum) { int width, height; - uv_tty_t out; - uv_tty_init(uv_default_loop(), &out, fileno(stdout), 0); - uv_tty_get_winsize(&out, &width, &height); + uv_tty_get_winsize(&tty_out, &width, &height); fprintf(stderr, "rows: %d, cols: %d\n", height, width); - uv_close((uv_handle_t *)&out, NULL); } #endif @@ -92,19 +81,10 @@ static void read_cb(uv_stream_t *stream, ssize_t cnt, const uv_buf_t *buf) } int *interrupted = stream->data; -#ifdef _WIN32 - // HACK: Special-case to avoid relying on SIGWINCH on Windows. - // See note at Screen:try_resize(). - bool invoke_sigwinch_handler = false; -#endif for (int i = 0; i < cnt; i++) { if (buf->base[i] == CTRL_C) { (*interrupted)++; -#ifdef _WIN32 - } else if (buf->base[i] == CTRL_Q) { - invoke_sigwinch_handler = true; -#endif } } @@ -113,26 +93,10 @@ static void read_cb(uv_stream_t *stream, ssize_t cnt, const uv_buf_t *buf) uv_tty_t out; uv_tty_init(&write_loop, &out, fileno(stdout), 0); -// #ifdef _WIN32 -// if (invoke_sigwinch_handler) { -// int width, height; -// uv_tty_get_winsize(&out, &width, &height); -// if (screen_rect.width != width || screen_rect.height != height) { -// screen_rect.width = width; -// screen_rect.height = height; -// // HACK: Invoke directly. See note at Screen:try_resize(). -// sig_handler(SIGWINCH); -// uv_run(&write_loop, UV_RUN_NOWAIT); -// } -// } else { -// #endif - uv_write_t req; - uv_buf_t b = {.base = buf->base, .len = (size_t)cnt}; - uv_write(&req, STRUCT_CAST(uv_stream_t, &out), &b, 1, NULL); - uv_run(&write_loop, UV_RUN_DEFAULT); -// #ifdef _WIN32 -// } -// #endif + uv_write_t req; + uv_buf_t b = {.base = buf->base, .len = (size_t)cnt}; + uv_write(&req, STRUCT_CAST(uv_stream_t, &out), &b, 1, NULL); + uv_run(&write_loop, UV_RUN_DEFAULT); uv_close(STRUCT_CAST(uv_handle_t, &out), NULL); uv_run(&write_loop, UV_RUN_DEFAULT); @@ -189,19 +153,13 @@ int main(int argc, char **argv) uv_prepare_t prepare; uv_prepare_init(uv_default_loop(), &prepare); uv_prepare_start(&prepare, prepare_cb); - // uv_tty_t tty; #ifndef WIN32 uv_tty_init(uv_default_loop(), &tty, fileno(stderr), 1); #else uv_tty_init(uv_default_loop(), &tty, fileno(stdin), 1); - uv_tty_t out; - uv_tty_init(uv_default_loop(), &out, fileno(stdout), 0); - int width; - int height; - uv_tty_get_winsize(&out, &width, &height); - screen_rect.width = width; - screen_rect.height = height; - uv_close((uv_handle_t *)&out, NULL); + uv_tty_init(uv_default_loop(), &tty_out, fileno(stdout), 0); + int width, height; + uv_tty_get_winsize(&tty_out, &width, &height); #endif uv_tty_set_mode(&tty, UV_TTY_MODE_RAW); tty.data = &interrupted; diff --git a/test/functional/terminal/window_split_tab_spec.lua b/test/functional/terminal/window_split_tab_spec.lua index 27c6c54d19..c5199f620e 100644 --- a/test/functional/terminal/window_split_tab_spec.lua +++ b/test/functional/terminal/window_split_tab_spec.lua @@ -68,7 +68,6 @@ describe('terminal', function() describe('when the screen is resized', function() it('will forward a resize request to the program', function() - if helpers.pending_win32(pending) then return end feed([[:]]) -- Go to cmdline-mode, so cursor is at bottom. screen:try_resize(screen._width - 3, screen._height - 2) screen:expect([[ -- cgit From dbb404542b3dc165e8186c839b5071f6511f8f8e Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Sun, 13 Aug 2017 19:54:48 +0200 Subject: test/win: place cursor at edge to tickle SIGWINCH --- test/functional/terminal/scrollback_spec.lua | 39 ++++++++++++++-------------- 1 file changed, 20 insertions(+), 19 deletions(-) (limited to 'test') diff --git a/test/functional/terminal/scrollback_spec.lua b/test/functional/terminal/scrollback_spec.lua index f804862996..acfa92e2f0 100644 --- a/test/functional/terminal/scrollback_spec.lua +++ b/test/functional/terminal/scrollback_spec.lua @@ -57,7 +57,7 @@ describe('terminal scrollback', function() end) end) - describe('with the cursor at the last row', function() + describe('with cursor at last row', function() before_each(function() feed_data({'line1', 'line2', 'line3', 'line4', ''}) screen:expect([[ @@ -138,16 +138,17 @@ describe('terminal scrollback', function() end) - describe('and the height is decreased by 1', function() + describe('and height decreased by 1', function() local function will_hide_top_line() - screen:try_resize(screen._width, screen._height - 1) + feed([[:]]) -- Go to cmdline-mode, so cursor is at bottom. + screen:try_resize(screen._width - 2, screen._height - 1) screen:expect([[ - line2 | - line3 | - line4 | - rows: 5, cols: 30 | - {1: } | - {3:-- TERMINAL --} | + line2 | + line3 | + line4 | + rows: 5, cols: 28 | + {2: } | + :^ | ]]) end @@ -156,23 +157,23 @@ describe('terminal scrollback', function() describe('and then decreased by 2', function() before_each(function() will_hide_top_line() - screen:try_resize(screen._width, screen._height - 2) + screen:try_resize(screen._width - 2, screen._height - 2) end) it('will hide the top 3 lines', function() screen:expect([[ - rows: 5, cols: 30 | - rows: 3, cols: 30 | - {1: } | - {3:-- TERMINAL --} | + rows: 5, cols: 28 | + rows: 3, cols: 26 | + {2: } | + :^ | ]]) eq(8, curbuf('line_count')) - feed('3k') + feed([[3k]]) screen:expect([[ - ^line4 | - rows: 5, cols: 30 | - rows: 3, cols: 30 | - | + ^line4 | + rows: 5, cols: 28 | + rows: 3, cols: 26 | + | ]]) end) end) -- cgit From 9a6eb71ebaac745198fdc4cec68e51731103c3d9 Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Wed, 16 Aug 2017 01:04:34 +0200 Subject: test/win: give up on this one --- test/functional/terminal/scrollback_spec.lua | 1 + 1 file changed, 1 insertion(+) (limited to 'test') diff --git a/test/functional/terminal/scrollback_spec.lua b/test/functional/terminal/scrollback_spec.lua index acfa92e2f0..af9b414311 100644 --- a/test/functional/terminal/scrollback_spec.lua +++ b/test/functional/terminal/scrollback_spec.lua @@ -139,6 +139,7 @@ describe('terminal scrollback', function() describe('and height decreased by 1', function() + if helpers.pending_win32(pending) then return end local function will_hide_top_line() feed([[:]]) -- Go to cmdline-mode, so cursor is at bottom. screen:try_resize(screen._width - 2, screen._height - 1) -- cgit