Add test cases for missing programs with os/spawn and os/execute.

This commit is contained in:
Calvin Rose
2026-09-28 16:53:09 -05:00
parent ec73cf884f
commit ffebf2c497
2 changed files with 21 additions and 8 deletions
+8 -8
View File
@@ -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;
+13
View File
@@ -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)