diff options
author | Robin Haberkorn <robin.haberkorn@googlemail.com> | 2024-10-28 17:38:02 +0300 |
---|---|---|
committer | Robin Haberkorn <robin.haberkorn@googlemail.com> | 2024-10-28 17:38:02 +0300 |
commit | 0ce3b52f696d9fb07dded56400d4d3338074ea6c (patch) | |
tree | d264e4352cd572c2a8003c35dd3a8396a9e680ee | |
parent | 427092d2c8ee11b4a56eb50dbf68861f10f2a81f (diff) | |
download | sciteco-0ce3b52f696d9fb07dded56400d4d3338074ea6c.tar.gz |
added hidden --fake-cmdline parameter for testing command-line editing
* Supports all immediate editing commands.
Naturally it cannot emulate arbitrary key presses since there is no
canonic ASCII-encoding of function keys.
Key macros are not consequently also not testable.
The --fake-cmdline parameter is instead treated very similar to
a key macro expansion.
* Most importantly this allows adding test cases for rubout behavior
and bugs that are quite common.
* Added regression test cases for the last two rubout bugs.
* It's not easy to pass control codes in command line arguments in
a portable manner, so the test cases will often use { and }.
Control codes could be used e.g. by defining variables like
RUBOUT=`printf '\b'`
and referencing them with ${RUBOUT}.
-rw-r--r-- | TODO | 3 | ||||
-rw-r--r-- | src/main.c | 13 | ||||
-rw-r--r-- | tests/atlocal.in | 7 | ||||
-rw-r--r-- | tests/testsuite.at | 11 |
4 files changed, 29 insertions, 5 deletions
@@ -418,9 +418,6 @@ Features: macros. The same construct would also be useful with non-interactive commands as a way to store the supplied parameter using EU for instance. - * Adding a secret command line option to process immediate editing - commands in batch mode with undo would allow us to add some - test cases that otherwise only occur in interactive mode. * Emscripten nodejs port. This may be a viable way to run SciTECO "cross"-platform, at least for evaluation... on UNIX-like systems in absence of prebuilt binaries. @@ -105,6 +105,7 @@ teco_get_default_config_path(const gchar *program) static gchar *teco_eval_macro = NULL; static gboolean teco_mung_file = FALSE; static gboolean teco_mung_profile = TRUE; +static gchar *teco_fake_cmdline = NULL; static gboolean teco_8bit_clean = FALSE; static gchar * @@ -121,6 +122,9 @@ teco_process_options(gchar ***argv) "Do not mung " "$SCITECOCONFIG" G_DIR_SEPARATOR_S INI_FILE " " "even if it exists"}, + {"fake-cmdline", 0, G_OPTION_FLAG_HIDDEN, + G_OPTION_ARG_STRING, &teco_fake_cmdline, + "Emulate key presses in batch mode (for debugging)", "keys"}, {"8bit", '8', 0, G_OPTION_ARG_NONE, &teco_8bit_clean, "Use ANSI encoding by default and disable automatic EOL conversion"}, {NULL} @@ -437,6 +441,15 @@ main(int argc, char **argv) */ teco_machine_main_init(&teco_cmdline.machine, &local_qregs, TRUE); + if (G_UNLIKELY(teco_fake_cmdline != NULL)) { + if (!teco_cmdline_keypress(teco_fake_cmdline, strlen(teco_fake_cmdline), &error) && + !g_error_matches(error, TECO_ERROR, TECO_ERROR_QUIT)) { + teco_error_add_frame_toplevel(); + goto error; + } + goto cleanup; + } + if (!teco_interface_event_loop(&error)) goto error; diff --git a/tests/atlocal.in b/tests/atlocal.in index 061937a..4bc0a21 100644 --- a/tests/atlocal.in +++ b/tests/atlocal.in @@ -4,11 +4,14 @@ host=@host@ # built. # Using the $BOOTSTRAP_SCITECO wouldn't make sense # anyway as we don't want to test some preinstalled SciTECO. -SCITECO=@abs_top_builddir@/src/sciteco +SCITECO="@abs_top_builddir@/src/sciteco" + +# For testing command-line editing: +SCITECO_CMDLINE="@abs_top_builddir@/src/sciteco --no-profile --fake-cmdline" # Make sure that the standard library from the source package # is used. -SCITECOPATH=@abs_top_srcdir@/lib +SCITECOPATH="@abs_top_srcdir@/lib" # Glib debug options G_SLICE=debug-blocks diff --git a/tests/testsuite.at b/tests/testsuite.at index 729b3c8..aba51a5 100644 --- a/tests/testsuite.at +++ b/tests/testsuite.at @@ -214,6 +214,17 @@ AT_SETUP([Jump to beginning of macro]) AT_CHECK([$SCITECO -e "%a-2\"< F< ' Qa-2\"N(0/0)'"], 0, ignore, ignore) AT_CLEANUP +# NOTE: It would generally be possible to use control codes like ^H (8) +# and ^W (23) for rubout as well, but this is tricky to write in a portable manner. +# Therefore we usally use the push/pop command-line commands { and }. +AT_SETUP([Rub out string append]) +AT_CHECK([$SCITECO_CMDLINE "@I/XXX/ H:Xa{-4D} :Qa-0\"N(0/0)'"], 0, ignore, ignore) +AT_CLEANUP + +AT_SETUP([Rub out of empty forward kill]) +AT_CHECK([$SCITECO_CMDLINE "@I/F/ J @I/X/ @FK/F/{-6D} Z-2\"N(0/0)'"], 0, ignore, ignore) +AT_CLEANUP + AT_BANNER([Known Bugs]) AT_SETUP([Number stack]) |