mirror of
https://github.com/lune-org/lune.git
synced 2025-05-04 10:43:57 +01:00
Improve process exec stdin test
This commit is contained in:
parent
b74568eea0
commit
f6d2afb003
1 changed files with 11 additions and 13 deletions
|
@ -1,19 +1,17 @@
|
|||
local process = require("@lune/process")
|
||||
|
||||
local IS_WINDOWS = process.os == "windows"
|
||||
|
||||
-- Windows uses \r\n (CRLF) and unix uses \n (LF)
|
||||
|
||||
local echoTrail = if IS_WINDOWS then "\r\n" else "\n"
|
||||
local echoMessage = "Hello from child process!"
|
||||
local expected = "Hello from child process!"
|
||||
|
||||
-- When passing stdin to powershell on windows we must "accept" using the double newline
|
||||
|
||||
local result = if IS_WINDOWS
|
||||
then process.exec("powershell", { "echo" }, { stdio = { stdin = echoMessage .. "\n\n" } })
|
||||
else process.exec("xargs", { "echo" }, { stdio = { stdin = echoMessage } })
|
||||
local result = if process.os == "windows"
|
||||
then process.exec("powershell", { "echo" }, { stdio = { stdin = expected .. "\n\n" } })
|
||||
else process.exec("xargs", { "echo" }, { stdio = { stdin = expected } })
|
||||
|
||||
local resultStdout = if IS_WINDOWS
|
||||
then string.sub(result.stdout, #result.stdout - #echoMessage - 1)
|
||||
else result.stdout
|
||||
assert(resultStdout == echoMessage .. echoTrail, "Stdin passing did not return proper output")
|
||||
local resultStdout = result.stdout
|
||||
resultStdout = string.gsub(resultStdout, "^%s+", "") -- Trim leading whitespace
|
||||
resultStdout = string.gsub(resultStdout, "%s+$", "") -- Trim trailing whitespace
|
||||
assert(
|
||||
resultStdout == expected,
|
||||
"Stdin passing did not return proper output!" .. `\nExpected: {expected}` .. `\nReceived: {resultStdout}`
|
||||
)
|
||||
|
|
Loading…
Add table
Reference in a new issue