800_Dpkg_IPC.t 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. #
  2. # This program is free software; you can redistribute it and/or modify
  3. # it under the terms of the GNU General Public License as published by
  4. # the Free Software Foundation; either version 2 of the License, or
  5. # (at your option) any later version.
  6. #
  7. # This program is distributed in the hope that it will be useful,
  8. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. # GNU General Public License for more details.
  11. #
  12. # You should have received a copy of the GNU General Public License
  13. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  14. use Test::More tests => 8;
  15. use strict;
  16. use warnings;
  17. use File::Temp qw(tempfile);
  18. use_ok('Dpkg::IPC');
  19. $/ = undef;
  20. my ($tmp_fh, $tmp_name) = tempfile;
  21. my ($tmp2_fh, $tmp2_name) = tempfile;
  22. my $string = "foo\nbar\n";
  23. my $string2;
  24. open TMP, '>', $tmp_name;
  25. print TMP $string;
  26. close TMP;
  27. my $pid = spawn(exec => "cat",
  28. from_string => \$string,
  29. to_string => \$string2);
  30. ok($pid);
  31. is($string2, $string, "{from,to}_string");
  32. $pid = spawn(exec => "cat",
  33. from_handle => $tmp_fh,
  34. to_handle => $tmp2_fh);
  35. ok($pid);
  36. wait_child($pid);
  37. open TMP, '<', $tmp2_name;
  38. $string2 = <TMP>;
  39. close TMP;
  40. is($string2, $string, "{from,to}_handle");
  41. $pid = spawn(exec => "cat",
  42. from_file => $tmp_name,
  43. to_file => $tmp2_name,
  44. wait_child => 1,
  45. timeout => 5);
  46. ok($pid);
  47. open TMP, '<', $tmp2_name;
  48. $string2 = <TMP>;
  49. close TMP;
  50. is($string2, $string, "{from,to}_file");
  51. eval {
  52. $pid = spawn(exec => ["sleep", "10"],
  53. wait_child => 1,
  54. timeout => 5);
  55. };
  56. ok($@, "fails on timeout");
  57. unlink($tmp_name);
  58. unlink($tmp2_name);