summaryrefslogtreecommitdiff
path: root/tests/modules/stdin/test.lua
diff options
context:
space:
mode:
authorSaikari <[email protected]>2026-02-02 11:04:21 +0300
committerSaikari <[email protected]>2026-02-02 11:04:21 +0300
commitcd45a05d8b83235f8e2c421769f12afa063ce669 (patch)
tree0cc9cbfc02fc2065dc0f5968032857bbb305c94c /tests/modules/stdin/test.lua
parentd1653c5b32f4efa7fec6ab40cb93eb14b0014c38 (diff)
refactor: enhance fix_ape_programfile function to improve argument handling and add executable header check
Diffstat (limited to 'tests/modules/stdin/test.lua')
-rw-r--r--tests/modules/stdin/test.lua16
1 files changed, 13 insertions, 3 deletions
diff --git a/tests/modules/stdin/test.lua b/tests/modules/stdin/test.lua
index b0c908c3c..c6544a6b1 100644
--- a/tests/modules/stdin/test.lua
+++ b/tests/modules/stdin/test.lua
@@ -10,13 +10,13 @@ end
-- Fix /usr/bin/ape loader mode on Linux
function fix_ape_programfile(xmake)
if is_host("linux") and path.filename(xmake):find("ape", 1, true) and os.isfile("/proc/self/cmdline") then
- local content = io.readfile("/proc/self/cmdline")
+ local content = io.readfile("/proc/self/cmdline", {encoding = "binary"})
if content then
local args = {}
for arg in content:gmatch("[^\0]+") do
table.insert(args, arg)
end
- if #args >= 2 and path.unix(args[1]) == xmake then
+ if #args >= 2 and (path.unix(args[1]) == xmake or path.filename(path.unix(args[1])) == path.filename(xmake)) then
xmake = path.unix(args[2])
xmake = resolve_path(xmake)
end
@@ -35,7 +35,17 @@ function main(t)
-- Fix pwsh and cosmocc "err: ape error: l: not found (maybe chmod +x or ./ needed)" for Linux
xmake = fix_ape_programfile(xmake)
- local is_ape = path.filename(xmake):find("ape-", 1, true) ~= nil
+ local is_ape = path.filename(xmake):find("ape", 1, true) ~= nil or xmake:endswith(".com")
+ if not is_ape and is_host("linux") and os.isfile(xmake) then
+ local file = io.open(xmake, "rb")
+ if file then
+ local header = file:read(2)
+ file:close()
+ if header == "MZ" then
+ is_ape = true
+ end
+ end
+ end
local run_stdin = string.format('env "%s" l --stdin', xmake)
-- Fix pwsh and cosmocc "exec format error" for MacOS