tests: shell-test: add INTERACT mode (#10405)

Use it to improve ls_spec: it should not use the user's real shell for
performance and other reasons.
This commit is contained in:
Daniel Hahler 2019-07-03 22:49:13 +02:00 committed by GitHub
parent 0dc73b87f1
commit f6298aba82
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 30 additions and 1 deletions

View File

@ -4,6 +4,8 @@ local command = helpers.command
local eq = helpers.eq
local eval = helpers.eval
local feed = helpers.feed
local nvim = helpers.nvim
local nvim_dir = helpers.nvim_dir
local retry = helpers.retry
describe(':ls', function()
@ -12,6 +14,8 @@ describe(':ls', function()
end)
it('R, F for :terminal buffers', function()
nvim('set_option', 'shell', string.format('"%s" INTERACT', nvim_dir..'/shell-test'))
command('edit foo')
command('set hidden')
command('terminal')

View File

@ -40,6 +40,8 @@ static void help(void)
puts(" ...");
puts(" 96: test");
puts(" will be printed because byte `a' is equal to 97.");
puts(" shell-test INTERACT");
puts(" Prints \"interact $ \" to stderr, and waits for \"exit\" input.");
}
int main(int argc, char **argv)
@ -89,8 +91,31 @@ int main(int argc, char **argv)
printf("3: \xc3\xa5\xcc"); wait();
printf("\xb2\n"); wait();
} else if (strcmp(argv[1], "INTERACT") == 0) {
char input[256];
char cmd[100];
int arg;
int input_argc;
while (1) {
fprintf(stderr, "interact $ ");
if (fgets(input, sizeof(input), stdin) == NULL) {
break; // EOF
}
input_argc = sscanf(input, "%s %d", cmd, &arg);
if(1 == input_argc) {
arg = 0;
}
if (strcmp(cmd, "exit") == 0) {
return arg;
} else {
fprintf(stderr, "Unknown first argument\n");
fprintf(stderr, "command not found: %s\n", cmd);
}
}
} else {
fprintf(stderr, "Unknown first argument: %s\n", argv[1]);
return 3;
}
return 0;