mirror of
https://github.com/lune-org/lune.git
synced 2025-04-10 21:40:54 +01:00
fix: rename tests to for process.spawn->process.exec
This commit is contained in:
parent
4b5b54eb0d
commit
ce033bbdcb
9 changed files with 25 additions and 25 deletions
|
@ -138,13 +138,13 @@ create_tests! {
|
||||||
process_cwd: "process/cwd",
|
process_cwd: "process/cwd",
|
||||||
process_env: "process/env",
|
process_env: "process/env",
|
||||||
process_exit: "process/exit",
|
process_exit: "process/exit",
|
||||||
process_spawn_async: "process/spawn/async",
|
process_exec_async: "process/exec/async",
|
||||||
process_spawn_basic: "process/spawn/basic",
|
process_exec_basic: "process/exec/basic",
|
||||||
process_spawn_cwd: "process/spawn/cwd",
|
process_exec_cwd: "process/exec/cwd",
|
||||||
process_spawn_no_panic: "process/spawn/no_panic",
|
process_exec_no_panic: "process/exec/no_panic",
|
||||||
process_spawn_shell: "process/spawn/shell",
|
process_exec_shell: "process/exec/shell",
|
||||||
process_spawn_stdin: "process/spawn/stdin",
|
process_exec_stdin: "process/exec/stdin",
|
||||||
process_spawn_stdio: "process/spawn/stdio",
|
process_exec_stdio: "process/exec/stdio",
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "std-regex")]
|
#[cfg(feature = "std-regex")]
|
||||||
|
@ -249,6 +249,6 @@ create_tests! {
|
||||||
task_cancel: "task/cancel",
|
task_cancel: "task/cancel",
|
||||||
task_defer: "task/defer",
|
task_defer: "task/defer",
|
||||||
task_delay: "task/delay",
|
task_delay: "task/delay",
|
||||||
task_spawn: "task/spawn",
|
task_exec: "task/exec",
|
||||||
task_wait: "task/wait",
|
task_wait: "task/wait",
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,7 +31,7 @@ for i = 1, SLEEP_SAMPLES, 1 do
|
||||||
table.insert(args, 1, "-Milliseconds")
|
table.insert(args, 1, "-Milliseconds")
|
||||||
end
|
end
|
||||||
-- Windows does not have `sleep` as a process, so we use powershell instead.
|
-- Windows does not have `sleep` as a process, so we use powershell instead.
|
||||||
process.spawn("sleep", args, if IS_WINDOWS then { shell = true } else nil)
|
process.exec("sleep", args, if IS_WINDOWS then { shell = true } else nil)
|
||||||
sleepCounter += 1
|
sleepCounter += 1
|
||||||
end)
|
end)
|
||||||
end
|
end
|
|
@ -12,7 +12,7 @@ end)
|
||||||
|
|
||||||
local IS_WINDOWS = process.os == "windows"
|
local IS_WINDOWS = process.os == "windows"
|
||||||
|
|
||||||
local result = process.spawn(
|
local result = process.exec(
|
||||||
if IS_WINDOWS then "cmd" else "ls",
|
if IS_WINDOWS then "cmd" else "ls",
|
||||||
if IS_WINDOWS then { "/c", "dir" } else { "-a" }
|
if IS_WINDOWS then { "/c", "dir" } else { "-a" }
|
||||||
)
|
)
|
|
@ -6,7 +6,7 @@ local pwdCommand = if IS_WINDOWS then "cmd" else "pwd"
|
||||||
local pwdArgs = if IS_WINDOWS then { "/c", "cd" } else {}
|
local pwdArgs = if IS_WINDOWS then { "/c", "cd" } else {}
|
||||||
|
|
||||||
-- Make sure the cwd option actually uses the directory we want
|
-- Make sure the cwd option actually uses the directory we want
|
||||||
local rootPwd = process.spawn(pwdCommand, pwdArgs, {
|
local rootPwd = process.exec(pwdCommand, pwdArgs, {
|
||||||
cwd = "/",
|
cwd = "/",
|
||||||
}).stdout
|
}).stdout
|
||||||
rootPwd = string.gsub(rootPwd, "^%s+", "")
|
rootPwd = string.gsub(rootPwd, "^%s+", "")
|
||||||
|
@ -27,24 +27,24 @@ end
|
||||||
|
|
||||||
-- Setting cwd should not change the cwd of this process
|
-- Setting cwd should not change the cwd of this process
|
||||||
|
|
||||||
local pwdBefore = process.spawn(pwdCommand, pwdArgs).stdout
|
local pwdBefore = process.exec(pwdCommand, pwdArgs).stdout
|
||||||
process.spawn("ls", {}, {
|
process.exec("ls", {}, {
|
||||||
cwd = "/",
|
cwd = "/",
|
||||||
shell = true,
|
shell = true,
|
||||||
})
|
})
|
||||||
local pwdAfter = process.spawn(pwdCommand, pwdArgs).stdout
|
local pwdAfter = process.exec(pwdCommand, pwdArgs).stdout
|
||||||
assert(pwdBefore == pwdAfter, "Current working directory changed after running child process")
|
assert(pwdBefore == pwdAfter, "Current working directory changed after running child process")
|
||||||
|
|
||||||
-- Setting the cwd on a child process should properly
|
-- Setting the cwd on a child process should properly
|
||||||
-- replace any leading ~ with the users real home dir
|
-- replace any leading ~ with the users real home dir
|
||||||
|
|
||||||
local homeDir1 = process.spawn("echo $HOME", nil, {
|
local homeDir1 = process.exec("echo $HOME", nil, {
|
||||||
shell = true,
|
shell = true,
|
||||||
}).stdout
|
}).stdout
|
||||||
|
|
||||||
-- NOTE: Powershell for windows uses `$pwd.Path` instead of `pwd` as pwd would return
|
-- NOTE: Powershell for windows uses `$pwd.Path` instead of `pwd` as pwd would return
|
||||||
-- a PathInfo object, using $pwd.Path gets the Path property of the PathInfo object
|
-- a PathInfo object, using $pwd.Path gets the Path property of the PathInfo object
|
||||||
local homeDir2 = process.spawn(if IS_WINDOWS then "$pwd.Path" else "pwd", nil, {
|
local homeDir2 = process.exec(if IS_WINDOWS then "$pwd.Path" else "pwd", nil, {
|
||||||
shell = true,
|
shell = true,
|
||||||
cwd = "~",
|
cwd = "~",
|
||||||
}).stdout
|
}).stdout
|
|
@ -3,5 +3,5 @@ local process = require("@lune/process")
|
||||||
-- Spawning a child process for a non-existent
|
-- Spawning a child process for a non-existent
|
||||||
-- program should not panic, but should error
|
-- program should not panic, but should error
|
||||||
|
|
||||||
local success = pcall(process.spawn, "someProgramThatDoesNotExist")
|
local success = pcall(process.exec, "someProgramThatDoesNotExist")
|
||||||
assert(not success, "Spawned a non-existent program")
|
assert(not success, "Spawned a non-existent program")
|
|
@ -5,7 +5,7 @@ local IS_WINDOWS = process.os == "windows"
|
||||||
-- Default shell should be /bin/sh on unix and powershell on Windows,
|
-- Default shell should be /bin/sh on unix and powershell on Windows,
|
||||||
-- note that powershell needs slightly different command flags for ls
|
-- note that powershell needs slightly different command flags for ls
|
||||||
|
|
||||||
local shellResult = process.spawn("ls", {
|
local shellResult = process.exec("ls", {
|
||||||
if IS_WINDOWS then "-Force" else "-a",
|
if IS_WINDOWS then "-Force" else "-a",
|
||||||
}, {
|
}, {
|
||||||
shell = true,
|
shell = true,
|
|
@ -10,8 +10,8 @@ local echoMessage = "Hello from child process!"
|
||||||
-- When passing stdin to powershell on windows we must "accept" using the double newline
|
-- When passing stdin to powershell on windows we must "accept" using the double newline
|
||||||
|
|
||||||
local result = if IS_WINDOWS
|
local result = if IS_WINDOWS
|
||||||
then process.spawn("powershell", { "echo" }, { stdin = echoMessage .. "\n\n" })
|
then process.exec("powershell", { "echo" }, { stdin = echoMessage .. "\n\n" })
|
||||||
else process.spawn("xargs", { "echo" }, { stdin = echoMessage })
|
else process.exec("xargs", { "echo" }, { stdin = echoMessage })
|
||||||
|
|
||||||
local resultStdout = if IS_WINDOWS
|
local resultStdout = if IS_WINDOWS
|
||||||
then string.sub(result.stdout, #result.stdout - #echoMessage - 1)
|
then string.sub(result.stdout, #result.stdout - #echoMessage - 1)
|
|
@ -5,7 +5,7 @@ local IS_WINDOWS = process.os == "windows"
|
||||||
-- Inheriting stdio & environment variables should work
|
-- Inheriting stdio & environment variables should work
|
||||||
|
|
||||||
local echoMessage = "Hello from child process!"
|
local echoMessage = "Hello from child process!"
|
||||||
local echoResult = process.spawn("echo", {
|
local echoResult = process.exec("echo", {
|
||||||
if IS_WINDOWS then '"$Env:TEST_VAR"' else '"$TEST_VAR"',
|
if IS_WINDOWS then '"$Env:TEST_VAR"' else '"$TEST_VAR"',
|
||||||
}, {
|
}, {
|
||||||
env = { TEST_VAR = echoMessage },
|
env = { TEST_VAR = echoMessage },
|
|
@ -12,7 +12,7 @@ export type SpawnOptionsStdio = {
|
||||||
@interface SpawnOptions
|
@interface SpawnOptions
|
||||||
@within Process
|
@within Process
|
||||||
|
|
||||||
A dictionary of options for `process.spawn`, with the following available values:
|
A dictionary of options for `process.exec`, with the following available values:
|
||||||
|
|
||||||
* `cwd` - The current working directory for the process
|
* `cwd` - The current working directory for the process
|
||||||
* `env` - Extra environment variables to give to the process
|
* `env` - Extra environment variables to give to the process
|
||||||
|
@ -32,7 +32,7 @@ export type SpawnOptions = {
|
||||||
@interface SpawnResult
|
@interface SpawnResult
|
||||||
@within Process
|
@within Process
|
||||||
|
|
||||||
Result type for child processes in `process.spawn`.
|
Result type for child processes in `process.exec`.
|
||||||
|
|
||||||
This is a dictionary containing the following values:
|
This is a dictionary containing the following values:
|
||||||
|
|
||||||
|
@ -74,7 +74,7 @@ export type SpawnResult = {
|
||||||
print("Running " .. process.os .. " on " .. process.arch .. "!")
|
print("Running " .. process.os .. " on " .. process.arch .. "!")
|
||||||
|
|
||||||
-- Spawning a child process
|
-- Spawning a child process
|
||||||
local result = process.spawn("program", {
|
local result = process.exec("program", {
|
||||||
"cli argument",
|
"cli argument",
|
||||||
"other cli argument"
|
"other cli argument"
|
||||||
})
|
})
|
||||||
|
@ -175,7 +175,7 @@ end
|
||||||
@param options A dictionary of options for the child process
|
@param options A dictionary of options for the child process
|
||||||
@return A dictionary representing the result of the child process
|
@return A dictionary representing the result of the child process
|
||||||
]=]
|
]=]
|
||||||
function process.spawn(program: string, params: { string }?, options: SpawnOptions?): SpawnResult
|
function process.exec(program: string, params: { string }?, options: SpawnOptions?): SpawnResult
|
||||||
return nil :: any
|
return nil :: any
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue