800_Dpkg_IPC.t 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. #!/usr/bin/perl
  2. #
  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.
  7. #
  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.
  12. #
  13. # You should have received a copy of the GNU General Public License
  14. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  15. use Test::More tests => 8;
  16. use strict;
  17. use warnings;
  18. use File::Temp qw(tempfile);
  19. use_ok('Dpkg::IPC');
  20. $/ = undef;
  21. my ($tmp1_fh, $tmp1_name) = tempfile;
  22. my ($tmp2_fh, $tmp2_name) = tempfile;
  23. my $tmp_fh;
  24. my $string1 = "foo\nbar\n";
  25. my $string2;
  26. open $tmp_fh, '>', $tmp1_name;
  27. print $tmp_fh $string1;
  28. close $tmp_fh;
  29. my $pid = spawn(exec => "cat",
  30. from_string => \$string1,
  31. to_string => \$string2);
  32. ok($pid);
  33. is($string2, $string1, "{from,to}_string");
  34. $pid = spawn(exec => "cat",
  35. from_handle => $tmp1_fh,
  36. to_handle => $tmp2_fh);
  37. ok($pid);
  38. wait_child($pid);
  39. open $tmp_fh, '<', $tmp2_name;
  40. $string2 = <$tmp_fh>;
  41. close $tmp_fh;
  42. is($string2, $string1, "{from,to}_handle");
  43. $pid = spawn(exec => "cat",
  44. from_file => $tmp1_name,
  45. to_file => $tmp2_name,
  46. wait_child => 1,
  47. timeout => 5);
  48. ok($pid);
  49. open $tmp_fh, '<', $tmp2_name;
  50. $string2 = <$tmp_fh>;
  51. close $tmp_fh;
  52. is($string2, $string1, "{from,to}_file");
  53. eval {
  54. $pid = spawn(exec => ["sleep", "10"],
  55. wait_child => 1,
  56. timeout => 5);
  57. };
  58. ok($@, "fails on timeout");
  59. unlink($tmp1_name);
  60. unlink($tmp2_name);