From d192fc984fed3298e6c05321ff2b40a5f78277e7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20M=C3=BCllner?= Date: Thu, 16 Jan 2025 16:19:19 +0100 Subject: [PATCH] run-test: Split out module evaluation The gjs API is slightly odd, in that explicit calls to `System.exit()` are treated as errors, regardless of the passed status code. Before addressing this, split out the module evaluation code into a separate function to separate it from the main logic. Part-of: --- src/run-js-test.c | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/src/run-js-test.c b/src/run-js-test.c index 513a4ae43..cc22e76e4 100644 --- a/src/run-js-test.c +++ b/src/run-js-test.c @@ -36,6 +36,18 @@ #include "shell-global.h" #include "shell-global-private.h" +static int +eval_module (GjsContext *js_context, + const char *filename, + GError **error) +{ + uint8_t code; + bool success = gjs_context_eval_module_file (js_context, filename, &code, error); + if (!success) + code = 1; + return code; +} + int main (int argc, char **argv) { @@ -77,13 +89,9 @@ main (int argc, char **argv) title = g_filename_display_basename (filename); g_set_prgname (title); - /* evaluate the script */ - bool success = gjs_context_eval_module_file (js_context, filename, &code, &error); - if (!success) - { - g_printerr ("%s\n", error->message); - exit (1); - } + code = eval_module (js_context, filename, &error); + if (error) + g_printerr ("%s\n", error->message); gjs_context_gc (js_context); gjs_context_gc (js_context);