From: Nick Bowler Date: Wed, 10 Mar 2021 01:25:21 +0000 (-0500) Subject: Fix empty and help commands causing program exit. X-Git-Tag: v1.1~11 X-Git-Url: https://git.draconx.ca/gitweb/cdecl99.git/commitdiff_plain/1964240454d93493ee68a75b171fdf7934332200 Fix empty and help commands causing program exit. This bug was introduced when the input handling was reworked: the "help" and blank commands are now causing the program to exit. Add some test coverage to ensure we don't regress again in the future. --- diff --git a/NEWS b/NEWS index 2ba5206..94edf77 100644 --- a/NEWS +++ b/NEWS @@ -1,4 +1,5 @@ Release 1a: + * Various bug fixes. Release 1: * Initial release. diff --git a/src/execute.gperf b/src/execute.gperf index e8a0665..c667408 100644 --- a/src/execute.gperf +++ b/src/execute.gperf @@ -79,7 +79,7 @@ static int run_cmd_help(void) print_block(gettext(strtab+c->cmd), 15, w); } - return 1; + return 0; } int run_command(const char *line, int interactive) @@ -90,7 +90,7 @@ int run_command(const char *line, int interactive) /* empty command */ if (cmd[0] == '\0') - return 1; + return 0; c = in_word_set(cmd, arg-cmd); if (!c) { diff --git a/tests/general.at b/tests/general.at index 337afdd..38493ce 100644 --- a/tests/general.at +++ b/tests/general.at @@ -29,3 +29,46 @@ AT_CHECK([$SHELL "$builddir/exported.sh" "$archive" || exit 99], [0], [stdout]) AT_CHECK([sed '/^cdecl_/d' stdout]) AT_CLEANUP + +dnl Verify that empty commands do nothing. +AT_SETUP([cdecl99 empty command]) + +AT_DATA([input], [[explain int x[42]; + +declare x as array 42 of int + +explain int + +]]) + +AT_CHECK([cdecl99 -f input], [0], [[declare x as array 42 of int +int x[42] +type int +]]) + +AT_CLEANUP + +dnl Verify that commands are not executed after "quit" +AT_SETUP([cdecl99 quit command]) + +AT_DATA([input], [[explain int; +quit +explain this is a syntax error +]]) + +AT_CHECK([cdecl99 -f input], [0], [type int +]) + +AT_CLEANUP + +AT_SETUP([cdecl99 help command]) + +AT_DATA([input], [[help +explain int +]]) + +AT_CHECK([cdecl99 -f input], [0], [stdout]) +AT_CHECK([sed -n '$p' stdout], [0], [type int +]) + +AT_CLEANUP