diff options
| author | Saikari <[email protected]> | 2026-02-02 09:07:30 +0300 |
|---|---|---|
| committer | Saikari <[email protected]> | 2026-02-02 09:07:30 +0300 |
| commit | 20960586d09f1b83b20798223d853aa834078dbc (patch) | |
| tree | ae93e6524ee785c04fb16aee0d172b7ae8b99a06 /tests/modules/stdin/test.lua | |
| parent | eb8a34c1838e72534d3662f1da6efe273d6cc370 (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.lua | 44 |
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) |
