Skip to content

Commit

Permalink
chore: add tests for awesome.spawn return_stdio
Browse files Browse the repository at this point in the history
Signed-off-by: aarondill <[email protected]>
  • Loading branch information
aarondill committed Jun 30, 2024
1 parent 989e018 commit 9a26df1
Showing 1 changed file with 66 additions and 0 deletions.
66 changes: 66 additions & 0 deletions tests/test-spawn.lua
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,72 @@ local steps = {
return true
end
end,
-- Test inheriting stdio
function(count)
if count == 1 then
do -- Test that DEV_NULL works and doesn't return a fd
local read_line = false
local pid, _, _, stdout, stderr = awesome.spawn({ 'readlink', '/proc/self/fd/2' },
false, false, true, "DEV_NULL")
assert(type(pid) ~= "string", pid)
assert(stderr == nil)
spawn.read_lines(require("lgi").Gio.UnixInputStream.new(stdout, true),
function(line)
assert(not read_line)
read_line = true
assert(line == "/dev/null", line)
spawns_done = spawns_done + 1
end, nil, true)
end

do -- Test that INHERIT works and doesn't return a fd
-- Note: if this is /dev/null, this test is useless.
local test_stdin = require('lgi').GLib.file_read_link('/proc/self/fd/0')

local read_line = false
local pid, _, stdin, stdout = awesome.spawn({ 'readlink', '/proc/self/fd/0' },
false, "INHERIT", true, false)
assert(type(pid) ~= "string", pid)
assert(stdin == nil)
spawn.read_lines(require("lgi").Gio.UnixInputStream.new(stdout, true),
function(line)
assert(not read_line)
read_line = true
assert(line == test_stdin, line)
spawns_done = spawns_done + 1
end, nil, true)
end

do -- Test that false doesn't return a pointer (behavior is untested - GLib defaults)
local pid, _, stdin, stdout, stderr = awesome.spawn({"true"},
false, false, false, false)
assert(type(pid) ~= "string", pid)
assert(stdin == nil)
assert(stdout == nil)
assert(stderr == nil)
end

do -- Test that true returns a pipe
local read_line = false
local pid, _, stdin, stdout, stderr = awesome.spawn({ 'readlink', '/proc/self/fd/0' },
false, true, true, true)
assert(type(pid) ~= "string", pid)
assert(stdin ~= nil)
assert(stdout ~= nil)
assert(stderr ~= nil)
spawn.read_lines(require("lgi").Gio.UnixInputStream.new(stdout, true),
function(line)
assert(not read_line)
read_line = true
assert(line:find("^pipe:%[[0-9]+%]$"), line)
spawns_done = spawns_done + 1
end, nil, true)
end
end
if spawns_done == 3 then
return true
end
end,
-- Test spawn_once
function()
if #client.get() ~= 1 then return end
Expand Down

0 comments on commit 9a26df1

Please sign in to comment.