From cf493d92b483cf72d182b03d696bc19d1a571d24 Mon Sep 17 00:00:00 2001 From: aarondill Date: Sun, 30 Jun 2024 00:25:03 -0500 Subject: [PATCH] chore: add tests for awesome.spawn return_stdio Signed-off-by: aarondill --- tests/test-spawn.lua | 66 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) diff --git a/tests/test-spawn.lua b/tests/test-spawn.lua index 71b901929c..7039d6b14e 100644 --- a/tests/test-spawn.lua +++ b/tests/test-spawn.lua @@ -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