aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/functional/fixtures/tty-test.c79
-rw-r--r--test/functional/terminal/buffer_spec.lua4
-rw-r--r--test/functional/terminal/cursor_spec.lua2
-rw-r--r--test/functional/terminal/ex_terminal_spec.lua11
-rw-r--r--test/functional/terminal/helpers.lua1
-rw-r--r--test/functional/terminal/highlight_spec.lua5
-rw-r--r--test/functional/terminal/mouse_spec.lua5
-rw-r--r--test/functional/terminal/scrollback_spec.lua86
-rw-r--r--test/functional/terminal/window_spec.lua2
-rw-r--r--test/functional/terminal/window_split_tab_spec.lua41
10 files changed, 137 insertions, 99 deletions
diff --git a/test/functional/fixtures/tty-test.c b/test/functional/fixtures/tty-test.c
index 7ba21d652a..edcbe23f86 100644
--- a/test/functional/fixtures/tty-test.c
+++ b/test/functional/fixtures/tty-test.c
@@ -5,42 +5,45 @@
#include <stdio.h>
#include <stdlib.h>
#include <uv.h>
+#ifdef _WIN32
+# include <windows.h>
+#else
+# include <unistd.h>
+#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
uv_tty_t tty;
+uv_tty_t tty_out;
-#ifdef _WIN32
-#include <windows.h>
bool owns_tty(void)
{
- HWND consoleWnd = GetConsoleWindow();
- DWORD dwProcessId;
- GetWindowThreadProcessId(consoleWnd, &dwProcessId);
- return GetCurrentProcessId() == dwProcessId;
-}
+#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 <unistd.h>
-bool owns_tty(void)
-{
return getsid(0) == getpid();
-}
#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);
}
}
-#ifndef WIN32
static void sig_handler(int signum)
{
- switch(signum) {
+ switch (signum) {
case SIGWINCH: {
int width, height;
uv_tty_get_winsize(&tty, &width, &height);
@@ -54,15 +57,15 @@ static void sig_handler(int signum)
return;
}
}
-#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);
-// }
+#ifdef WIN32
+static void sigwinch_cb(uv_signal_t *handle, int signum)
+{
+ int width, height;
+ uv_tty_get_winsize(&tty_out, &width, &height);
+ fprintf(stderr, "rows: %d, cols: %d\n", height, width);
+}
+#endif
static void alloc_cb(uv_handle_t *handle, size_t suggested, uv_buf_t *buf)
{
@@ -80,7 +83,7 @@ static void read_cb(uv_stream_t *stream, ssize_t cnt, const uv_buf_t *buf)
int *interrupted = stream->data;
for (int i = 0; i < cnt; i++) {
- if (buf->base[i] == 3) {
+ if (buf->base[i] == CTRL_C) {
(*interrupted)++;
}
}
@@ -88,11 +91,13 @@ 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);
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)) {
@@ -137,7 +142,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);
@@ -148,8 +153,14 @@ 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_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;
uv_read_start(STRUCT_CAST(uv_stream_t, &tty), alloc_cb, read_cb);
@@ -160,15 +171,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..4ce33fef7b 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
@@ -160,6 +158,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 +204,6 @@ describe('terminal buffer', function()
end)
describe('No heap-buffer-overflow when using', function()
-
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..9930efc402 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,12 +174,15 @@ describe(':terminal (with fake shell)', function()
eq('term://', string.match(eval('bufname("%")'), "^term://"))
helpers.feed([[<C-\><C-N>]])
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()
terminal_with_fake_shell([[echo "scripts/shadacat.py"]])
- wait()
screen:expect([[
ready $ echo "scripts/shadacat.py" |
|
diff --git a/test/functional/terminal/helpers.lua b/test/functional/terminal/helpers.lua
index 3b04d17705..bd24b9785d 100644
--- a/test/functional/terminal/helpers.lua
+++ b/test/functional/terminal/helpers.lua
@@ -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
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('<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,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('<c-\\><c-n>:vsp<cr>')
screen:expect([[
diff --git a/test/functional/terminal/scrollback_spec.lua b/test/functional/terminal/scrollback_spec.lua
index 05f81295c2..af9b414311 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 = helpers.iswin
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
@@ -58,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([[
@@ -139,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
@@ -157,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)
@@ -181,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)
@@ -255,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([[
@@ -384,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)
@@ -395,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)
@@ -403,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)
@@ -416,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)
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
diff --git a/test/functional/terminal/window_split_tab_spec.lua b/test/functional/terminal/window_split_tab_spec.lua
index 4867e0d9fa..c5199f620e 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('<c-\\><c-n>')
feed_command('2split')
screen:expect([[
@@ -69,31 +68,25 @@ 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)
+ 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: 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)