aboutsummaryrefslogtreecommitdiff
path: root/test/functional/terminal/helpers.lua
diff options
context:
space:
mode:
authorThiago de Arruda <tpadilha84@gmail.com>2015-10-01 15:03:40 -0300
committerThiago de Arruda <tpadilha84@gmail.com>2015-10-01 15:22:49 -0300
commit5d185c77726dfff20b87d97897d2bb237e95d95a (patch)
tree40873cf933b5ba5cff44d1ea07db2b3f2663020e /test/functional/terminal/helpers.lua
parent2182cd6081af283d3f08c434d00cc634b492033e (diff)
downloadrneovim-5d185c77726dfff20b87d97897d2bb237e95d95a.tar.gz
rneovim-5d185c77726dfff20b87d97897d2bb237e95d95a.tar.bz2
rneovim-5d185c77726dfff20b87d97897d2bb237e95d95a.zip
test: Add basic tests for the TUI
The tests use `termopen` to spawn nvim and verify the TUI.
Diffstat (limited to 'test/functional/terminal/helpers.lua')
-rw-r--r--test/functional/terminal/helpers.lua46
1 files changed, 26 insertions, 20 deletions
diff --git a/test/functional/terminal/helpers.lua b/test/functional/terminal/helpers.lua
index e488495139..ae13aab277 100644
--- a/test/functional/terminal/helpers.lua
+++ b/test/functional/terminal/helpers.lua
@@ -1,7 +1,7 @@
local helpers = require('test.functional.helpers')
local Screen = require('test.functional.ui.screen')
local nvim_dir = helpers.nvim_dir
-local execute, nvim = helpers.execute, helpers.nvim
+local execute, nvim, wait = helpers.execute, helpers.nvim, helpers.wait
local function feed_data(data)
nvim('set_var', 'term_data', data)
@@ -31,13 +31,15 @@ local function clear_attrs() feed_termcode('[0;10m') end
local function enable_mouse() feed_termcode('[?1002h') end
local function disable_mouse() feed_termcode('[?1002l') end
+local default_command = '["'..nvim_dir..'/tty-test'..'"]'
-local function screen_setup(extra_height)
+local function screen_setup(extra_height, command)
nvim('command', 'highlight TermCursor cterm=reverse')
nvim('command', 'highlight TermCursorNC ctermbg=11')
nvim('set_var', 'terminal_scrollback_buffer_size', 10)
if not extra_height then extra_height = 0 end
+ if not command then command = default_command end
local screen = Screen.new(50, 7 + extra_height)
screen:set_default_attr_ids({
[1] = {reverse = true}, -- focused cursor
@@ -56,25 +58,29 @@ local function screen_setup(extra_height)
-- tty-test puts the terminal into raw mode and echoes all input. tests are
-- done by feeding it with terminfo codes to control the display and
-- verifying output with screen:expect.
- execute('enew | call termopen(["'..nvim_dir..'/tty-test"]) | startinsert')
- -- wait for "tty ready" to be printed before each test or the terminal may
- -- still be in canonical mode(will echo characters for example)
- --
- local empty_line = ' '
- local expected = {
- 'tty ready ',
- '{1: } ',
- empty_line,
- empty_line,
- empty_line,
- empty_line,
- }
- for i = 1, extra_height do
- table.insert(expected, empty_line)
- end
+ execute('enew | call termopen('..command..') | startinsert')
+ if command == default_command then
+ -- wait for "tty ready" to be printed before each test or the terminal may
+ -- still be in canonical mode(will echo characters for example)
+ --
+ local empty_line = ' '
+ local expected = {
+ 'tty ready ',
+ '{1: } ',
+ empty_line,
+ empty_line,
+ empty_line,
+ empty_line,
+ }
+ for i = 1, extra_height do
+ table.insert(expected, empty_line)
+ end
- table.insert(expected, '-- TERMINAL -- ')
- screen:expect(table.concat(expected, '\n'))
+ table.insert(expected, '-- TERMINAL -- ')
+ screen:expect(table.concat(expected, '\n'))
+ else
+ wait()
+ end
return screen
end