800_Dpkg_IPC.t 968 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. # -*- mode: cperl -*-
  2. use Test::More tests => 7;
  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. ok($pid);
  34. open TMP, '<', $tmp2_name;
  35. $string2 = <TMP>;
  36. close TMP;
  37. is($string2, $string, "{from,to}_file");
  38. unlink($tmp_name);
  39. unlink($tmp2_name);