800_Dpkg_IPC.t 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. # -*- mode: cperl -*-
  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 ($tmp_fh, $tmp_name) = tempfile;
  22. my ($tmp2_fh, $tmp2_name) = tempfile;
  23. my $string = "foo\nbar\n";
  24. my $string2;
  25. open TMP, '>', $tmp_name;
  26. print TMP $string;
  27. close TMP;
  28. my $pid = spawn(exec => "cat",
  29. from_string => \$string,
  30. to_string => \$string2);
  31. ok($pid);
  32. is($string2, $string, "{from,to}_string");
  33. $pid = spawn(exec => "cat",
  34. from_handle => $tmp_fh,
  35. to_handle => $tmp2_fh);
  36. ok($pid);
  37. wait_child($pid);
  38. open TMP, '<', $tmp2_name;
  39. $string2 = <TMP>;
  40. close TMP;
  41. is($string2, $string, "{from,to}_handle");
  42. $pid = spawn(exec => "cat",
  43. from_file => $tmp_name,
  44. to_file => $tmp2_name,
  45. wait_child => 1,
  46. timeout => 5);
  47. ok($pid);
  48. open TMP, '<', $tmp2_name;
  49. $string2 = <TMP>;
  50. close TMP;
  51. is($string2, $string, "{from,to}_file");
  52. eval {
  53. $pid = spawn(exec => ["sleep", "10"],
  54. wait_child => 1,
  55. timeout => 5);
  56. };
  57. ok($@, "fails on timeout");
  58. unlink($tmp_name);
  59. unlink($tmp2_name);