-- testes/lush/commands.lua -- Tests for backtick command execution (issues #02, #03). print "testing backtick commands" -- basic command, result is a table with code/stdout/stderr do local r = `echo hello` assert(type(r) == "table") assert(type(r.code) == "number") assert(type(r.stdout) == "string") assert(type(r.stderr) == "string") end -- successful command returns exit code 0 do local r = `true` assert(r.code == 0) end -- failed command returns non-zero exit code do local r = `false` assert(r.code == 1) end -- specific exit codes are preserved do local r = `sh -c "exit 42"` assert(r.code == 42) end -- command not found returns 127 do local r = `nonexistent_command_xyz_999` assert(r.code == 127) end -- stdout capture do local r = `echo hello` assert(r.stdout == "hello\n") end -- stderr capture do local r = `sh -c "echo err >&2"` assert(r.stderr == "err\n") assert(r.stdout == "") end -- stdout and stderr are independent do local r = `sh -c "echo out; echo err >&2"` assert(r.stdout == "out\n") assert(r.stderr == "err\n") end -- empty command returns code 0 and empty strings do local r = `` assert(r.code == 0) assert(r.stdout == "") assert(r.stderr == "") end -- multi-word output preserved do local r = `echo hello world` assert(r.stdout == "hello world\n") end -- backtick as statement (result discarded, no error) do `true` end -- backtick result used inline do local code = `true`.code assert(code == 0) end -- multiline output captured do local r = `printf "a\nb\nc\n"` assert(r.stdout == "a\nb\nc\n") end print "OK"