diff --git a/tests/process/exec/async.luau b/tests/process/exec/async.luau index bab274b..205eccc 100644 --- a/tests/process/exec/async.luau +++ b/tests/process/exec/async.luau @@ -4,7 +4,7 @@ local task = require("@lune/task") local IS_WINDOWS = process.os == "windows" --- Spawning a process should not block any lua thread(s) +-- Executing a command should not block any lua thread(s) local SLEEP_DURATION = 1 / 4 local SLEEP_SAMPLES = 2 diff --git a/tests/process/exec/basic.luau b/tests/process/exec/basic.luau index be782b5..f0b35d1 100644 --- a/tests/process/exec/basic.luau +++ b/tests/process/exec/basic.luau @@ -2,7 +2,7 @@ local process = require("@lune/process") local stdio = require("@lune/stdio") local task = require("@lune/task") --- Spawning a child process should work, with options +-- Executing a comamnd should work, with options local thread = task.delay(1, function() stdio.ewrite("Spawning a process should take a reasonable amount of time\n") diff --git a/tests/process/exec/no_panic.luau b/tests/process/exec/no_panic.luau index 9c95421..a7d289f 100644 --- a/tests/process/exec/no_panic.luau +++ b/tests/process/exec/no_panic.luau @@ -1,7 +1,7 @@ local process = require("@lune/process") --- Spawning a child process for a non-existent --- program should not panic, but should error +-- Executing a non existent command as a child process +-- should not panic, but should error local success = pcall(process.exec, "someProgramThatDoesNotExist") assert(not success, "Spawned a non-existent program") diff --git a/tests/process/spawn/non_blocking.luau b/tests/process/spawn/non_blocking.luau new file mode 100644 index 0000000..9b886c0 --- /dev/null +++ b/tests/process/spawn/non_blocking.luau @@ -0,0 +1,18 @@ +local process = require("@lune/process") + +-- Spawning a child process should not block the main thread + +local SAMPLES = 400 + +for _ = 1, SAMPLES do + local start = os.time() + local child = process.spawn("echo", { "hello, world" }) + + assert(child ~= nil, "Failed to spawn child process") + + local delta = os.time() - start + assert( + delta <= 1, + `Spawning a child process should not block the main thread, process.spawn took {delta}s to return it should return immediately` + ) +end diff --git a/tests/process/spawn/status.luau b/tests/process/spawn/status.luau new file mode 100644 index 0000000..3ee6f36 --- /dev/null +++ b/tests/process/spawn/status.luau @@ -0,0 +1,15 @@ +local process = require("@lune/process") + +-- The exit code of an child process should be correct + +local randomExitCode = math.random(1, 255) +local isOk = randomExitCode == 0 +local child = process.spawn("exit", { tostring(randomExitCode) }, { shell = true }) +local status = child.status() + +assert( + status.code == randomExitCode, + `Child process exited with wrong exit code, expected {randomExitCode}` +) + +assert(status.ok == isOk, `Child status should be {if status.ok then "ok" else "not ok"}`) diff --git a/tests/process/spawn/stream.luau b/tests/process/spawn/stream.luau new file mode 100644 index 0000000..7edd9e9 --- /dev/null +++ b/tests/process/spawn/stream.luau @@ -0,0 +1,18 @@ +local process = require("@lune/process") + +-- Should be able to write and read from child process streams + +local msg = "hello, world" + +local catChild = process.spawn("cat") +catChild.stdin:write(msg) +assert( + msg == buffer.tostring(catChild.stdout:read(#msg)), + "Failed to write to stdin or read from stdout of child process" +) + +local echoChild = process.spawn("echo", { msg, ">>/dev/stderr" }, { shell = true }) +assert( + msg == buffer.tostring(echoChild.stderr:read(#msg)), + "Failed to read from stderr of child process" +)