From 546f3d65f7735e6cbb19d418144c05bf7adb4f44 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20M=C3=BCllner?= Date: Thu, 16 Jan 2025 12:22:21 +0100 Subject: [PATCH] run-test: Always use returned status code if possible gjs_context_eval_module_file() is a convenience method for - register the module (load and parse) - evaluate the module (run) The first can fail, but has no notion of status code; the second will always set a valid code if provided (either as returned by the module, or set by gjs itself). Doing those two steps separately allows us to explicitly handle failures to register the module, so that we can then return the original status code from evaluating the module. That means that if evaluating the module "fails" with a `GJS_ERROR_SYSTEM_EXIT` error (because it was terminated with `System.exit()`), we now return the correct status code instead of `EXIT_FAILURE`. Part-of: --- src/run-js-test.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/run-js-test.c b/src/run-js-test.c index cc22e76e4..5e56a663c 100644 --- a/src/run-js-test.c +++ b/src/run-js-test.c @@ -41,10 +41,20 @@ eval_module (GjsContext *js_context, const char *filename, GError **error) { + g_autoptr (GFile) file = NULL; + g_autofree char *uri = NULL; uint8_t code; - bool success = gjs_context_eval_module_file (js_context, filename, &code, error); - if (!success) - code = 1; + + file = g_file_new_for_commandline_arg (filename); + uri = g_file_get_uri (file); + + if (!gjs_context_register_module (js_context, uri, uri, error)) + return 1; + + if (!gjs_context_eval_module (js_context, uri, &code, error)) + { + /* nothing, but avoid G_GNUC_WARN_UNUSED_RESULT compiler warnings */ + } return code; }