1 # Copyright (C) 2015 all contributors <meta@public-inbox.org>
2 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
6 use PublicInbox::Spawn qw(which spawn);
9 my $true = which('true');
10 ok($true, "'true' command found with which()");
14 my $pid = spawn(['true']);
15 ok($pid, 'spawned process');
16 is(waitpid($pid, 0), $pid, 'waitpid succeeds on spawned process');
17 is($?, 0, 'true exited successfully');
22 pipe $r, $w or die "pipe failed: $!";
23 my $pid = spawn(['echo', 'hello world'], undef, { 1 => fileno($w) });
24 close $w or die "close pipe[1] failed: $!";
25 is(<$r>, "hello world\n", 'read stdout of spawned from pipe');
26 is(waitpid($pid, 0), $pid, 'waitpid succeeds on spawned process');
27 is($?, 0, 'true exited successfully');
32 pipe $r, $w or die "pipe failed: $!";
33 my $pid = spawn(['sh', '-c', 'echo $HELLO'],
34 { 'HELLO' => 'world' }, { 1 => fileno($w) });
35 close $w or die "close pipe[1] failed: $!";
36 is(<$r>, "world\n", 'read stdout of spawned from pipe');
37 is(waitpid($pid, 0), $pid, 'waitpid succeeds on spawned process');
38 is($?, 0, 'sh exited successfully');
43 pipe $r, $w or die "pipe failed: $!";
44 my $pid = spawn(['env'], {}, { -env => 1, 1 => fileno($w) });
45 close $w or die "close pipe[1] failed: $!";
46 ok(!defined(<$r>), 'read stdout of spawned from pipe');
47 is(waitpid($pid, 0), $pid, 'waitpid succeeds on spawned process');
48 is($?, 0, 'env(1) exited successfully');