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);
30 my $string1 = "foo\nbar\n";
33 file_dump
($tmp1_name, $string1);
35 my $pid = spawn
(exec => 'cat',
36 from_string
=> \
$string1,
37 to_string
=> \
$string2);
39 ok
($pid, 'execute cat program, I/O to variables');
41 is
($string2, $string1, '{from,to}_string');
43 $pid = spawn
(exec => 'cat',
44 from_handle
=> $tmp1_fh,
45 to_handle
=> $tmp2_fh);
47 ok
($pid, 'execute cat program, I/O to filehandles');
51 $string2 = file_slurp
($tmp2_name);
53 is
($string2, $string1, '{from,to}_handle');
55 $pid = spawn
(exec => 'cat',
56 from_file
=> $tmp1_name,
57 to_file
=> $tmp2_name,
60 ok
($pid, 'execute cat program, I/O to filenames and wait');
62 $string2 = file_slurp
($tmp2_name);
64 is
($string2, $string1, '{from,to}_file');
67 $pid = spawn
(exec => ['sleep', '10'],
71 ok
($@
, 'fails on timeout');