about summary refs log tree commit homepage
path: root/t
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2023-10-25 00:29:25 +0000
committerEric Wong <e@80x24.org>2023-10-25 07:28:31 +0000
commit07f639c9219968a01d5c722424e9c61d3b146014 (patch)
tree90819294795e27bf2ee74893a4e4cabebf05d84b /t
parentf81954fe591c6a6358ba528118874313e3920e83 (diff)
downloadpublic-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.t13
1 files changed, 12 insertions, 1 deletions
diff --git a/t/spawn.t b/t/spawn.t
index 1af66bda..4b3baae4 100644
--- a/t/spawn.t
+++ b/t/spawn.t
@@ -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');