]> git.draconx.ca Git - cdecl99.git/commitdiff
Fix empty and help commands causing program exit.
authorNick Bowler <nbowler@draconx.ca>
Wed, 10 Mar 2021 01:25:21 +0000 (20:25 -0500)
committerNick Bowler <nbowler@draconx.ca>
Wed, 10 Mar 2021 01:28:24 +0000 (20:28 -0500)
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.

NEWS
src/execute.gperf
tests/general.at

diff --git a/NEWS b/NEWS
index 2ba520652ca24d1de4a7109df3bf095bf23a06c1..94edf7791d25fbadd7937394120774f744df5bec 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -1,4 +1,5 @@
 Release 1a:
+       * Various bug fixes.
 
 Release 1:
        * Initial release.
index e8a066547b73ff7e3cd85927ffeb04f50d8c7ae1..c667408c57c85282298ec9e6c55c0638e6b609c3 100644 (file)
@@ -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) {
index 337afddf4bd4953b7bade3b8eed25bc786266300..38493ce1e9d0a53dc05c0ff8f0f0e8f2649d7d55 100644 (file)
@@ -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