From a1493215a2e18f3b0a18a7d77222e0bf93ca32b3 Mon Sep 17 00:00:00 2001 From: ZyX Date: Sun, 28 Feb 2016 04:34:27 +0300 Subject: Revert "Merge pull request #4362 from justinmk/termopen" This reverts commit b01db02de4753908b3595b5ada0a6929e595e930, reversing changes made to 62321e5132ed29b11f79c8a56ca172d56b9ac042. --- src/nvim/main.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/nvim/main.c b/src/nvim/main.c index 09fe29c087..a2aca65001 100644 --- a/src/nvim/main.c +++ b/src/nvim/main.c @@ -324,8 +324,7 @@ int main(int argc, char **argv) "'\\c\\mterm://\\%(.\\{-}//\\%(\\d\\+:\\)\\?\\)\\?\\zs.*'), " // capture the working directory "{'cwd': get(matchlist(expand(\"\"), " - "'\\c\\mterm://\\(.\\{-}\\)//'), 1, '')})" - "|doautocmd TermOpen"); + "'\\c\\mterm://\\(.\\{-}\\)//'), 1, '')})"); /* Execute --cmd arguments. */ exe_pre_commands(¶ms); -- cgit From b32396170f2c1cd17f36b8a5eb1ad313f6f9a8c3 Mon Sep 17 00:00:00 2001 From: ZyX Date: Sun, 28 Feb 2016 04:49:26 +0300 Subject: main: Make using :edit term:// run TermOpen event Ref #4306 --- src/nvim/main.c | 2 +- test/functional/terminal/edit_spec.lua | 23 +++++++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 test/functional/terminal/edit_spec.lua diff --git a/src/nvim/main.c b/src/nvim/main.c index a2aca65001..92e8774ec4 100644 --- a/src/nvim/main.c +++ b/src/nvim/main.c @@ -317,7 +317,7 @@ int main(int argc, char **argv) } // open terminals when opening files that start with term:// - do_cmdline_cmd("autocmd BufReadCmd term://* " + do_cmdline_cmd("autocmd BufReadCmd term://* nested " ":call termopen( " // Capture the command string "matchstr(expand(\"\"), " diff --git a/test/functional/terminal/edit_spec.lua b/test/functional/terminal/edit_spec.lua new file mode 100644 index 0000000000..924f90e8f8 --- /dev/null +++ b/test/functional/terminal/edit_spec.lua @@ -0,0 +1,23 @@ +local helpers = require('test.functional.helpers') + +local nvim_dir = helpers.nvim_dir +local command = helpers.command +local meths = helpers.meths +local clear = helpers.clear +local eq = helpers.eq + +describe(':edit term://*', function() + before_each(function() + clear() + meths.set_option('shell', nvim_dir .. '/shell-test') + end) + + it('runs TermOpen event', function() + meths.set_var('termopen_runs', {}) + command('autocmd TermOpen * :call add(g:termopen_runs, expand(""))') + command('edit term://') + termopen_runs = meths.get_var('termopen_runs') + eq(1, #termopen_runs) + eq(termopen_runs[1], termopen_runs[1]:match('^term://.//%d+:$')) + end) +end) -- cgit From c6eeefa339ee3452866ed5517b6e8a3decc1ec67 Mon Sep 17 00:00:00 2001 From: ZyX Date: Sun, 28 Feb 2016 06:29:38 +0300 Subject: main: Move term:// protocol name to a macros --- src/nvim/main.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/nvim/main.c b/src/nvim/main.c index 92e8774ec4..5b5c8a22aa 100644 --- a/src/nvim/main.c +++ b/src/nvim/main.c @@ -317,14 +317,16 @@ int main(int argc, char **argv) } // open terminals when opening files that start with term:// - do_cmdline_cmd("autocmd BufReadCmd term://* nested " +#define PROTO "term://" + do_cmdline_cmd("autocmd BufReadCmd " PROTO "* nested " ":call termopen( " // Capture the command string "matchstr(expand(\"\"), " - "'\\c\\mterm://\\%(.\\{-}//\\%(\\d\\+:\\)\\?\\)\\?\\zs.*'), " + "'\\c\\m" PROTO "\\%(.\\{-}//\\%(\\d\\+:\\)\\?\\)\\?\\zs.*'), " // capture the working directory "{'cwd': get(matchlist(expand(\"\"), " - "'\\c\\mterm://\\(.\\{-}\\)//'), 1, '')})"); + "'\\c\\m" PROTO "\\(.\\{-}\\)//'), 1, '')})"); +#undef PROTO /* Execute --cmd arguments. */ exe_pre_commands(¶ms); -- cgit From 712f057ed91bd74039836628acd9543fd4d889f6 Mon Sep 17 00:00:00 2001 From: ZyX Date: Sun, 28 Feb 2016 06:54:05 +0300 Subject: functests: Make sure that setting scrollback size works from TermOpen --- test/functional/fixtures/shell-test.c | 66 +++++++++++++++++++++++++--------- test/functional/terminal/edit_spec.lua | 28 +++++++++++++++ 2 files changed, 78 insertions(+), 16 deletions(-) diff --git a/test/functional/fixtures/shell-test.c b/test/functional/fixtures/shell-test.c index 5fa8a58049..d9ec254aff 100644 --- a/test/functional/fixtures/shell-test.c +++ b/test/functional/fixtures/shell-test.c @@ -1,25 +1,59 @@ -// A simple implementation of a shell for testing -// `termopen([&sh, &shcf, '{cmd'}])` and `termopen([&sh])`. -// -// If launched with no arguments, prints "ready $ ", otherwise prints -// "ready $ {cmd}\n". - #include #include +#include + +static void help(void) +{ + puts("A simple implementation of a shell for testing termopen()."); + puts(""); + puts("Usage:"); + puts(" shell-test --help"); + puts(" Prints this help to stdout."); + puts(" shell-test"); + puts(" shell-test EXE"); + puts(" Prints \"ready $ \" to stderr."); + puts(" shell-test EXE \"prog args...\""); + puts(" Prints \"ready $ prog args...\\n\" to stderr."); + puts(" shell-test REP {byte} \"line line line\""); + puts(" Prints \"{lnr}: line line line\\n\" to stdout {byte} times."); + puts(" I.e. for `shell-test REP ab \"test\"'"); + puts(" 0: test"); + puts(" ..."); + puts(" 96: test"); + puts(" will be printed because byte `a' is equal to 97."); +} int main(int argc, char **argv) { - fprintf(stderr, "ready $ "); + if (argc == 2 && strcmp(argv[1], "--help") == 0) { + help(); + } - if (argc == 3) { - // argv should be {"terminal-test", "EXE", "prog args..."} - if (strcmp(argv[1], "EXE") != 0) { - fprintf(stderr, "first argument must be 'EXE'\n"); - return 2; + if (argc >= 2) { + if (strcmp(argv[1], "EXE") == 0) { + fprintf(stderr, "ready $ "); + if (argc >= 3) { + fprintf(stderr, "%s\n", argv[2]); + } + } else if (strcmp(argv[1], "REP") == 0) { + if (argc < 4) { + fprintf(stderr, "Not enough REP arguments\n"); + return 4; + } + uint8_t number = (uint8_t) *argv[2]; + for (uint8_t i = 0; i < number; i++) { + printf("%d: %s\n", (int) i, argv[3]); + } + } else { + fprintf(stderr, "Unknown first argument\n"); + return 3; } - - fprintf(stderr, "%s\n", argv[2]); + return 0; + } else if (argc == 1) { + fprintf(stderr, "ready $ "); + return 0; + } else { + fprintf(stderr, "Missing first argument\n"); + return 2; } - - return 0; } diff --git a/test/functional/terminal/edit_spec.lua b/test/functional/terminal/edit_spec.lua index 924f90e8f8..1062bb4843 100644 --- a/test/functional/terminal/edit_spec.lua +++ b/test/functional/terminal/edit_spec.lua @@ -1,5 +1,8 @@ local helpers = require('test.functional.helpers') +local screen = require('test.functional.ui.screen') +local curbufmeths = helpers.curbufmeths +local curwinmeths = helpers.curwinmeths local nvim_dir = helpers.nvim_dir local command = helpers.command local meths = helpers.meths @@ -10,6 +13,7 @@ describe(':edit term://*', function() before_each(function() clear() meths.set_option('shell', nvim_dir .. '/shell-test') + meths.set_option('shellcmdflag', 'EXE') end) it('runs TermOpen event', function() @@ -20,4 +24,28 @@ describe(':edit term://*', function() eq(1, #termopen_runs) eq(termopen_runs[1], termopen_runs[1]:match('^term://.//%d+:$')) end) + + it('runs TermOpen early enough to respect terminal_scrollback_buffer_size', function() + local rep = 'a' + meths.set_option('shellcmdflag', 'REP ' .. rep) + local rep_size = rep:byte() + local sb = 10 + local gsb = 20 + meths.set_var('terminal_scrollback_buffer_size', gsb) + command('autocmd TermOpen * :let b:terminal_scrollback_buffer_size = ' + .. tostring(sb)) + command('edit term://foobar') + local bufcontents = {} + local winheight = curwinmeths.get_height() + -- I have no idea why there is + 4 needed. But otherwise it works fine with + -- different scrollbacks. + local shift = -4 + for i = (rep_size - 1 - sb - winheight - shift),(rep_size - 1) do + bufcontents[#bufcontents + 1] = ('%d: foobar'):format(i) + end + bufcontents[#bufcontents + 1] = '' + bufcontents[#bufcontents + 1] = '[Process exited 0]' + command('sleep 500m') + eq(bufcontents, curbufmeths.get_line_slice(1, -1, true, true)) + end) end) -- cgit From a16d4a2b62c8727c05dcf72163efccc6dfc2f5a8 Mon Sep 17 00:00:00 2001 From: ZyX Date: Sun, 28 Feb 2016 08:12:55 +0300 Subject: functests: Make test more robust --- test/functional/terminal/edit_spec.lua | 31 ++++++++++++++++++++++++++++--- 1 file changed, 28 insertions(+), 3 deletions(-) diff --git a/test/functional/terminal/edit_spec.lua b/test/functional/terminal/edit_spec.lua index 1062bb4843..3ad1b33970 100644 --- a/test/functional/terminal/edit_spec.lua +++ b/test/functional/terminal/edit_spec.lua @@ -10,6 +10,12 @@ local clear = helpers.clear local eq = helpers.eq describe(':edit term://*', function() + local get_screen = function(columns, lines) + local scr = screen.new(columns, lines) + scr:attach(false) + return scr + end + before_each(function() clear() meths.set_option('shell', nvim_dir .. '/shell-test') @@ -26,6 +32,8 @@ describe(':edit term://*', function() end) it('runs TermOpen early enough to respect terminal_scrollback_buffer_size', function() + local columns, lines = 20, 4 + local scr = get_screen(columns, lines) local rep = 'a' meths.set_option('shellcmdflag', 'REP ' .. rep) local rep_size = rep:byte() @@ -40,12 +48,29 @@ describe(':edit term://*', function() -- I have no idea why there is + 4 needed. But otherwise it works fine with -- different scrollbacks. local shift = -4 - for i = (rep_size - 1 - sb - winheight - shift),(rep_size - 1) do - bufcontents[#bufcontents + 1] = ('%d: foobar'):format(i) + local buf_cont_start = rep_size - 1 - sb - winheight - shift + local bufline = function(i) return ('%d: foobar'):format(i) end + for i = buf_cont_start,(rep_size - 1) do + bufcontents[#bufcontents + 1] = bufline(i) end bufcontents[#bufcontents + 1] = '' bufcontents[#bufcontents + 1] = '[Process exited 0]' - command('sleep 500m') + -- Do not ask me why displayed screen is one line *before* buffer + -- contents: buffer starts with 87:, screen with 86:. + local exp_screen = '\n' + local did_cursor = false + local shift = 10 + for i = 0,(winheight - 1) do + local line = bufline(buf_cont_start + i - 1) + exp_screen = (exp_screen + .. (did_cursor and '' or '^') + .. line + .. (' '):rep(columns - #line) + .. '|\n') + did_cursor = true + end + exp_screen = exp_screen .. (' '):rep(columns) .. '|\n' + scr:expect(exp_screen) eq(bufcontents, curbufmeths.get_line_slice(1, -1, true, true)) end) end) -- cgit From 0409cfded5ca126a734e99657182cb4837f149c9 Mon Sep 17 00:00:00 2001 From: ZyX Date: Sun, 28 Feb 2016 08:15:52 +0300 Subject: functests: Improve screen:expect error reporting --- test/functional/ui/screen.lua | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/test/functional/ui/screen.lua b/test/functional/ui/screen.lua index 80f46326ee..3f857e25f9 100644 --- a/test/functional/ui/screen.lua +++ b/test/functional/ui/screen.lua @@ -219,12 +219,22 @@ function Screen:expect(expected, attr_ids, attr_ignore) local ids = attr_ids or self._default_attr_ids local ignore = attr_ignore or self._default_attr_ignore self:wait(function() + local actual_rows = {} for i = 1, self._height do - local expected_row = expected_rows[i] - local actual_row = self:_row_repr(self._rows[i], ids, ignore) - if expected_row ~= actual_row then - return 'Row '..tostring(i)..' didn\'t match.\nExpected: "'.. - expected_row..'"\nActual: "'..actual_row..'"' + actual_rows[i] = self:_row_repr(self._rows[i], ids, ignore) + end + for i = 1, self._height do + if expected_rows[i] ~= actual_rows[i] then + local msg_expected_rows = {} + for i = 1, #expected_rows do msg_expected_rows[i] = expected_rows[i] end + msg_expected_rows[i] = '*' .. msg_expected_rows[i] + actual_rows[i] = '*' .. actual_rows[i] + msg = ( + 'Row ' .. tostring(i) .. ' didn\'t match.\n' + .. 'Expected:\n|' .. table.concat(msg_expected_rows, '|\n|') .. '|\n' + .. 'Actual:\n|' .. table.concat(actual_rows, '|\n|') .. '|' + ) + return msg end end end) -- cgit