# Copyright (C) 2015 all contributors # License: AGPL-3.0+ use strict; use warnings; use Test::More; use PublicInbox::Spawn qw(which spawn); { my $true = which('true'); ok($true, "'true' command found with which()"); } { my $pid = spawn(['true']); ok($pid, 'spawned process'); is(waitpid($pid, 0), $pid, 'waitpid succeeds on spawned process'); is($?, 0, 'true exited successfully'); } { my ($r, $w); pipe $r, $w or die "pipe failed: $!"; my $pid = spawn(['echo', 'hello world'], undef, { 1 => fileno($w) }); close $w or die "close pipe[1] failed: $!"; is(<$r>, "hello world\n", 'read stdout of spawned from pipe'); is(waitpid($pid, 0), $pid, 'waitpid succeeds on spawned process'); is($?, 0, 'true exited successfully'); } { my ($r, $w); pipe $r, $w or die "pipe failed: $!"; my $pid = spawn(['sh', '-c', 'echo $HELLO'], { 'HELLO' => 'world' }, { 1 => fileno($w) }); close $w or die "close pipe[1] failed: $!"; is(<$r>, "world\n", 'read stdout of spawned from pipe'); is(waitpid($pid, 0), $pid, 'waitpid succeeds on spawned process'); is($?, 0, 'sh exited successfully'); } { my ($r, $w); pipe $r, $w or die "pipe failed: $!"; my $pid = spawn(['env'], {}, { -env => 1, 1 => fileno($w) }); close $w or die "close pipe[1] failed: $!"; ok(!defined(<$r>), 'read stdout of spawned from pipe'); is(waitpid($pid, 0), $pid, 'waitpid succeeds on spawned process'); is($?, 0, 'env(1) exited successfully'); } done_testing(); 1;