aboutsummaryrefslogtreecommitdiff
path: root/test/functional/terminal
diff options
context:
space:
mode:
Diffstat (limited to 'test/functional/terminal')
-rw-r--r--test/functional/terminal/buffer_spec.lua34
-rw-r--r--test/functional/terminal/cursor_spec.lua38
-rw-r--r--test/functional/terminal/edit_spec.lua5
-rw-r--r--test/functional/terminal/ex_terminal_spec.lua69
-rw-r--r--test/functional/terminal/helpers.lua9
-rw-r--r--test/functional/terminal/highlight_spec.lua23
-rw-r--r--test/functional/terminal/mouse_spec.lua33
-rw-r--r--test/functional/terminal/scrollback_spec.lua136
-rw-r--r--test/functional/terminal/tui_spec.lua461
-rw-r--r--test/functional/terminal/window_spec.lua66
-rw-r--r--test/functional/terminal/window_split_tab_spec.lua106
11 files changed, 694 insertions, 286 deletions
diff --git a/test/functional/terminal/buffer_spec.lua b/test/functional/terminal/buffer_spec.lua
index 129390a7a5..4ce33fef7b 100644
--- a/test/functional/terminal/buffer_spec.lua
+++ b/test/functional/terminal/buffer_spec.lua
@@ -2,18 +2,16 @@ local helpers = require('test.functional.helpers')(after_each)
local thelpers = require('test.functional.terminal.helpers')
local feed, clear, nvim = helpers.feed, helpers.clear, helpers.nvim
local wait = helpers.wait
-local eval, execute, source = helpers.eval, helpers.execute, helpers.source
+local eval, feed_command, source = helpers.eval, helpers.feed_command, helpers.source
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
before_each(function()
clear()
- execute('set modifiable swapfile undolevels=20')
+ feed_command('set modifiable swapfile undolevels=20')
wait()
screen = thelpers.screen_setup()
end)
@@ -86,7 +84,7 @@ describe('terminal buffer', function()
it('sends data to the terminal when the "put" operator is used', function()
feed('<c-\\><c-n>gg"ayj')
- execute('let @a = "appended " . @a')
+ feed_command('let @a = "appended " . @a')
feed('"ap"ap')
screen:expect([[
^tty ready |
@@ -112,8 +110,8 @@ describe('terminal buffer', function()
it('sends data to the terminal when the ":put" command is used', function()
feed('<c-\\><c-n>gg"ayj')
- execute('let @a = "appended " . @a')
- execute('put a')
+ feed_command('let @a = "appended " . @a')
+ feed_command('put a')
screen:expect([[
^tty ready |
appended tty ready |
@@ -124,7 +122,7 @@ describe('terminal buffer', function()
:put a |
]])
-- line argument is only used to move the cursor
- execute('6put a')
+ feed_command('6put a')
screen:expect([[
tty ready |
appended tty ready |
@@ -147,7 +145,7 @@ describe('terminal buffer', function()
{4:~ }|
:bd! |
]])
- execute('bnext')
+ feed_command('bnext')
screen:expect([[
^ |
{4:~ }|
@@ -160,9 +158,10 @@ 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', '==========')
- execute('set laststatus=0')
+ feed_command('set laststatus=0')
-- Save the buffer number of the terminal for later testing.
local tbuf = eval('bufnr("%")')
@@ -191,21 +190,20 @@ describe('terminal buffer', function()
]])
neq(tbuf, eval('bufnr("%")'))
- execute('quit!') -- Should exit the new window, not the terminal.
+ feed_command('quit!') -- Should exit the new window, not the terminal.
eq(tbuf, eval('bufnr("%")'))
- execute('set laststatus=1') -- Restore laststatus to the default.
+ feed_command('set laststatus=1') -- Restore laststatus to the default.
end)
it('term_close() use-after-free #4393', function()
- execute('terminal yes')
+ feed_command('terminal yes')
feed([[<C-\><C-n>]])
- execute('bdelete!')
+ feed_command('bdelete!')
end)
end)
describe('No heap-buffer-overflow when using', function()
-
local testfilename = 'Xtestfile-functional-terminal-buffers_spec'
before_each(function()
@@ -217,12 +215,12 @@ describe('No heap-buffer-overflow when using', function()
end)
it('termopen(echo) #3161', function()
- execute('edit ' .. testfilename)
+ feed_command('edit ' .. testfilename)
-- Move cursor away from the beginning of the line
feed('$')
-- Let termopen() modify the buffer
- execute('call termopen("echo")')
+ feed_command('call termopen("echo")')
wait()
- execute('bdelete!')
+ feed_command('bdelete!')
end)
end)
diff --git a/test/functional/terminal/cursor_spec.lua b/test/functional/terminal/cursor_spec.lua
index d990f92c3a..d942723d02 100644
--- a/test/functional/terminal/cursor_spec.lua
+++ b/test/functional/terminal/cursor_spec.lua
@@ -2,12 +2,11 @@ local helpers = require('test.functional.helpers')(after_each)
local Screen = require('test.functional.ui.screen')
local thelpers = require('test.functional.terminal.helpers')
local feed, clear, nvim = helpers.feed, helpers.clear, helpers.nvim
-local nvim_dir, execute = helpers.nvim_dir, helpers.execute
+local nvim_dir, command = helpers.nvim_dir, helpers.command
+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
@@ -51,8 +50,8 @@ describe('terminal cursor', function()
it('is positioned correctly when unfocused', function()
screen:expect([[
{7: 1 }tty ready |
- {7: 2 }{2:^ } |
- {7: 3 } |
+ {7: 2 }^rows: 6, cols: 46 |
+ {7: 3 }{2: } |
{7: 4 } |
{7: 5 } |
{7: 6 } |
@@ -60,16 +59,26 @@ describe('terminal cursor', function()
]])
end)
- pending('is positioned correctly when focused', function()
+ it('is positioned correctly when focused', function()
+ screen:expect([[
+ {7: 1 }tty ready |
+ {7: 2 }^rows: 6, cols: 46 |
+ {7: 3 }{2: } |
+ {7: 4 } |
+ {7: 5 } |
+ {7: 6 } |
+ :set number |
+ ]])
feed('i')
+ helpers.wait()
screen:expect([[
- 1 tty ready |
- 2 {1: } |
- 3 |
- 4 |
- 5 |
- 6 |
- -- TERMINAL -- |
+ {7: 1 }tty ready |
+ {7: 2 }rows: 6, cols: 46 |
+ {7: 3 }{1: } |
+ {7: 4 } |
+ {7: 5 } |
+ {7: 6 } |
+ {3:-- TERMINAL --} |
]])
end)
end)
@@ -137,7 +146,8 @@ describe('cursor with customized highlighting', function()
[3] = {bold = true},
})
screen:attach({rgb=false})
- execute('call termopen(["'..nvim_dir..'/tty-test"]) | startinsert')
+ command('call termopen(["'..nvim_dir..'/tty-test"])')
+ feed_command('startinsert')
end)
it('overrides the default highlighting', function()
diff --git a/test/functional/terminal/edit_spec.lua b/test/functional/terminal/edit_spec.lua
index 42a5c768bb..d2b2d8a60c 100644
--- a/test/functional/terminal/edit_spec.lua
+++ b/test/functional/terminal/edit_spec.lua
@@ -45,11 +45,8 @@ describe(':edit term://*', function()
local bufcontents = {}
local winheight = curwinmeths.get_height()
local buf_cont_start = rep_size - sb - winheight + 2
- local function bufline (i)
- return ('%d: foobar'):format(i)
- end
for i = buf_cont_start,(rep_size - 1) do
- bufcontents[#bufcontents + 1] = bufline(i)
+ bufcontents[#bufcontents + 1] = ('%d: foobar'):format(i)
end
bufcontents[#bufcontents + 1] = ''
bufcontents[#bufcontents + 1] = '[Process exited 0]'
diff --git a/test/functional/terminal/ex_terminal_spec.lua b/test/functional/terminal/ex_terminal_spec.lua
index 9bb683f25f..e015df10db 100644
--- a/test/functional/terminal/ex_terminal_spec.lua
+++ b/test/functional/terminal/ex_terminal_spec.lua
@@ -2,11 +2,12 @@ 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 execute, eval = helpers.execute, helpers.eval
-
-if helpers.pending_win32(pending) then return end
+local feed_command, eval = helpers.feed_command, helpers.eval
+local retry = helpers.retry
+local iswin = helpers.iswin
describe(':terminal', function()
+ if helpers.pending_win32(pending) then return end
local screen
before_each(function()
@@ -23,11 +24,11 @@ describe(':terminal', function()
echomsg "msg3"
]])
-- Invoke a command that emits frequent terminal activity.
- execute([[terminal while true; do echo X; done]])
+ feed_command([[terminal while true; do echo X; done]])
helpers.feed([[<C-\><C-N>]])
wait()
- helpers.sleep(10) -- Let some terminal activity happen.
- execute("messages")
+ screen:sleep(10) -- Let some terminal activity happen.
+ feed_command("messages")
screen:expect([[
msg1 |
msg2 |
@@ -37,14 +38,14 @@ describe(':terminal', function()
end)
it("in normal-mode :split does not move cursor", function()
- execute([[terminal while true; do echo foo; sleep .1; done]])
+ feed_command([[terminal while true; do echo foo; sleep .1; done]])
helpers.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
- execute('vsplit')
+ feed_command('vsplit')
eq(2, eval("line('.')")) -- cursor stays where we put it
- execute('split')
+ feed_command('split')
eq(2, eval("line('.')")) -- cursor stays where we put it
end)
@@ -65,24 +66,24 @@ describe(':terminal (with fake shell)', function()
-- Invokes `:terminal {cmd}` using a fake shell (shell-test.c) which prints
-- the {cmd} and exits immediately .
local function terminal_with_fake_shell(cmd)
- execute("terminal "..(cmd and cmd or ""))
+ feed_command("terminal "..(cmd and cmd or ""))
end
it('with no argument, acts like termopen()', function()
terminal_with_fake_shell()
- wait()
+ retry(3, 4 * screen.timeout, function()
screen:expect([[
- ready $ |
+ ^ready $ |
[Process exited 0] |
|
- -- TERMINAL -- |
+ :terminal |
]])
+ end)
end)
it("with no argument, and 'shell' is set to empty string", function()
nvim('set_option', 'shell', '')
terminal_with_fake_shell()
- wait()
screen:expect([[
^ |
~ |
@@ -94,46 +95,42 @@ describe(':terminal (with fake shell)', function()
it("with no argument, but 'shell' has arguments, acts like termopen()", function()
nvim('set_option', 'shell', nvim_dir..'/shell-test -t jeff')
terminal_with_fake_shell()
- wait()
screen:expect([[
- jeff $ |
+ ^jeff $ |
[Process exited 0] |
|
- -- TERMINAL -- |
+ :terminal |
]])
end)
it('executes a given command through the shell', function()
terminal_with_fake_shell('echo hi')
- wait()
screen:expect([[
- ready $ echo hi |
+ ^ready $ echo hi |
|
[Process exited 0] |
- -- TERMINAL -- |
+ :terminal echo hi |
]])
end)
it("executes a given command through the shell, when 'shell' has arguments", function()
nvim('set_option', 'shell', nvim_dir..'/shell-test -t jeff')
terminal_with_fake_shell('echo hi')
- wait()
screen:expect([[
- jeff $ echo hi |
+ ^jeff $ echo hi |
|
[Process exited 0] |
- -- TERMINAL -- |
+ :terminal echo hi |
]])
end)
it('allows quotes and slashes', function()
terminal_with_fake_shell([[echo 'hello' \ "world"]])
- wait()
screen:expect([[
- ready $ echo 'hello' \ "world" |
+ ^ready $ echo 'hello' \ "world" |
|
[Process exited 0] |
- -- TERMINAL -- |
+ :terminal echo 'hello' \ "world" |
]])
end)
@@ -157,34 +154,36 @@ describe(':terminal (with fake shell)', function()
end)
it('works with findfile()', function()
- execute('terminal')
+ feed_command('terminal')
eq('term://', string.match(eval('bufname("%")'), "^term://"))
eq('scripts/shadacat.py', eval('findfile("scripts/shadacat.py", ".")'))
end)
it('works with :find', function()
terminal_with_fake_shell()
- wait()
screen:expect([[
- ready $ |
+ ^ready $ |
[Process exited 0] |
|
- -- TERMINAL -- |
+ :terminal |
]])
eq('term://', string.match(eval('bufname("%")'), "^term://"))
helpers.feed([[<C-\><C-N>]])
- execute([[find */shadacat.py]])
- eq('scripts/shadacat.py', eval('bufname("%")'))
+ feed_command([[find */shadacat.py]])
+ if iswin() then
+ eq('scripts\\shadacat.py', eval('bufname("%")'))
+ else
+ eq('scripts/shadacat.py', eval('bufname("%")'))
+ end
end)
it('works with gf', function()
terminal_with_fake_shell([[echo "scripts/shadacat.py"]])
- wait()
screen:expect([[
- ready $ echo "scripts/shadacat.py" |
+ ^ready $ echo "scripts/shadacat.py" |
|
[Process exited 0] |
- -- TERMINAL -- |
+ :terminal echo "scripts/shadacat.py" |
]])
helpers.feed([[<C-\><C-N>]])
eq('term://', string.match(eval('bufname("%")'), "^term://"))
diff --git a/test/functional/terminal/helpers.lua b/test/functional/terminal/helpers.lua
index 934c01e3bf..bd24b9785d 100644
--- a/test/functional/terminal/helpers.lua
+++ b/test/functional/terminal/helpers.lua
@@ -1,7 +1,7 @@
local helpers = require('test.functional.helpers')(nil)
local Screen = require('test.functional.ui.screen')
local nvim_dir = helpers.nvim_dir
-local execute, nvim = helpers.execute, helpers.nvim
+local feed_command, nvim = helpers.feed_command, helpers.nvim
local function feed_data(data)
nvim('set_var', 'term_data', data)
@@ -33,7 +33,6 @@ local function disable_mouse() feed_termcode('[?1002l') 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
@@ -58,15 +57,15 @@ local function screen_setup(extra_rows, command, cols)
screen:attach({rgb=false})
- execute('enew | call termopen('..command..')')
+ feed_command('enew | call termopen('..command..')')
nvim('input', '<CR>')
local vim_errmsg = nvim('eval', 'v:errmsg')
if vim_errmsg and "" ~= vim_errmsg then
error(vim_errmsg)
end
- execute('setlocal scrollback=10')
- execute('startinsert')
+ feed_command('setlocal scrollback=10')
+ feed_command('startinsert')
-- tty-test puts the terminal into raw mode and echoes input. Tests work by
-- feeding termcodes to control the display and asserting by screen:expect.
diff --git a/test/functional/terminal/highlight_spec.lua b/test/functional/terminal/highlight_spec.lua
index 0fe463401e..fddc0bbb71 100644
--- a/test/functional/terminal/highlight_spec.lua
+++ b/test/functional/terminal/highlight_spec.lua
@@ -2,11 +2,9 @@ local helpers = require('test.functional.helpers')(after_each)
local Screen = require('test.functional.ui.screen')
local thelpers = require('test.functional.terminal.helpers')
local feed, clear, nvim = helpers.feed, helpers.clear, helpers.nvim
-local nvim_dir, execute = helpers.nvim_dir, helpers.execute
+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
@@ -27,7 +25,8 @@ describe('terminal window highlighting', function()
[11] = {background = 11},
})
screen:attach({rgb=false})
- execute('enew | call termopen(["'..nvim_dir..'/tty-test"]) | startinsert')
+ command('enew | call termopen(["'..nvim_dir..'/tty-test"])')
+ feed('i')
screen:expect([[
tty ready |
{10: } |
@@ -54,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: } |
@@ -68,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
@@ -130,7 +131,8 @@ describe('terminal window highlighting with custom palette', function()
})
screen:attach({rgb=true})
nvim('set_var', 'terminal_color_3', '#123456')
- execute('enew | call termopen(["'..nvim_dir..'/tty-test"]) | startinsert')
+ command('enew | call termopen(["'..nvim_dir..'/tty-test"])')
+ feed('i')
screen:expect([[
tty ready |
{7: } |
@@ -143,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()
@@ -164,9 +167,9 @@ describe('synIDattr()', function()
before_each(function()
clear()
screen = Screen.new(50, 7)
- execute('highlight Normal ctermfg=252 guifg=#ff0000 guibg=Black')
+ command('highlight Normal ctermfg=252 guifg=#ff0000 guibg=Black')
-- Salmon #fa8072 Maroon #800000
- execute('highlight Keyword ctermfg=79 guifg=Salmon guisp=Maroon')
+ command('highlight Keyword ctermfg=79 guifg=Salmon guisp=Maroon')
end)
it('returns cterm-color if RGB-capable UI is _not_ attached', function()
@@ -213,8 +216,8 @@ describe('fg/bg special colors', function()
before_each(function()
clear()
screen = Screen.new(50, 7)
- execute('highlight Normal ctermfg=145 ctermbg=16 guifg=#ff0000 guibg=Black')
- execute('highlight Visual ctermfg=bg ctermbg=fg guifg=bg guibg=fg guisp=bg')
+ command('highlight Normal ctermfg=145 ctermbg=16 guifg=#ff0000 guibg=Black')
+ command('highlight Visual ctermfg=bg ctermbg=fg guifg=bg guibg=fg guisp=bg')
end)
it('resolve to "Normal" values', function()
@@ -251,7 +254,7 @@ describe('fg/bg special colors', function()
screen:attach({rgb=true})
local new_guibg = '#282c34'
local new_guifg = '#abb2bf'
- execute('highlight Normal guifg='..new_guifg..' guibg='..new_guibg)
+ command('highlight Normal guifg='..new_guifg..' guibg='..new_guibg)
eq(new_guibg, eval('synIDattr(hlID("Visual"), "fg#")'))
eq(new_guifg, eval('synIDattr(hlID("Visual"), "bg#")'))
eq(new_guibg, eval('synIDattr(hlID("Visual"), "sp#")'))
diff --git a/test/functional/terminal/mouse_spec.lua b/test/functional/terminal/mouse_spec.lua
index 9239c2ad31..5e5558ee0a 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('<LeftMouse><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('<ScrollWheelUp><0,0>')
screen:expect([[
line27 |
@@ -94,13 +94,14 @@ 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('<c-\\><c-n>:vsp<cr>')
screen:expect([[
line28 |line28 |
line29 |line29 |
line30 |line30 |
- rows: 5, cols: 25 |rows: 5, cols: 25 |
+ rows: 5, cols: 24 |rows: 5, cols: 24 |
{2:^ } |{2: } |
========== ========== |
:vsp |
@@ -110,7 +111,7 @@ describe('terminal mouse', function()
{7: 1 }^ |line28 |
{4:~ }|line29 |
{4:~ }|line30 |
- {4:~ }|rows: 5, cols: 25 |
+ {4:~ }|rows: 5, cols: 24 |
{4:~ }|{2: } |
========== ========== |
:enew | set number |
@@ -120,16 +121,16 @@ describe('terminal mouse', function()
{7: 27 }line |line28 |
{7: 28 }line |line29 |
{7: 29 }line |line30 |
- {7: 30 }line |rows: 5, cols: 25 |
+ {7: 30 }line |rows: 5, cols: 24 |
{7: 31 }^ |{2: } |
========== ========== |
|
]])
feed('<c-w>li')
screen:expect([[
- {7: 27 }line |line29 |
- {7: 28 }line |line30 |
- {7: 29 }line |rows: 5, cols: 25 |
+ {7: 27 }line |line28 |
+ {7: 28 }line |line29 |
+ {7: 29 }line |line30 |
{7: 30 }line |rows: 5, cols: 24 |
{7: 31 } |{1: } |
========== ========== |
@@ -139,8 +140,8 @@ describe('terminal mouse', function()
thelpers.enable_mouse()
thelpers.feed_data('mouse enabled\n')
screen:expect([[
- {7: 27 }line |line30 |
- {7: 28 }line |rows: 5, cols: 25 |
+ {7: 27 }line |line29 |
+ {7: 28 }line |line30 |
{7: 29 }line |rows: 5, cols: 24 |
{7: 30 }line |mouse enabled |
{7: 31 } |{1: } |
@@ -152,8 +153,8 @@ 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 |line30 |
- {7: 22 }line |rows: 5, cols: 25 |
+ {7: 21 }line |line29 |
+ {7: 22 }line |line30 |
{7: 23 }line |rows: 5, cols: 24 |
{7: 24 }line |mouse enabled |
{7: 25 }line |{1: } |
@@ -162,8 +163,8 @@ describe('terminal mouse', function()
]])
feed('<S-ScrollWheelDown><0,0>')
screen:expect([[
- {7: 26 }line |line30 |
- {7: 27 }line |rows: 5, cols: 25 |
+ {7: 26 }line |line29 |
+ {7: 27 }line |line30 |
{7: 28 }line |rows: 5, cols: 24 |
{7: 29 }line |mouse enabled |
{7: 30 }line |{1: } |
@@ -175,8 +176,8 @@ describe('terminal mouse', function()
it('will lose focus if another window is clicked', function()
feed('<LeftMouse><5,1>')
screen:expect([[
- {7: 27 }line |line30 |
- {7: 28 }l^ine |rows: 5, cols: 25 |
+ {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/scrollback_spec.lua b/test/functional/terminal/scrollback_spec.lua
index 81649f2bde..c665e64a80 100644
--- a/test/functional/terminal/scrollback_spec.lua
+++ b/test/functional/terminal/scrollback_spec.lua
@@ -2,16 +2,16 @@ local Screen = require('test.functional.ui.screen')
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, execute = helpers.feed, helpers.nvim_dir, helpers.execute
+local feed, nvim_dir, feed_command = helpers.feed, helpers.nvim_dir, helpers.feed_command
+local iswin = helpers.iswin
local eval = helpers.eval
local command = helpers.command
local wait = helpers.wait
local retry = helpers.retry
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
@@ -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,18 @@ describe('terminal scrollback', function()
end)
- describe('and the height is decreased by 1', function()
+ describe('and height decreased by 1', function()
+ if helpers.pending_win32(pending) then return end
local function will_hide_top_line()
- screen:try_resize(screen._width, screen._height - 1)
+ feed([[<C-\><C-N>:]]) -- 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 +158,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('<c-\\><c-n>3k')
+ feed([[<C-\><C-N>3k]])
screen:expect([[
- ^line4 |
- rows: 5, cols: 30 |
- rows: 3, cols: 30 |
- |
+ ^line4 |
+ rows: 5, cols: 28 |
+ rows: 3, cols: 26 |
+ |
]])
end)
end)
@@ -180,6 +182,11 @@ describe('terminal scrollback', function()
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()
before_each(function()
screen:try_resize(screen._width, screen._height - 2)
@@ -254,6 +261,10 @@ describe('terminal scrollback', function()
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([[
@@ -338,7 +349,7 @@ describe('terminal prints more lines than the screen height and exits', function
clear()
local screen = Screen.new(30, 7)
screen:attach({rgb=false})
- execute('call termopen(["'..nvim_dir..'/tty-test", "10"]) | startinsert')
+ feed_command('call termopen(["'..nvim_dir..'/tty-test", "10"]) | startinsert')
wait()
screen:expect([[
line6 |
@@ -368,6 +379,12 @@ describe("'scrollback' option", function()
clear()
end)
+ local function set_fake_shell()
+ -- shell-test.c is a fake shell that prints its arguments and exits.
+ nvim('set_option', 'shell', nvim_dir..'/shell-test')
+ nvim('set_option', 'shellcmdflag', 'EXE')
+ end
+
local function expect_lines(expected, epsilon)
local ep = epsilon and epsilon or 0
local actual = eval("line('$')")
@@ -377,10 +394,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)
@@ -388,7 +415,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)
@@ -396,7 +429,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)
@@ -409,7 +446,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)
@@ -421,12 +462,13 @@ describe("'scrollback' option", function()
screen:detach()
end)
- it('defaults to 1000', function()
- execute('terminal')
- eq(1000, curbufmeths.get_option('scrollback'))
+ it('defaults to 10000 in terminal buffers', function()
+ set_fake_shell()
+ command('terminal')
+ eq(10000, curbufmeths.get_option('scrollback'))
end)
- it('error if set to invalid values', function()
+ it('error if set to invalid value', function()
local status, rv = pcall(command, 'set scrollback=-2')
eq(false, status) -- assert failure
eq('E474:', string.match(rv, "E%d*:"))
@@ -437,15 +479,39 @@ describe("'scrollback' option", function()
end)
it('defaults to -1 on normal buffers', function()
- execute('new')
+ command('new')
eq(-1, curbufmeths.get_option('scrollback'))
end)
- it('error if set on a normal buffer', function()
+ it(':setlocal in a normal buffer is an error', function()
command('new')
- execute('set scrollback=42')
+
+ -- :setlocal to -1 is NOT an error.
+ feed_command('setlocal scrollback=-1')
+ eq(nil, string.match(eval("v:errmsg"), "E%d*:"))
+ feed('<CR>')
+
+ -- :setlocal to anything except -1 is an error.
+ feed_command('setlocal scrollback=42')
feed('<CR>')
eq('E474:', string.match(eval("v:errmsg"), "E%d*:"))
+ eq(-1, curbufmeths.get_option('scrollback'))
+ end)
+
+ it(':set updates local value and global default', function()
+ set_fake_shell()
+ command('set scrollback=42') -- set global and (attempt) local
+ eq(-1, curbufmeths.get_option('scrollback')) -- normal buffer: -1
+ command('terminal')
+ eq(42, curbufmeths.get_option('scrollback')) -- inherits global default
+ command('setlocal scrollback=99')
+ eq(99, curbufmeths.get_option('scrollback'))
+ command('set scrollback<') -- reset to global default
+ eq(42, curbufmeths.get_option('scrollback'))
+ command('setglobal scrollback=734') -- new global default
+ eq(42, curbufmeths.get_option('scrollback')) -- local value did not change
+ command('terminal')
+ eq(734, curbufmeths.get_option('scrollback'))
end)
end)
diff --git a/test/functional/terminal/tui_spec.lua b/test/functional/terminal/tui_spec.lua
index 0e5c437c28..d5f6a21d1d 100644
--- a/test/functional/terminal/tui_spec.lua
+++ b/test/functional/terminal/tui_spec.lua
@@ -1,10 +1,16 @@
--- Some sanity checks for the TUI using the builtin terminal emulator
--- as a simple way to send keys and assert screen state.
+-- TUI acceptance tests.
+-- Uses :terminal as a way to send keys and assert screen state.
+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 = thelpers.feed_data
-local execute = helpers.execute
+local feed_data = thelpers.feed_data
+local feed_command = helpers.feed_command
+local clear = helpers.clear
local nvim_dir = helpers.nvim_dir
+local retry = helpers.retry
+local nvim_prog = helpers.nvim_prog
+local nvim_set = helpers.nvim_set
if helpers.pending_win32(pending) then return end
@@ -12,9 +18,9 @@ describe('tui', function()
local screen
before_each(function()
- helpers.clear()
- screen = thelpers.screen_setup(0, '["'..helpers.nvim_prog
- ..'", "-u", "NONE", "-i", "NONE", "--cmd", "set noswapfile noshowcmd noruler"]')
+ 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
@@ -34,7 +40,7 @@ describe('tui', function()
end)
it('accepts basic utf-8 input', function()
- feed('iabc\ntest1\ntest2')
+ feed_data('iabc\ntest1\ntest2')
screen:expect([[
abc |
test1 |
@@ -44,7 +50,7 @@ describe('tui', function()
{3:-- INSERT --} |
{3:-- TERMINAL --} |
]])
- feed('\027')
+ feed_data('\027')
screen:expect([[
abc |
test1 |
@@ -59,8 +65,8 @@ describe('tui', function()
it('interprets leading <Esc> byte as ALT modifier in normal-mode', function()
local keys = 'dfghjkl'
for c in keys:gmatch('.') do
- execute('nnoremap <a-'..c..'> ialt-'..c..'<cr><esc>')
- feed('\027'..c)
+ feed_command('nnoremap <a-'..c..'> ialt-'..c..'<cr><esc>')
+ feed_data('\027'..c)
end
screen:expect([[
alt-j |
@@ -71,7 +77,7 @@ describe('tui', function()
|
{3:-- TERMINAL --} |
]])
- feed('gg')
+ feed_data('gg')
screen:expect([[
{1:a}lt-d |
alt-f |
@@ -90,7 +96,7 @@ describe('tui', function()
-- Example: for input ALT+j:
-- * Vim (Nvim prior to #3982) sets high-bit, inserts "ê".
-- * Nvim (after #3982) inserts "j".
- feed('i\027j')
+ feed_data('i\027j')
screen:expect([[
j{1: } |
{4:~ }|
@@ -103,10 +109,10 @@ describe('tui', function()
end)
it('accepts ascii control sequences', function()
- feed('i')
- feed('\022\007') -- ctrl+g
- feed('\022\022') -- ctrl+v
- feed('\022\013') -- ctrl+m
+ feed_data('i')
+ feed_data('\022\007') -- ctrl+g
+ feed_data('\022\022') -- ctrl+v
+ feed_data('\022\013') -- ctrl+m
screen:expect([[
{9:^G^V^M}{1: } |
{4:~ }|
@@ -119,7 +125,7 @@ describe('tui', function()
end)
it('automatically sends <Paste> for bracketed paste sequences', function()
- feed('i\027[200~')
+ feed_data('i\027[200~')
screen:expect([[
{1: } |
{4:~ }|
@@ -129,7 +135,7 @@ describe('tui', function()
{3:-- INSERT (paste) --} |
{3:-- TERMINAL --} |
]])
- feed('pasted from terminal')
+ feed_data('pasted from terminal')
screen:expect([[
pasted from terminal{1: } |
{4:~ }|
@@ -139,7 +145,7 @@ describe('tui', function()
{3:-- INSERT (paste) --} |
{3:-- TERMINAL --} |
]])
- feed('\027[201~')
+ feed_data('\027[201~')
screen:expect([[
pasted from terminal{1: } |
{4:~ }|
@@ -152,12 +158,12 @@ describe('tui', function()
end)
it('can handle arbitrarily long bursts of input', function()
- execute('set ruler')
+ feed_command('set ruler')
local t = {}
for i = 1, 3000 do
t[i] = 'item ' .. tostring(i)
end
- feed('i\027[200~'..table.concat(t, '\n')..'\027[201~')
+ feed_data('i\027[200~'..table.concat(t, '\n')..'\027[201~')
screen:expect([[
item 2997 |
item 2998 |
@@ -180,7 +186,7 @@ describe('tui with non-tty file descriptors', function()
it('can handle pipes as stdout and stderr', function()
local screen = thelpers.screen_setup(0, '"'..helpers.nvim_prog
..' -u NONE -i NONE --cmd \'set noswapfile noshowcmd noruler\' --cmd \'normal iabc\' > /dev/null 2>&1 && cat testF && rm testF"')
- feed(':w testF\n:q\n')
+ feed_data(':w testF\n:q\n')
screen:expect([[
:w testF |
:q |
@@ -193,19 +199,21 @@ describe('tui with non-tty file descriptors', function()
end)
end)
-describe('tui focus event handling', function()
+describe('tui FocusGained/FocusLost', function()
local screen
before_each(function()
helpers.clear()
screen = thelpers.screen_setup(0, '["'..helpers.nvim_prog
..'", "-u", "NONE", "-i", "NONE", "--cmd", "set noswapfile noshowcmd noruler"]')
- execute('autocmd FocusGained * echo "gained"')
- execute('autocmd FocusLost * echo "lost"')
+ feed_data(":autocmd FocusGained * echo 'gained'\n")
+ feed_data(":autocmd FocusLost * echo 'lost'\n")
+ feed_data("\034\016") -- CTRL-\ CTRL-N
end)
- it('can handle focus events in normal mode', function()
- feed('\027[I')
+ it('in normal-mode', function()
+ retry(2, 3 * screen.timeout, function()
+ feed_data('\027[I')
screen:expect([[
{1: } |
{4:~ }|
@@ -216,7 +224,7 @@ describe('tui focus event handling', function()
{3:-- TERMINAL --} |
]])
- feed('\027[O')
+ feed_data('\027[O')
screen:expect([[
{1: } |
{4:~ }|
@@ -226,12 +234,14 @@ describe('tui focus event handling', function()
lost |
{3:-- TERMINAL --} |
]])
+ end)
end)
- it('can handle focus events in insert mode', function()
- execute('set noshowmode')
- feed('i')
- feed('\027[I')
+ it('in insert-mode', function()
+ feed_command('set noshowmode')
+ feed_data('i')
+ retry(2, 3 * screen.timeout, function()
+ feed_data('\027[I')
screen:expect([[
{1: } |
{4:~ }|
@@ -241,7 +251,7 @@ describe('tui focus event handling', function()
gained |
{3:-- TERMINAL --} |
]])
- feed('\027[O')
+ feed_data('\027[O')
screen:expect([[
{1: } |
{4:~ }|
@@ -251,55 +261,112 @@ describe('tui focus event handling', function()
lost |
{3:-- TERMINAL --} |
]])
+ end)
end)
- it('can handle focus events in cmdline mode', function()
- feed(':')
- feed('\027[I')
+ -- During cmdline-mode we ignore :echo invoked by timers/events.
+ -- See commit: 5cc87d4dabd02167117be7a978b5c8faaa975419.
+ it('in cmdline-mode does NOT :echo', function()
+ feed_data(':')
+ feed_data('\027[I')
screen:expect([[
|
{4:~ }|
{4:~ }|
{4:~ }|
{5:[No Name] }|
- g{1:a}ined |
+ :{1: } |
{3:-- TERMINAL --} |
]])
- feed('\027[O')
+ feed_data('\027[O')
screen:expect([[
|
{4:~ }|
{4:~ }|
{4:~ }|
{5:[No Name] }|
- l{1:o}st |
+ :{1: } |
{3:-- TERMINAL --} |
]])
end)
- it('can handle focus events in terminal mode', function()
- execute('set shell='..nvim_dir..'/shell-test')
- execute('set laststatus=0')
- execute('set noshowmode')
- execute('terminal')
- feed('\027[I')
- screen:expect([[
- ready $ |
- [Process exited 0]{1: } |
- |
- |
- |
- gained |
- {3:-- TERMINAL --} |
- ]])
- feed('\027[O')
+ it('in cmdline-mode', function()
+ -- Set up autocmds that modify the buffer, instead of just calling :echo.
+ -- This is how we can test handling of focus gained/lost during cmdline-mode.
+ -- See commit: 5cc87d4dabd02167117be7a978b5c8faaa975419.
+ feed_data(":autocmd!\n")
+ feed_data(":autocmd FocusLost * call append(line('$'), 'lost')\n")
+ feed_data(":autocmd FocusGained * call append(line('$'), 'gained')\n")
+ retry(2, 3 * screen.timeout, function()
+ -- Enter cmdline-mode.
+ feed_data(':')
+ screen:sleep(1)
+ -- Send focus lost/gained termcodes.
+ feed_data('\027[O')
+ feed_data('\027[I')
+ screen:sleep(1)
+ -- Exit cmdline-mode. Redraws from timers/events are blocked during
+ -- cmdline-mode, so the buffer won't be updated until we exit cmdline-mode.
+ feed_data('\n')
+ screen:expect([[
+ {1: } |
+ lost |
+ gained |
+ {4:~ }|
+ {5:[No Name] [+] }|
+ : |
+ {3:-- TERMINAL --} |
+ ]])
+ end)
+ end)
+
+ it('in terminal-mode', function()
+ feed_data(':set shell='..nvim_dir..'/shell-test\n')
+ feed_data(':set noshowmode laststatus=0\n')
+
+ retry(2, 3 * screen.timeout, function()
+ feed_data(':terminal\n')
+ screen:sleep(1)
+ feed_data('\027[I')
+ screen:expect([[
+ {1:r}eady $ |
+ [Process exited 0] |
+ |
+ |
+ |
+ gained |
+ {3:-- TERMINAL --} |
+ ]])
+ feed_data('\027[O')
+ screen:expect([[
+ {1:r}eady $ |
+ [Process exited 0] |
+ |
+ |
+ |
+ lost |
+ {3:-- TERMINAL --} |
+ ]])
+
+ -- If retry is needed...
+ feed_data("\034\016") -- CTRL-\ CTRL-N
+ feed_data(':bwipeout!\n')
+ end)
+ end)
+
+ it('in press-enter prompt', function()
+ feed_data(":echom 'msg1'|echom 'msg2'|echom 'msg3'|echom 'msg4'|echom 'msg5'\n")
+ -- Execute :messages to provoke the press-enter prompt.
+ feed_data(":messages\n")
+ feed_data('\027[I')
+ feed_data('\027[I')
screen:expect([[
- ready $ |
- [Process exited 0]{1: } |
- |
- |
- |
- lost |
+ msg1 |
+ msg2 |
+ msg3 |
+ msg4 |
+ msg5 |
+ {10:Press ENTER or type command to continue}{1: } |
{3:-- TERMINAL --} |
]])
end)
@@ -309,21 +376,23 @@ end)
-- does not initialize the TUI.
describe("tui 't_Co' (terminal colors)", function()
local screen
- local is_linux = (helpers.eval("system('uname') =~? 'linux'") == 1)
+ local is_freebsd = (string.lower(uname()) == 'freebsd')
local function assert_term_colors(term, colorterm, maxcolors)
helpers.clear({env={TERM=term}, args={}})
-- This is ugly because :term/termopen() forces TERM=xterm-256color.
-- TODO: Revisit this after jobstart/termopen accept `env` dict.
screen = thelpers.screen_setup(0, string.format(
- [=[['sh', '-c', 'LANG=C TERM=%s %s %s -u NONE -i NONE --cmd "silent set noswapfile noshowcmd noruler"']]=],
- term,
+ [=[['sh', '-c', 'LANG=C TERM=%s %s %s -u NONE -i NONE --cmd "%s"']]=],
+ term or "",
(colorterm ~= nil and "COLORTERM="..colorterm or ""),
- helpers.nvim_prog))
+ nvim_prog,
+ nvim_set))
- thelpers.feed_data(":echo &t_Co\n")
+ feed_data(":echo &t_Co\n")
+ helpers.wait()
local tline
- if maxcolors == 8 then
+ if maxcolors == 8 or maxcolors == 16 then
tline = "~ "
else
tline = "{4:~ }"
@@ -333,33 +402,85 @@ describe("tui 't_Co' (terminal colors)", function()
%s|
%s|
%s|
- {5:[No Name] }|
+ %s|
%-3s |
{3:-- TERMINAL --} |
- ]], tline, tline, tline, tostring(maxcolors and maxcolors or "")))
+ ]], tline, tline, tline, tline, tostring(maxcolors and maxcolors or "")))
end
- it("unknown TERM sets empty 't_Co'", function()
- assert_term_colors("yet-another-term", nil, nil)
+ -- ansi and no terminal type at all:
+
+ it("no TERM uses 8 colors", function()
+ assert_term_colors(nil, nil, 8)
+ end)
+
+ it("TERM=ansi no COLORTERM uses 8 colors", function()
+ assert_term_colors("ansi", nil, 8)
+ end)
+
+ it("TERM=ansi with COLORTERM=anything-no-number uses 16 colors", function()
+ assert_term_colors("ansi", "yet-another-term", 16)
+ end)
+
+ it("unknown TERM COLORTERM with 256 in name uses 256 colors", function()
+ assert_term_colors("ansi", "yet-another-term-256color", 256)
+ end)
+
+ it("TERM=ansi-256color sets 256 colours", function()
+ assert_term_colors("ansi-256color", nil, 256)
+ end)
+
+ -- Unknown terminal types:
+
+ it("unknown TERM no COLORTERM sets 8 colours", function()
+ assert_term_colors("yet-another-term", nil, 8)
+ end)
+
+ it("unknown TERM with COLORTERM=anything-no-number uses 16 colors", function()
+ assert_term_colors("yet-another-term", "yet-another-term", 16)
+ end)
+
+ it("unknown TERM with 256 in name sets 256 colours", function()
+ assert_term_colors("yet-another-term-256color", nil, 256)
end)
- it("unknown TERM with COLORTERM=screen-256color uses 256 colors", function()
- assert_term_colors("yet-another-term", "screen-256color", 256)
+ it("unknown TERM COLORTERM with 256 in name uses 256 colors", function()
+ assert_term_colors("yet-another-term", "yet-another-term-256color", 256)
end)
- it("TERM=linux uses 8 colors", function()
- if is_linux then
- assert_term_colors("linux", nil, 8)
+ -- Linux kernel terminal emulator:
+
+ it("TERM=linux uses 256 colors", function()
+ assert_term_colors("linux", nil, 256)
+ end)
+
+ it("TERM=linux-16color uses 256 colors", function()
+ assert_term_colors("linux-16color", nil, 256)
+ end)
+
+ it("TERM=linux-256color uses 256 colors", function()
+ assert_term_colors("linux-256color", nil, 256)
+ end)
+
+ -- screen:
+ --
+ -- FreeBSD falls back to the built-in screen-256colour entry.
+ -- Linux and MacOS have a screen entry in external terminfo with 8 colours,
+ -- which is raised to 16 by COLORTERM.
+
+ it("TERM=screen no COLORTERM uses 8/256 colors", function()
+ if is_freebsd then
+ assert_term_colors("screen", nil, 256)
else
- pending()
+ assert_term_colors("screen", nil, 8)
end
end)
- it("TERM=screen uses 8 colors", function()
- if is_linux then
- assert_term_colors("screen", nil, 8)
+ it("TERM=screen COLORTERM=screen uses 16/256 colors", function()
+ if is_freebsd then
+ assert_term_colors("screen", "screen", 256)
else
- pending()
+ assert_term_colors("screen", "screen", 16)
end
end)
@@ -367,15 +488,187 @@ describe("tui 't_Co' (terminal colors)", function()
assert_term_colors("screen", "screen-256color", 256)
end)
- it("TERM=yet-another-term COLORTERM=screen-256color uses 256 colors", function()
- assert_term_colors("screen", "screen-256color", 256)
+ it("TERM=screen-256color no COLORTERM uses 256 colors", function()
+ assert_term_colors("screen-256color", nil, 256)
+ end)
+
+ -- tmux:
+ --
+ -- FreeBSD and MacOS fall back to the built-in tmux-256colour entry.
+ -- Linux has a tmux entry in external terminfo with 8 colours,
+ -- which is raised to 256.
+
+ it("TERM=tmux no COLORTERM uses 256 colors", function()
+ assert_term_colors("tmux", nil, 256)
+ end)
+
+ it("TERM=tmux COLORTERM=tmux uses 256 colors", function()
+ assert_term_colors("tmux", "tmux", 256)
end)
+ it("TERM=tmux COLORTERM=tmux-256color uses 256 colors", function()
+ assert_term_colors("tmux", "tmux-256color", 256)
+ end)
+
+ it("TERM=tmux-256color no COLORTERM uses 256 colors", function()
+ assert_term_colors("tmux-256color", nil, 256)
+ end)
+
+ -- xterm and imitators:
+
it("TERM=xterm uses 256 colors", function()
assert_term_colors("xterm", nil, 256)
end)
+ it("TERM=xterm COLORTERM=gnome-terminal uses 256 colors", function()
+ assert_term_colors("xterm", "gnome-terminal", 256)
+ end)
+
+ it("TERM=xterm COLORTERM=mate-terminal uses 256 colors", function()
+ assert_term_colors("xterm", "mate-terminal", 256)
+ end)
+
it("TERM=xterm-256color uses 256 colors", function()
assert_term_colors("xterm-256color", nil, 256)
end)
+
+ -- rxvt and stterm:
+ --
+ -- FreeBSD and MacOS fall back to the built-in rxvt-256color and
+ -- st-256colour entries.
+ -- Linux has an rxvt, an st, and an st-16color entry in external terminfo
+ -- with 8, 8, and 16 colours respectively, which are raised to 256.
+
+ it("TERM=rxvt no COLORTERM uses 256 colors", function()
+ assert_term_colors("rxvt", nil, 256)
+ end)
+
+ it("TERM=rxvt COLORTERM=rxvt uses 256 colors", function()
+ assert_term_colors("rxvt", "rxvt", 256)
+ end)
+
+ it("TERM=rxvt-256color uses 256 colors", function()
+ assert_term_colors("rxvt-256color", nil, 256)
+ end)
+
+ it("TERM=st no COLORTERM uses 256 colors", function()
+ assert_term_colors("st", nil, 256)
+ end)
+
+ it("TERM=st COLORTERM=st uses 256 colors", function()
+ assert_term_colors("st", "st", 256)
+ end)
+
+ it("TERM=st COLORTERM=st-256color uses 256 colors", function()
+ assert_term_colors("st", "st-256color", 256)
+ end)
+
+ it("TERM=st-16color no COLORTERM uses 8/256 colors", function()
+ assert_term_colors("st", nil, 256)
+ end)
+
+ it("TERM=st-16color COLORTERM=st uses 16/256 colors", function()
+ assert_term_colors("st", "st", 256)
+ end)
+
+ it("TERM=st-16color COLORTERM=st-256color uses 256 colors", function()
+ assert_term_colors("st", "st-256color", 256)
+ end)
+
+ it("TERM=st-256color uses 256 colors", function()
+ assert_term_colors("st-256color", nil, 256)
+ end)
+
+ -- gnome and vte:
+ --
+ -- FreeBSD and MacOS fall back to the built-in vte-256color entry.
+ -- Linux has a gnome, a vte, a gnome-256color, and a vte-256color entry in
+ -- external terminfo with 8, 8, 256, and 256 colours respectively, which are
+ -- raised to 256.
+
+ it("TERM=gnome no COLORTERM uses 256 colors", function()
+ assert_term_colors("gnome", nil, 256)
+ end)
+
+ it("TERM=gnome COLORTERM=gnome uses 256 colors", function()
+ assert_term_colors("gnome", "gnome", 256)
+ end)
+
+ it("TERM=gnome COLORTERM=gnome-256color uses 256 colors", function()
+ assert_term_colors("gnome", "gnome-256color", 256)
+ end)
+
+ it("TERM=gnome-256color uses 256 colors", function()
+ assert_term_colors("gnome-256color", nil, 256)
+ end)
+
+ it("TERM=vte no COLORTERM uses 256 colors", function()
+ assert_term_colors("vte", nil, 256)
+ end)
+
+ it("TERM=vte COLORTERM=vte uses 256 colors", function()
+ assert_term_colors("vte", "vte", 256)
+ end)
+
+ it("TERM=vte COLORTERM=vte-256color uses 256 colors", function()
+ assert_term_colors("vte", "vte-256color", 256)
+ end)
+
+ it("TERM=vte-256color uses 256 colors", function()
+ assert_term_colors("vte-256color", nil, 256)
+ end)
+
+ -- others:
+
+ it("TERM=interix uses 8 colors", function()
+ assert_term_colors("interix", nil, 8)
+ end)
+
+ it("TERM=iTerm.app uses 256 colors", function()
+ assert_term_colors("iTerm.app", nil, 256)
+ end)
+
+ it("TERM=iterm uses 256 colors", function()
+ assert_term_colors("iterm", nil, 256)
+ end)
+
+end)
+
+-- These tests require `thelpers` because --headless/--embed
+-- does not initialize the TUI.
+describe("tui 'term' option", function()
+ local screen
+ local is_bsd = not not string.find(string.lower(uname()), 'bsd')
+
+ local function assert_term(term_envvar, term_expected)
+ 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 TERM=%s %s -u NONE -i NONE --cmd "%s"']]=],
+ term_envvar or "",
+ nvim_prog,
+ nvim_set)
+ screen = thelpers.screen_setup(0, cmd)
+
+ local full_timeout = screen.timeout
+ screen.timeout = 250 -- We want screen:expect() to fail quickly.
+ retry(nil, 2 * full_timeout, function() -- Wait for TUI thread to set 'term'.
+ feed_data(":echo 'term='.(&term)\n")
+ screen:expect('term='..term_expected, nil, nil, nil, true)
+ end)
+ end
+
+ it('gets builtin term if $TERM is invalid', function()
+ assert_term("foo", "builtin_ansi")
+ end)
+
+ it('gets system-provided term if $TERM is valid', function()
+ if is_bsd then -- BSD lacks terminfo, we always use builtin there.
+ assert_term("xterm", "builtin_xterm")
+ else
+ assert_term("xterm", "xterm")
+ end
+ end)
+
end)
diff --git a/test/functional/terminal/window_spec.lua b/test/functional/terminal/window_spec.lua
index 888b1e1328..842a81872e 100644
--- a/test/functional/terminal/window_spec.lua
+++ b/test/functional/terminal/window_spec.lua
@@ -2,8 +2,7 @@ local helpers = require('test.functional.helpers')(after_each)
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
+local iswin = helpers.iswin
describe('terminal window', function()
local screen
@@ -13,9 +12,62 @@ describe('terminal window', function()
screen = thelpers.screen_setup()
end)
- describe('with colorcolumn set', function()
+ describe("with 'number'", function()
+ it('wraps text', function()
+ feed([[<C-\><C-N>]])
+ feed([[:set numberwidth=1 number<CR>i]])
+ screen:expect([[
+ {7:1 }tty ready |
+ {7:2 }rows: 6, cols: 48 |
+ {7:3 }{1: } |
+ {7:4 } |
+ {7:5 } |
+ {7:6 } |
+ {3:-- TERMINAL --} |
+ ]])
+ thelpers.feed_data({'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'})
+ screen:expect([[
+ {7:1 }tty ready |
+ {7:2 }rows: 6, cols: 48 |
+ {7:3 }abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUV|
+ {7:4 }WXYZ{1: } |
+ {7:5 } |
+ {7:6 } |
+ {3:-- TERMINAL --} |
+ ]])
+
+ if iswin() then
+ return -- win: :terminal resize is unreliable #7007
+ end
+
+ -- numberwidth=9
+ feed([[<C-\><C-N>]])
+ feed([[:set numberwidth=9 number<CR>i]])
+ screen:expect([[
+ {7: 1 }tty ready |
+ {7: 2 }rows: 6, cols: 48 |
+ {7: 3 }abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNO|
+ {7: 4 }WXYZrows: 6, cols: 41 |
+ {7: 5 }{1: } |
+ {7: 6 } |
+ {3:-- TERMINAL --} |
+ ]])
+ thelpers.feed_data({' abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'})
+ screen:expect([[
+ {7: 1 }tty ready |
+ {7: 2 }rows: 6, cols: 48 |
+ {7: 3 }abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNO|
+ {7: 4 }WXYZrows: 6, cols: 41 |
+ {7: 5 } abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMN|
+ {7: 6 }OPQRSTUVWXYZ{1: } |
+ {3:-- TERMINAL --} |
+ ]])
+ end)
+ end)
+
+ describe("with 'colorcolumn'", function()
before_each(function()
- feed('<c-\\><c-n>')
+ feed([[<C-\><C-N>]])
screen:expect([[
tty ready |
{2:^ } |
@@ -25,7 +77,7 @@ describe('terminal window', function()
|
|
]])
- feed(':set colorcolumn=20<cr>i')
+ feed(':set colorcolumn=20<CR>i')
end)
it('wont show the color column', function()
@@ -43,7 +95,7 @@ describe('terminal window', function()
describe('with fold set', function()
before_each(function()
- feed('<c-\\><c-n>:set foldenable foldmethod=manual<cr>i')
+ feed([[<C-\><C-N>:set foldenable foldmethod=manual<CR>i]])
thelpers.feed_data({'line1', 'line2', 'line3', 'line4', ''})
screen:expect([[
tty ready |
@@ -57,7 +109,7 @@ describe('terminal window', function()
end)
it('wont show any folds', function()
- feed('<c-\\><c-n>ggvGzf')
+ feed([[<C-\><C-N>ggvGzf]])
wait()
screen:expect([[
^tty ready |
diff --git a/test/functional/terminal/window_split_tab_spec.lua b/test/functional/terminal/window_split_tab_spec.lua
index d3386a641e..714c2476ce 100644
--- a/test/functional/terminal/window_split_tab_spec.lua
+++ b/test/functional/terminal/window_split_tab_spec.lua
@@ -2,9 +2,10 @@ local helpers = require('test.functional.helpers')(after_each)
local thelpers = require('test.functional.terminal.helpers')
local clear = helpers.clear
local feed, nvim = helpers.feed, helpers.nvim
-local execute = helpers.execute
-
-if helpers.pending_win32(pending) then return end
+local feed_command = helpers.feed_command
+local command = helpers.command
+local eq = helpers.eq
+local eval = helpers.eval
describe('terminal', function()
local screen
@@ -24,77 +25,66 @@ describe('terminal', function()
screen:detach()
end)
- it('resets its size when entering terminal window', function()
+ it('next to a closing window', function()
+ command('split')
+ command('terminal')
+ command('vsplit foo')
+ eq(3, eval("winnr('$')"))
+ feed('ZQ') -- Close split, should not crash. #7538
+ eq(2, eval("1+1")) -- Still alive?
+ end)
+
+ it('does not change size on WinEnter', function()
+ if helpers.pending_win32(pending) then return end
feed('<c-\\><c-n>')
- execute('2split')
- screen:expect([[
- rows: 2, cols: 50 |
- {2:^ } |
- ========== |
- rows: 2, cols: 50 |
- {2: } |
- {4:~ }|
- {4:~ }|
- {4:~ }|
- ========== |
- :2split |
- ]])
- execute('wincmd p')
+ feed_command('2split')
screen:expect([[
tty ready |
- rows: 2, cols: 50 |
+ ^rows: 5, cols: 50 |
========== |
tty ready |
- rows: 2, cols: 50 |
rows: 5, cols: 50 |
{2: } |
- ^ |
+ |
+ |
========== |
- :wincmd p |
+ :2split |
]])
- execute('wincmd p')
+ feed_command('wincmd p')
screen:expect([[
- rows: 2, cols: 50 |
- {2:^ } |
+ tty ready |
+ rows: 5, cols: 50 |
========== |
- rows: 2, cols: 50 |
+ tty ready |
+ ^rows: 5, cols: 50 |
{2: } |
- {4:~ }|
- {4:~ }|
- {4:~ }|
+ |
+ |
========== |
:wincmd p |
]])
end)
- 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)
- screen:expect([[
- tty ready |
- rows: 14, cols: 53 |
- {1: } |
- |
- |
- |
- |
- |
- |
- |
- |
- |
- |
- |
- {3:-- TERMINAL --} |
- ]])
- screen:try_resize(screen._width - 6, screen._height - 10)
- screen:expect([[
- tty ready |
- rows: 14, cols: 53 |
- rows: 4, cols: 47 |
- {1: } |
- {3:-- TERMINAL --} |
- ]])
- end)
+ it('forwards resize request to the program', function()
+ feed([[<C-\><C-N>:]]) -- Go to cmdline-mode, so cursor is at bottom.
+ screen:try_resize(screen._width - 3, screen._height - 2)
+ screen:expect([[
+ tty ready |
+ rows: 7, cols: 47 |
+ {2: } |
+ |
+ |
+ |
+ |
+ :^ |
+ ]])
+ screen:try_resize(screen._width - 6, screen._height - 3)
+ screen:expect([[
+ tty ready |
+ rows: 7, cols: 47 |
+ rows: 4, cols: 41 |
+ {2: } |
+ :^ |
+ ]])
end)
end)