aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--test/functional/fixtures/shell-test.c66
-rw-r--r--test/functional/terminal/edit_spec.lua28
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 <stdio.h>
#include <string.h>
+#include <stdint.h>
+
+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)