aboutsummaryrefslogtreecommitdiff
path: root/test/functional/terminal
diff options
context:
space:
mode:
authorb-r-o-c-k <brockmammen@gmail.com>2018-04-14 14:17:51 -0500
committerb-r-o-c-k <brockmammen@gmail.com>2018-04-14 14:17:51 -0500
commitad999eaa775d7d4b0cacedb30c6ea3a0ee699a6f (patch)
tree92de2079e80f5f289dd87a54af123cb7d90c3058 /test/functional/terminal
parent78bc52ea5397c092d01cd08296fe1dc85d998329 (diff)
parentef4feab0e75be19c5f41d70a001db980b72090f5 (diff)
downloadrneovim-ad999eaa775d7d4b0cacedb30c6ea3a0ee699a6f.tar.gz
rneovim-ad999eaa775d7d4b0cacedb30c6ea3a0ee699a6f.tar.bz2
rneovim-ad999eaa775d7d4b0cacedb30c6ea3a0ee699a6f.zip
Merge branch 'master' into s-dash-stdin
Diffstat (limited to 'test/functional/terminal')
-rw-r--r--test/functional/terminal/edit_spec.lua1
-rw-r--r--test/functional/terminal/ex_terminal_spec.lua66
-rw-r--r--test/functional/terminal/mouse_spec.lua80
-rw-r--r--test/functional/terminal/tui_spec.lua161
4 files changed, 242 insertions, 66 deletions
diff --git a/test/functional/terminal/edit_spec.lua b/test/functional/terminal/edit_spec.lua
index d2b2d8a60c..84d7ae6e9c 100644
--- a/test/functional/terminal/edit_spec.lua
+++ b/test/functional/terminal/edit_spec.lua
@@ -36,6 +36,7 @@ describe(':edit term://*', function()
local scr = get_screen(columns, lines)
local rep = 'a'
meths.set_option('shellcmdflag', 'REP ' .. rep)
+ command('set shellxquote=') -- win: avoid extra quotes
local rep_size = rep:byte() -- 'a' => 97
local sb = 10
command('autocmd TermOpen * :setlocal scrollback='..tostring(sb)
diff --git a/test/functional/terminal/ex_terminal_spec.lua b/test/functional/terminal/ex_terminal_spec.lua
index e015df10db..4f22f7385d 100644
--- a/test/functional/terminal/ex_terminal_spec.lua
+++ b/test/functional/terminal/ex_terminal_spec.lua
@@ -2,12 +2,15 @@ local helpers = require('test.functional.helpers')(after_each)
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 = helpers.feed
local feed_command, eval = helpers.feed_command, helpers.eval
+local funcs = helpers.funcs
local retry = helpers.retry
+local ok = helpers.ok
local iswin = helpers.iswin
+local command = helpers.command
describe(':terminal', function()
- if helpers.pending_win32(pending) then return end
local screen
before_each(function()
@@ -24,10 +27,17 @@ describe(':terminal', function()
echomsg "msg3"
]])
-- Invoke a command that emits frequent terminal activity.
- feed_command([[terminal while true; do echo X; done]])
- helpers.feed([[<C-\><C-N>]])
+ if iswin() then
+ feed_command([[terminal for /L \%I in (1,0,2) do echo \%I]])
+ else
+ feed_command([[terminal while true; do echo X; done]])
+ end
+ feed([[<C-\><C-N>]])
wait()
- screen:sleep(10) -- Let some terminal activity happen.
+ -- Wait for some terminal activity.
+ retry(nil, 4000, function()
+ ok(funcs.line('$') > 6)
+ end)
feed_command("messages")
screen:expect([[
msg1 |
@@ -38,8 +48,12 @@ describe(':terminal', function()
end)
it("in normal-mode :split does not move cursor", function()
- feed_command([[terminal while true; do echo foo; sleep .1; done]])
- helpers.feed([[<C-\><C-N>M]]) -- move cursor away from last line
+ if iswin() then
+ feed_command([[terminal for /L \\%I in (1,0,2) do ( echo foo & ping -w 100 -n 1 127.0.0.1 > nul )]])
+ else
+ feed_command([[terminal while true; do echo foo; sleep .1; done]])
+ end
+ feed([[<C-\><C-N>M]]) -- move cursor away from last line
wait()
eq(3, eval("line('$')")) -- window height
eq(2, eval("line('.')")) -- cursor is in the middle
@@ -49,6 +63,32 @@ describe(':terminal', function()
eq(2, eval("line('.')")) -- cursor stays where we put it
end)
+ it('Enter/Leave does not increment jumplist #3723', function()
+ feed_command('terminal')
+ local function enter_and_leave()
+ local lines_before = funcs.line('$')
+ -- Create a new line (in the shell). For a normal buffer this
+ -- increments the jumplist; for a terminal-buffer it should not. #3723
+ feed('i')
+ wait()
+ feed('<CR><CR><CR><CR>')
+ wait()
+ feed([[<C-\><C-N>]])
+ wait()
+ -- Wait for >=1 lines to be created.
+ retry(nil, 4000, function()
+ ok(funcs.line('$') > lines_before)
+ end)
+ end
+ enter_and_leave()
+ enter_and_leave()
+ enter_and_leave()
+ ok(funcs.line('$') > 6) -- Verify assumption.
+ local jumps = funcs.split(funcs.execute('jumps'), '\n')
+ eq(' jump line col file/text', jumps[1])
+ eq(3, #jumps)
+ end)
+
end)
describe(':terminal (with fake shell)', function()
@@ -104,6 +144,7 @@ describe(':terminal (with fake shell)', function()
end)
it('executes a given command through the shell', function()
+ command('set shellxquote=') -- win: avoid extra quotes
terminal_with_fake_shell('echo hi')
screen:expect([[
^ready $ echo hi |
@@ -115,6 +156,7 @@ describe(':terminal (with fake shell)', function()
it("executes a given command through the shell, when 'shell' has arguments", function()
nvim('set_option', 'shell', nvim_dir..'/shell-test -t jeff')
+ command('set shellxquote=') -- win: avoid extra quotes
terminal_with_fake_shell('echo hi')
screen:expect([[
^jeff $ echo hi |
@@ -125,6 +167,7 @@ describe(':terminal (with fake shell)', function()
end)
it('allows quotes and slashes', function()
+ command('set shellxquote=') -- win: avoid extra quotes
terminal_with_fake_shell([[echo 'hello' \ "world"]])
screen:expect([[
^ready $ echo 'hello' \ "world" |
@@ -144,12 +187,12 @@ describe(':terminal (with fake shell)', function()
it('ignores writes if the backing stream closes', function()
terminal_with_fake_shell()
- helpers.feed('iiXXXXXXX')
+ feed('iiXXXXXXX')
wait()
-- Race: Though the shell exited (and streams were closed by SIGCHLD
-- handler), :terminal cleanup is pending on the main-loop.
-- This write should be ignored (not crash, #5445).
- helpers.feed('iiYYYYYYY')
+ feed('iiYYYYYYY')
eq(2, eval("1+1")) -- Still alive?
end)
@@ -168,7 +211,7 @@ describe(':terminal (with fake shell)', function()
:terminal |
]])
eq('term://', string.match(eval('bufname("%")'), "^term://"))
- helpers.feed([[<C-\><C-N>]])
+ feed([[<C-\><C-N>]])
feed_command([[find */shadacat.py]])
if iswin() then
eq('scripts\\shadacat.py', eval('bufname("%")'))
@@ -178,6 +221,7 @@ describe(':terminal (with fake shell)', function()
end)
it('works with gf', function()
+ command('set shellxquote=') -- win: avoid extra quotes
terminal_with_fake_shell([[echo "scripts/shadacat.py"]])
screen:expect([[
^ready $ echo "scripts/shadacat.py" |
@@ -185,9 +229,9 @@ describe(':terminal (with fake shell)', function()
[Process exited 0] |
:terminal echo "scripts/shadacat.py" |
]])
- helpers.feed([[<C-\><C-N>]])
+ feed([[<C-\><C-N>]])
eq('term://', string.match(eval('bufname("%")'), "^term://"))
- helpers.feed([[ggf"lgf]])
+ feed([[ggf"lgf]])
eq('scripts/shadacat.py', eval('bufname("%")'))
end)
diff --git a/test/functional/terminal/mouse_spec.lua b/test/functional/terminal/mouse_spec.lua
index 5e5558ee0a..a21d9f0a56 100644
--- a/test/functional/terminal/mouse_spec.lua
+++ b/test/functional/terminal/mouse_spec.lua
@@ -98,41 +98,41 @@ describe('terminal mouse', function()
before_each(function()
feed('<c-\\><c-n>:vsp<cr>')
screen:expect([[
- line28 |line28 |
- line29 |line29 |
- line30 |line30 |
- rows: 5, cols: 24 |rows: 5, cols: 24 |
- {2:^ } |{2: } |
+ line28 │line28 |
+ line29 │line29 |
+ line30 │line30 |
+ rows: 5, cols: 24 │rows: 5, cols: 24 |
+ {2:^ } │{2: } |
========== ========== |
:vsp |
]])
feed(':enew | set number<cr>')
screen:expect([[
- {7: 1 }^ |line28 |
- {4:~ }|line29 |
- {4:~ }|line30 |
- {4:~ }|rows: 5, cols: 24 |
- {4:~ }|{2: } |
+ {7: 1 }^ │line28 |
+ {4:~ }│line29 |
+ {4:~ }│line30 |
+ {4:~ }│rows: 5, cols: 24 |
+ {4:~ }│{2: } |
========== ========== |
:enew | set number |
]])
feed('30iline\n<esc>')
screen:expect([[
- {7: 27 }line |line28 |
- {7: 28 }line |line29 |
- {7: 29 }line |line30 |
- {7: 30 }line |rows: 5, cols: 24 |
- {7: 31 }^ |{2: } |
+ {7: 27 }line │line28 |
+ {7: 28 }line │line29 |
+ {7: 29 }line │line30 |
+ {7: 30 }line │rows: 5, cols: 24 |
+ {7: 31 }^ │{2: } |
========== ========== |
|
]])
feed('<c-w>li')
screen:expect([[
- {7: 27 }line |line28 |
- {7: 28 }line |line29 |
- {7: 29 }line |line30 |
- {7: 30 }line |rows: 5, cols: 24 |
- {7: 31 } |{1: } |
+ {7: 27 }line │line28 |
+ {7: 28 }line │line29 |
+ {7: 29 }line │line30 |
+ {7: 30 }line │rows: 5, cols: 24 |
+ {7: 31 } │{1: } |
========== ========== |
{3:-- TERMINAL --} |
]])
@@ -140,11 +140,11 @@ describe('terminal mouse', function()
thelpers.enable_mouse()
thelpers.feed_data('mouse enabled\n')
screen:expect([[
- {7: 27 }line |line29 |
- {7: 28 }line |line30 |
- {7: 29 }line |rows: 5, cols: 24 |
- {7: 30 }line |mouse enabled |
- {7: 31 } |{1: } |
+ {7: 27 }line │line29 |
+ {7: 28 }line │line30 |
+ {7: 29 }line │rows: 5, cols: 24 |
+ {7: 30 }line │mouse enabled |
+ {7: 31 } │{1: } |
========== ========== |
{3:-- TERMINAL --} |
]])
@@ -153,21 +153,21 @@ describe('terminal mouse', function()
it('wont lose focus if another window is scrolled', function()
feed('<ScrollWheelUp><0,0><ScrollWheelUp><0,0>')
screen:expect([[
- {7: 21 }line |line29 |
- {7: 22 }line |line30 |
- {7: 23 }line |rows: 5, cols: 24 |
- {7: 24 }line |mouse enabled |
- {7: 25 }line |{1: } |
+ {7: 21 }line │line29 |
+ {7: 22 }line │line30 |
+ {7: 23 }line │rows: 5, cols: 24 |
+ {7: 24 }line │mouse enabled |
+ {7: 25 }line │{1: } |
========== ========== |
{3:-- TERMINAL --} |
]])
feed('<S-ScrollWheelDown><0,0>')
screen:expect([[
- {7: 26 }line |line29 |
- {7: 27 }line |line30 |
- {7: 28 }line |rows: 5, cols: 24 |
- {7: 29 }line |mouse enabled |
- {7: 30 }line |{1: } |
+ {7: 26 }line │line29 |
+ {7: 27 }line │line30 |
+ {7: 28 }line │rows: 5, cols: 24 |
+ {7: 29 }line │mouse enabled |
+ {7: 30 }line │{1: } |
========== ========== |
{3:-- TERMINAL --} |
]])
@@ -176,11 +176,11 @@ describe('terminal mouse', function()
it('will lose focus if another window is clicked', function()
feed('<LeftMouse><5,1>')
screen:expect([[
- {7: 27 }line |line29 |
- {7: 28 }l^ine |line30 |
- {7: 29 }line |rows: 5, cols: 24 |
- {7: 30 }line |mouse enabled |
- {7: 31 } |{2: } |
+ {7: 27 }line │line29 |
+ {7: 28 }l^ine │line30 |
+ {7: 29 }line │rows: 5, cols: 24 |
+ {7: 30 }line │mouse enabled |
+ {7: 31 } │{2: } |
========== ========== |
|
]])
diff --git a/test/functional/terminal/tui_spec.lua b/test/functional/terminal/tui_spec.lua
index d5f6a21d1d..2f9abfd3f6 100644
--- a/test/functional/terminal/tui_spec.lua
+++ b/test/functional/terminal/tui_spec.lua
@@ -4,13 +4,20 @@ local global_helpers = require('test.helpers')
local uname = global_helpers.uname
local helpers = require('test.functional.helpers')(after_each)
local thelpers = require('test.functional.terminal.helpers')
-local feed_data = thelpers.feed_data
+local Screen = require('test.functional.ui.screen')
+local eq = helpers.eq
local feed_command = helpers.feed_command
+local feed_data = thelpers.feed_data
local clear = helpers.clear
+local command = helpers.command
+local eval = helpers.eval
local nvim_dir = helpers.nvim_dir
local retry = helpers.retry
local nvim_prog = helpers.nvim_prog
local nvim_set = helpers.nvim_set
+local ok = helpers.ok
+local read_file = helpers.read_file
+local wait = helpers.wait
if helpers.pending_win32(pending) then return end
@@ -21,9 +28,6 @@ describe('tui', function()
clear()
screen = thelpers.screen_setup(0, '["'..nvim_prog
..'", "-u", "NONE", "-i", "NONE", "--cmd", "set noswapfile noshowcmd noruler undodir=. directory=. viewdir=. backupdir=."]')
- -- right now pasting can be really slow in the TUI, especially in ASAN.
- -- this will be fixed later but for now we require a high timeout.
- screen.timeout = 60000
screen:expect([[
{1: } |
{4:~ }|
@@ -39,6 +43,28 @@ describe('tui', function()
screen:detach()
end)
+ it('rapid resize #7572 #7628', function()
+ -- Need buffer rows to provoke the behavior.
+ feed_data(":edit test/functional/fixtures/bigfile.txt:")
+ command('call jobresize(b:terminal_job_id, 58, 9)')
+ command('call jobresize(b:terminal_job_id, 62, 13)')
+ command('call jobresize(b:terminal_job_id, 100, 42)')
+ command('call jobresize(b:terminal_job_id, 37, 1000)')
+ -- Resize to <5 columns.
+ screen:try_resize(4, 44)
+ command('call jobresize(b:terminal_job_id, 4, 1000)')
+ -- Resize to 1 row, then to 1 column, then increase rows to 4.
+ screen:try_resize(44, 1)
+ command('call jobresize(b:terminal_job_id, 44, 1)')
+ screen:try_resize(1, 1)
+ command('call jobresize(b:terminal_job_id, 1, 1)')
+ screen:try_resize(1, 4)
+ command('call jobresize(b:terminal_job_id, 1, 4)')
+ screen:try_resize(57, 17)
+ command('call jobresize(b:terminal_job_id, 57, 17)')
+ eq(2, eval("1+1")) -- Still alive?
+ end)
+
it('accepts basic utf-8 input', function()
feed_data('iabc\ntest1\ntest2')
screen:expect([[
@@ -89,16 +115,12 @@ describe('tui', function()
]])
end)
- it('does not mangle unmapped ALT-key chord', function()
- -- Vim represents ALT/META by setting the "high bit" of the modified key;
- -- we do _not_. #3982
- --
- -- Example: for input ALT+j:
- -- * Vim (Nvim prior to #3982) sets high-bit, inserts "ê".
- -- * Nvim (after #3982) inserts "j".
- feed_data('i\027j')
+ it('interprets ESC+key as ALT chord', function()
+ -- Vim represents ALT/META by setting the "high bit" of the modified key:
+ -- ALT+j inserts "ê". Nvim does not (#3982).
+ feed_data('i\022\027j')
screen:expect([[
- j{1: } |
+ <M-j>{1: } |
{4:~ }|
{4:~ }|
{4:~ }|
@@ -125,6 +147,9 @@ describe('tui', function()
end)
it('automatically sends <Paste> for bracketed paste sequences', function()
+ -- Pasting can be really slow in the TUI, specially in ASAN.
+ -- This will be fixed later but for now we require a high timeout.
+ screen.timeout = 60000
feed_data('i\027[200~')
screen:expect([[
{1: } |
@@ -158,6 +183,8 @@ describe('tui', function()
end)
it('can handle arbitrarily long bursts of input', function()
+ -- Need extra time for this test, specially in ASAN.
+ screen.timeout = 60000
feed_command('set ruler')
local t = {}
for i = 1, 3000 do
@@ -174,6 +201,58 @@ describe('tui', function()
{3:-- TERMINAL --} |
]])
end)
+
+ it('allows termguicolors to be set at runtime', function()
+ screen:set_option('rgb', true)
+ screen:set_default_attr_ids({
+ [1] = {reverse = true},
+ [2] = {foreground = 13, special = Screen.colors.Grey0},
+ [3] = {special = Screen.colors.Grey0, bold = true, reverse = true},
+ [4] = {bold = true},
+ [5] = {special = Screen.colors.Grey0, reverse = true, foreground = 4},
+ [6] = {foreground = 4, special = Screen.colors.Grey0},
+ [7] = {special = Screen.colors.Grey0, reverse = true, foreground = Screen.colors.SeaGreen4},
+ [8] = {foreground = Screen.colors.SeaGreen4, special = Screen.colors.Grey0},
+ [9] = {special = Screen.colors.Grey0, bold = true, foreground = Screen.colors.Blue1},
+ })
+
+ feed_data(':hi SpecialKey ctermfg=3 guifg=SeaGreen\n')
+ feed_data('i')
+ feed_data('\022\007') -- ctrl+g
+ feed_data('\028\014') -- crtl+\ ctrl+N
+ feed_data(':set termguicolors?\n')
+ screen:expect([[
+ {5:^}{6:G} |
+ {2:~ }|
+ {2:~ }|
+ {2:~ }|
+ {3:[No Name] [+] }|
+ notermguicolors |
+ {4:-- TERMINAL --} |
+ ]])
+
+ feed_data(':set termguicolors\n')
+ screen:expect([[
+ {7:^}{8:G} |
+ {9:~ }|
+ {9:~ }|
+ {9:~ }|
+ {3:[No Name] [+] }|
+ :set termguicolors |
+ {4:-- TERMINAL --} |
+ ]])
+
+ feed_data(':set notermguicolors\n')
+ screen:expect([[
+ {5:^}{6:G} |
+ {2:~ }|
+ {2:~ }|
+ {2:~ }|
+ {3:[No Name] [+] }|
+ :set notermguicolors |
+ {4:-- TERMINAL --} |
+ ]])
+ end)
end)
describe('tui with non-tty file descriptors', function()
@@ -390,7 +469,7 @@ describe("tui 't_Co' (terminal colors)", function()
nvim_set))
feed_data(":echo &t_Co\n")
- helpers.wait()
+ wait()
local tline
if maxcolors == 8 or maxcolors == 16 then
tline = "~ "
@@ -639,6 +718,7 @@ end)
describe("tui 'term' option", function()
local screen
local is_bsd = not not string.find(string.lower(uname()), 'bsd')
+ local is_macos = not not string.find(string.lower(uname()), 'darwin')
local function assert_term(term_envvar, term_expected)
clear()
@@ -664,11 +744,62 @@ describe("tui 'term' option", function()
end)
it('gets system-provided term if $TERM is valid', function()
- if is_bsd then -- BSD lacks terminfo, we always use builtin there.
+ if is_bsd then -- BSD lacks terminfo, builtin is always used.
assert_term("xterm", "builtin_xterm")
+ elseif is_macos then
+ local status, _ = pcall(assert_term, "xterm", "xterm")
+ if not status then
+ pending("macOS: unibilium could not find terminfo", function() end)
+ end
else
assert_term("xterm", "xterm")
end
end)
end)
+
+-- These tests require `thelpers` because --headless/--embed
+-- does not initialize the TUI.
+describe("tui", function()
+ local screen
+ local logfile = 'Xtest_tui_verbose_log'
+ after_each(function()
+ os.remove(logfile)
+ end)
+
+ -- Runs (child) `nvim` in a TTY (:terminal), to start the builtin TUI.
+ local function nvim_tui(extra_args)
+ clear()
+ -- This is ugly because :term/termopen() forces TERM=xterm-256color.
+ -- TODO: Revisit this after jobstart/termopen accept `env` dict.
+ local cmd = string.format(
+ [=[['sh', '-c', 'LANG=C %s -u NONE -i NONE %s --cmd "%s"']]=],
+ nvim_prog,
+ extra_args or "",
+ nvim_set)
+ screen = thelpers.screen_setup(0, cmd)
+ end
+
+ it('-V3log logs terminfo values', function()
+ nvim_tui('-V3'..logfile)
+
+ -- Wait for TUI to start.
+ feed_data('Gitext')
+ screen:expect([[
+ text{1: } |
+ {4:~ }|
+ {4:~ }|
+ {4:~ }|
+ {4:~ }|
+ {3:-- INSERT --} |
+ {3:-- TERMINAL --} |
+ ]])
+
+ retry(nil, 3000, function() -- Wait for log file to be flushed.
+ local log = read_file('Xtest_tui_verbose_log') or ''
+ eq('--- Terminal info --- {{{\n', string.match(log, '--- Terminal.-\n'))
+ ok(#log > 50)
+ end)
+ end)
+
+end)