diff options
author | Gregory Anders <greg@gpanders.com> | 2021-08-20 11:45:28 -0600 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-08-20 10:45:28 -0700 |
commit | 50b30de2007961718cc11811a30f6b0f35c3c793 (patch) | |
tree | 5bef15d7394ec3ccef0ced4c7e93d68bb11fa015 /test | |
parent | 599af74514d0d7083c0565005f255e59ecd7e2ad (diff) | |
download | rneovim-50b30de2007961718cc11811a30f6b0f35c3c793.tar.gz rneovim-50b30de2007961718cc11811a30f6b0f35c3c793.tar.bz2 rneovim-50b30de2007961718cc11811a30f6b0f35c3c793.zip |
feat(terminal): TermClose: set exit code in v:event.status #15406
Closes #4713
Diffstat (limited to 'test')
-rw-r--r-- | test/functional/autocmd/termxx_spec.lua | 13 | ||||
-rw-r--r-- | test/functional/fixtures/shell-test.c | 17 |
2 files changed, 25 insertions, 5 deletions
diff --git a/test/functional/autocmd/termxx_spec.lua b/test/functional/autocmd/termxx_spec.lua index b12c24b58d..1e8f981437 100644 --- a/test/functional/autocmd/termxx_spec.lua +++ b/test/functional/autocmd/termxx_spec.lua @@ -13,7 +13,7 @@ describe('autocmd TermClose', function() before_each(function() clear() nvim('set_option', 'shell', nvim_dir .. '/shell-test') - nvim('set_option', 'shellcmdflag', 'EXE') + command('set shellcmdflag=EXE shellredir= shellpipe= shellquote= shellxquote=') end) it('triggers when fast-exiting terminal job stops', function() @@ -90,6 +90,17 @@ describe('autocmd TermClose', function() retry(nil, nil, function() eq('3', eval('g:abuf')) end) feed('<c-c>:qa!<cr>') end) + + it('exposes v:event.status', function() + command('set shellcmdflag=EXIT') + command('autocmd TermClose * let g:status = v:event.status') + + command('terminal 0') + retry(nil, nil, function() eq(0, eval('g:status')) end) + + command('terminal 42') + retry(nil, nil, function() eq(42, eval('g:status')) end) + end) end) it('autocmd TermEnter, TermLeave', function() diff --git a/test/functional/fixtures/shell-test.c b/test/functional/fixtures/shell-test.c index b95e563932..4196716799 100644 --- a/test/functional/fixtures/shell-test.c +++ b/test/functional/fixtures/shell-test.c @@ -19,7 +19,7 @@ static void flush_wait(void) static void help(void) { - puts("A simple implementation of a shell for testing termopen()."); + puts("Fake shell"); puts(""); puts("Usage:"); puts(" shell-test --help"); @@ -42,6 +42,8 @@ static void help(void) puts(" 96: foo bar"); puts(" shell-test INTERACT"); puts(" Prints \"interact $ \" to stderr, and waits for \"exit\" input."); + puts(" shell-test EXIT {code}"); + puts(" Exits immediately with exit code \"{code}\"."); } int main(int argc, char **argv) @@ -103,7 +105,6 @@ int main(int argc, char **argv) char input[256]; char cmd[100]; int arg; - int input_argc; while (1) { fprintf(stderr, "interact $ "); @@ -112,8 +113,7 @@ int main(int argc, char **argv) break; // EOF } - input_argc = sscanf(input, "%99s %d", cmd, &arg); - if(1 == input_argc) { + if(1 == sscanf(input, "%99s %d", cmd, &arg)) { arg = 0; } if (strcmp(cmd, "exit") == 0) { @@ -122,6 +122,15 @@ int main(int argc, char **argv) fprintf(stderr, "command not found: %s\n", cmd); } } + } else if (strcmp(argv[1], "EXIT") == 0) { + int code = 1; + if (argc >= 3) { + if (sscanf(argv[2], "%d", &code) != 1) { + fprintf(stderr, "Invalid exit code: %s\n", argv[2]); + return 2; + } + } + return code; } else { fprintf(stderr, "Unknown first argument: %s\n", argv[1]); return 3; |