3 # This program is free software; you can redistribute it and/or modify
4 # it under the terms of the GNU General Public License as published by
5 # the Free Software Foundation; either version 2 of the License, or
6 # (at your option) any later version.
8 # This program is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # GNU General Public License for more details.
13 # You should have received a copy of the GNU General Public License
14 # along with this program. If not, see <https://www.gnu.org/licenses/>.
19 use Test::More tests => 8;
21 use File::Temp qw(tempfile);
27 my ($tmp1_fh, $tmp1_name) = tempfile(UNLINK => 1);
28 my ($tmp2_fh, $tmp2_name) = tempfile(UNLINK => 1);
31 my $string1 = "foo\nbar\n";
34 open $tmp_fh, '>', $tmp1_name
35 or die "cannot open $tmp1_name: $!";
36 print { $tmp_fh } $string1;
39 my $pid = spawn(exec => 'cat',
40 from_string => \$string1,
41 to_string => \$string2);
43 ok($pid, 'execute cat program, I/O to variables');
45 is($string2, $string1, '{from,to}_string');
47 $pid = spawn(exec => 'cat',
48 from_handle => $tmp1_fh,
49 to_handle => $tmp2_fh);
51 ok($pid, 'execute cat program, I/O to filehandles');
55 open $tmp_fh, '<', $tmp2_name
56 or die "cannot open $tmp2_name: $!";
60 is($string2, $string1, '{from,to}_handle');
62 $pid = spawn(exec => 'cat',
63 from_file => $tmp1_name,
64 to_file => $tmp2_name,
67 ok($pid, 'execute cat program, I/O to filenames and wait');
69 open $tmp_fh, '<', $tmp2_name
70 or die "cannot open $tmp2_name: $!";
74 is($string2, $string1, '{from,to}_file');
77 $pid = spawn(exec => ['sleep', '10'],
81 ok($@, 'fails on timeout');