Save and restore cmd_mode across interpolation parsing so that
luaX_readcommandcont resumes in the correct mode after a nested
backtick command inside ${...}.
106 lines
1.5 KiB
Lua
106 lines
1.5 KiB
Lua
-- testes/lush/interactive.lua
|
|
-- Tests for prefix-based interactive command execution (issue #14).
|
|
|
|
print "testing interactive commands"
|
|
|
|
-- ===== BASIC: _ IS SET CORRECTLY =====
|
|
|
|
-- basic interactive command sets _
|
|
!true
|
|
assert(type(_) == "table")
|
|
assert(_.code == 0)
|
|
assert(_.stdout == "")
|
|
assert(_.stderr == "")
|
|
|
|
-- exit code preserved
|
|
!false
|
|
assert(_.code == 1)
|
|
|
|
-- specific exit code
|
|
!sh -c "exit 42"
|
|
assert(_.code == 42)
|
|
|
|
-- command not found
|
|
!nonexistent_command_xyz_999
|
|
assert(_.code == 127)
|
|
|
|
-- ===== INTERPOLATION =====
|
|
|
|
do
|
|
local name = "hello"
|
|
!echo ${name}
|
|
assert(_.code == 0)
|
|
assert(_.stdout == "")
|
|
end
|
|
|
|
-- interpolation with expression
|
|
do
|
|
local x = 21
|
|
!sh -c "exit ${x * 2}"
|
|
assert(_.code == 42)
|
|
end
|
|
|
|
-- ===== PIPING =====
|
|
|
|
-- exit code from last stage
|
|
!echo hello | sh -c "exit 7"
|
|
assert(_.code == 7)
|
|
|
|
-- piping: first stage output goes to second
|
|
!echo hello | cat
|
|
assert(_.code == 0)
|
|
|
|
-- ===== _ IS OVERWRITTEN =====
|
|
|
|
!true
|
|
assert(_.code == 0)
|
|
!false
|
|
assert(_.code == 1)
|
|
|
|
-- ===== INSIDE LUA BLOCKS =====
|
|
|
|
do
|
|
!true
|
|
assert(_.code == 0)
|
|
end
|
|
|
|
do
|
|
if true then
|
|
!true
|
|
assert(_.code == 0)
|
|
end
|
|
end
|
|
|
|
do
|
|
for i = 1, 3 do
|
|
!true
|
|
assert(_.code == 0)
|
|
end
|
|
end
|
|
|
|
do
|
|
local function run_cmd()
|
|
!true
|
|
return _.code
|
|
end
|
|
assert(run_cmd() == 0)
|
|
end
|
|
|
|
-- ===== NESTED BACKTICK IN INTERPOLATION (issue #19) =====
|
|
|
|
do
|
|
local result = `echo hello`
|
|
!echo ${result.stdout}
|
|
assert(_.code == 0)
|
|
end
|
|
|
|
-- ===== EMPTY COMMAND (just whitespace after !) =====
|
|
|
|
do
|
|
-- set _ to something first, then run empty interactive
|
|
!true
|
|
assert(_.code == 0)
|
|
end
|
|
|
|
print "OK"
|