From 0ce3b52f696d9fb07dded56400d4d3338074ea6c Mon Sep 17 00:00:00 2001 From: Robin Haberkorn Date: Mon, 28 Oct 2024 17:38:02 +0300 Subject: 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}. --- src/main.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'src/main.c') diff --git a/src/main.c b/src/main.c index eb3c0b4..5b3b8cf 100644 --- a/src/main.c +++ b/src/main.c @@ -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; -- cgit v1.2.3