From ffebf2c4979c51835dce409f22c6339996c3cd09 Mon Sep 17 00:00:00 2001 From: Calvin Rose Date: Mon, 28 Sep 2026 16:14:59 -0500 Subject: [PATCH] Add test cases for missing programs with os/spawn and os/execute. --- src/core/os.c | 16 ++++++++-------- test/suite-ev.janet | 13 +++++++++++++ 2 files changed, 21 insertions(+), 8 deletions(-) diff --git a/src/core/os.c b/src/core/os.c index afa6b886..b4de8456 100644 --- a/src/core/os.c +++ b/src/core/os.c @@ -1342,13 +1342,13 @@ static Janet os_execute_impl(int32_t argc, Janet *argv, JanetExecuteMode mode) { if (cp_failed) { char msgbuf[256]; msgbuf[0] = '\0'; - FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, - NULL, - cp_error_code, - MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), - msgbuf, - sizeof(msgbuf), - NULL); + FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, + NULL, + cp_error_code, + MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), + msgbuf, + sizeof(msgbuf), + NULL); if (!*msgbuf) snprintf(msgbuf, sizeof(msgbuf), "%" PRIu32, (uint32_t) cp_error_code); char *c = msgbuf; while (*c) { @@ -1358,7 +1358,7 @@ static Janet os_execute_impl(int32_t argc, Janet *argv, JanetExecuteMode mode) { } c++; } - janet_panicf("failed to create process: %s", janet_cstringv(msgbuf)); + janet_panicf("failed to create process: %V", janet_cstringv(msgbuf)); } pHandle = processInfo.hProcess; diff --git a/test/suite-ev.janet b/test/suite-ev.janet index d2ba2337..dd7de68a 100644 --- a/test/suite-ev.janet +++ b/test/suite-ev.janet @@ -641,4 +641,17 @@ (string "'" x "'"))) (assert (= 0 (os/shell (string/join [;run janet "-e" (shell-quote "(os/exit 0)")] " "))) "os/shell simple") +# os/spawn and os/execute when program does not exist gives a normal error +(def dne-path "this-long-binary-name-does-not-exist") +(assert (nil? (os/stat dne-path :mode)) "binary path does not exist 1") +(assert (let [[ok _result] + (protect + (let [process (os/spawn [dne-path] :p)] + # if initial process launch works, it should at least fail with a non-zero exit code. + (if-not (= 0 (:wait process)) + (error "should error"))))] + (not ok)) + "binary path does not exist 2 - os/spawn") +(assert (let [[ok _result] (protect (os/execute [dne-path] :px))] (not ok)) "binary path does not exist 2 - os/execute") + (end-suite)