800_Dpkg_IPC.t 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. # -*- mode: cperl -*-
  2. use Test::More tests => 8;
  3. use strict;
  4. use warnings;
  5. use File::Temp qw(tempfile);
  6. use_ok('Dpkg::IPC');
  7. $/ = undef;
  8. my ($tmp_fh, $tmp_name) = tempfile;
  9. my ($tmp2_fh, $tmp2_name) = tempfile;
  10. my $string = "foo\nbar\n";
  11. my $string2;
  12. open TMP, '>', $tmp_name;
  13. print TMP $string;
  14. close TMP;
  15. my $pid = fork_and_exec(exec => "cat",
  16. from_string => \$string,
  17. to_string => \$string2);
  18. ok($pid);
  19. is($string2, $string, "{from,to}_string");
  20. $pid = fork_and_exec(exec => "cat",
  21. from_handle => $tmp_fh,
  22. to_handle => $tmp2_fh);
  23. ok($pid);
  24. wait_child($pid);
  25. open TMP, '<', $tmp2_name;
  26. $string2 = <TMP>;
  27. close TMP;
  28. is($string2, $string, "{from,to}_handle");
  29. $pid = fork_and_exec(exec => "cat",
  30. from_file => $tmp_name,
  31. to_file => $tmp2_name,
  32. wait_child => 1,
  33. timeout => 5);
  34. ok($pid);
  35. open TMP, '<', $tmp2_name;
  36. $string2 = <TMP>;
  37. close TMP;
  38. is($string2, $string, "{from,to}_file");
  39. eval {
  40. $pid = fork_and_exec(exec => ["sleep", "10"],
  41. wait_child => 1,
  42. timeout => 5);
  43. };
  44. ok($@, "fails on timeout");
  45. unlink($tmp_name);
  46. unlink($tmp2_name);