diff options
author | Eric Wong <e@80x24.org> | 2023-10-25 00:29:25 +0000 |
---|---|---|
committer | Eric Wong <e@80x24.org> | 2023-10-25 07:28:31 +0000 |
commit | 07f639c9219968a01d5c722424e9c61d3b146014 (patch) | |
tree | 90819294795e27bf2ee74893a4e4cabebf05d84b /t | |
parent | f81954fe591c6a6358ba528118874313e3920e83 (diff) | |
download | public-inbox-07f639c9219968a01d5c722424e9c61d3b146014.tar.gz |
This is similar to `backtick` but supports all our existing spawn functionality (chdir, env, rlimit, redirects, etc.). It also supports SCALAR ref redirects like run_script in our test suite for std{in,out,err}. We can probably use :utf8 by default for these redirects, even.
Diffstat (limited to 't')
-rw-r--r-- | t/spawn.t | 13 |
1 files changed, 12 insertions, 1 deletions
@@ -3,7 +3,7 @@ # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt> use v5.12; use Test::More; -use PublicInbox::Spawn qw(which spawn popen_rd); +use PublicInbox::Spawn qw(which spawn popen_rd run_qx); require PublicInbox::Sigfd; require PublicInbox::DS; @@ -19,6 +19,17 @@ require PublicInbox::DS; is($?, 0, 'true exited successfully'); } +{ + my $opt = { 0 => \'in', 2 => \(my $e) }; + my $out = run_qx(['sh', '-c', 'echo e >&2; cat'], undef, $opt); + is($e, "e\n", 'captured stderr'); + is($out, 'in', 'stdin read and stdout captured'); + $opt->{0} = \"IN\n3\nLINES"; + my @out = run_qx(['sh', '-c', 'echo E >&2; cat'], undef, $opt); + is($e, "e\nE\n", 'captured stderr appended to string'); + is_deeply(\@out, [ "IN\n", "3\n", 'LINES' ], 'stdout array'); +} + SKIP: { my $pid = spawn(['true'], undef, { pgid => 0 }); ok($pid, 'spawned process with new pgid'); |