summaryrefslogtreecommitdiff
path: root/tests/modules/stdin/test.lua
diff options
context:
space:
mode:
authorSaikari <[email protected]>2026-02-02 09:07:30 +0300
committerSaikari <[email protected]>2026-02-02 09:07:30 +0300
commit20960586d09f1b83b20798223d853aa834078dbc (patch)
treeae93e6524ee785c04fb16aee0d172b7ae8b99a06 /tests/modules/stdin/test.lua
parenteb8a34c1838e72534d3662f1da6efe273d6cc370 (diff)
refactor: extract fix_ape_programfile function for improved readability and maintainability
Diffstat (limited to 'tests/modules/stdin/test.lua')
-rw-r--r--tests/modules/stdin/test.lua44
1 files changed, 22 insertions, 22 deletions
diff --git a/tests/modules/stdin/test.lua b/tests/modules/stdin/test.lua
index 784e55489..26c7d4b47 100644
--- a/tests/modules/stdin/test.lua
+++ b/tests/modules/stdin/test.lua
@@ -7,6 +7,28 @@ function resolve_path(p)
return p
end
+-- Fix /usr/bin/ape loader mode on Linux
+function fix_ape_programfile(xmake)
+ if os.host() == "linux" and path.filename(xmake):find("ape", 1, true) and os.isfile("/proc/self/cmdline") then
+ local file = io.open("/proc/self/cmdline", "rb")
+ if file then
+ local content = file:read("*a")
+ file:close()
+ 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
+ xmake = path.unix(args[2])
+ xmake = resolve_path(xmake)
+ end
+ end
+ end
+ end
+ return xmake
+end
+
function main(t)
local xmake = path.unix(os.programfile())
if os.host() == "windows" then
@@ -14,28 +36,6 @@ function main(t)
end
xmake = resolve_path(xmake)
- -- Fix /usr/bin/ape loader mode on Linux
- local function fix_ape_programfile(xmake)
- if os.host() == "linux" and path.filename(xmake):find("ape", 1, true) and os.isfile("/proc/self/cmdline") then
- local file = io.open("/proc/self/cmdline", "rb")
- if file then
- local content = file:read("*a")
- file:close()
- 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
- xmake = path.unix(args[2])
- xmake = resolve_path(xmake)
- end
- end
- end
- end
- return xmake
- end
-
-- Fix pwsh and cosmocc "err: ape error: l: not found (maybe chmod +x or ./ needed)" for Linux
xmake = fix_ape_programfile(xmake)