diff --git a/testes/lush/builtins.lua b/testes/lush/builtins.lua index 5a58a4da..72a2ffb5 100644 --- a/testes/lush/builtins.lua +++ b/testes/lush/builtins.lua @@ -3,6 +3,8 @@ print "testing shell builtins" +local interp = require("lush.testutil").INTERP + -- === __builtins is NOT in _G (internal, stored in registry) === do @@ -132,7 +134,7 @@ end -- exec replaces process (test in subprocess) do - local r = `sh -c './lua -e "os.exit(42)"'` + local r = lush.capture("sh -c '" .. interp .. " -e \"os.exit(42)\"'") assert(r.code == 42, "subprocess exit code: " .. tostring(r.code)) end diff --git a/testes/lush/config.lua b/testes/lush/config.lua index 3e8ca048..41b02bcf 100644 --- a/testes/lush/config.lua +++ b/testes/lush/config.lua @@ -3,6 +3,8 @@ print "testing configuration" +local INTERP = require("lush.testutil").INTERP + -- helper: get a unique temp directory local tmpbase = os.tmpname() os.remove(tmpbase) -- tmpname creates the file on some systems @@ -21,10 +23,10 @@ local function rmrf(path) os.execute('rm -rf "' .. path .. '"') end --- helper: run ./lua -i with XDG_CONFIG_HOME set, feed it a command via stdin +-- helper: run interpreter -i with XDG_CONFIG_HOME set, feed it a command via stdin local function run_with_config(xdg_dir, input) local cmd = string.format( - 'printf "%%s\\n" "%s" | XDG_CONFIG_HOME="%s" ./lua -i 2>&1', + 'printf "%%s\\n" "%s" | XDG_CONFIG_HOME="%s" ' .. INTERP .. ' -i 2>&1', input, xdg_dir) local f = io.popen(cmd) local output = f:read("*a") @@ -32,10 +34,10 @@ local function run_with_config(xdg_dir, input) return output end --- helper: run ./lua -E -i with XDG_CONFIG_HOME set +-- helper: run interpreter -E -i with XDG_CONFIG_HOME set local function run_with_config_E(xdg_dir, input) local cmd = string.format( - 'printf "%%s\\n" "%s" | XDG_CONFIG_HOME="%s" ./lua -E -i 2>&1', + 'printf "%%s\\n" "%s" | XDG_CONFIG_HOME="%s" ' .. INTERP .. ' -E -i 2>&1', input, xdg_dir) local f = io.popen(cmd) local output = f:read("*a") diff --git a/testes/lush/globbing.lua b/testes/lush/globbing.lua index 2191f811..954af613 100644 --- a/testes/lush/globbing.lua +++ b/testes/lush/globbing.lua @@ -7,7 +7,7 @@ print "testing globbing and tilde expansion" -- *.lua should expand to matching files (we know lush test files exist) do - local r = `echo *.c` + local r = `echo ../*.c` local out = r.stdout:gsub("\n$", "") -- should NOT be the literal "*.c" since .c files exist in the project assert(out ~= "*.c", "expected *.c to expand, got literal: " .. out) @@ -125,7 +125,7 @@ end -- === expansion in pipelines === do - local r = `echo *.c | head -1` + local r = `echo ../*.c | head -1` local out = r.stdout:gsub("\n$", "") -- pipeline should have expanded *.c before piping assert(out ~= "*.c", "glob not expanded in pipeline, got: " .. out) diff --git a/testes/lush/prompt.lua b/testes/lush/prompt.lua index f793bae1..be0cddbd 100644 --- a/testes/lush/prompt.lua +++ b/testes/lush/prompt.lua @@ -3,6 +3,8 @@ print "testing prompt system" +local INTERP = require("lush.testutil").INTERP + -- helper: get a unique temp directory local tmpbase = os.tmpname() os.remove(tmpbase) -- tmpname creates the file on some systems @@ -21,7 +23,7 @@ local function rmrf(path) os.execute('rm -rf "' .. path .. '"') end --- helper: run ./lua -i with config, use print() to reveal prompt state +-- helper: run interpreter -i with config, use print() to reveal prompt state local function run_lua(input, config_content) local tmpdir = tmpbase .. "_run" mkdir(tmpdir .. "/lush") @@ -29,7 +31,7 @@ local function run_lua(input, config_content) writefile(tmpdir .. "/lush/config.lua", config_content) end local cmd = string.format( - 'printf "%%s\\n" %s | XDG_CONFIG_HOME="%s" ./lua -i 2>&1', + 'printf "%%s\\n" %s | XDG_CONFIG_HOME="%s" ' .. INTERP .. ' -i 2>&1', input, tmpdir) local f = io.popen(cmd) local output = f:read("*a") diff --git a/testes/lush/testutil.lua b/testes/lush/testutil.lua new file mode 100644 index 00000000..ec2838e9 --- /dev/null +++ b/testes/lush/testutil.lua @@ -0,0 +1,13 @@ +-- testes/lush/testutil.lua +-- Shared utilities for lush test files. + +local M = {} + +-- Derive the interpreter path from the arg table. +-- Works regardless of CWD (project root or testes/). +local a = arg or ARG +local i = 0 +while a[i] do i = i - 1 end +M.INTERP = a[i + 1] + +return M