issue93.t 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. #! /usr/bin/env perl
  2. # http://code.google.com/p/perl-compiler/issues/detail?id=93
  3. # recover state of IO objects. Or not
  4. # Another testcase is t/testm.sh Test::NoWarnings
  5. use strict;
  6. BEGIN {
  7. unshift @INC, 't';
  8. require "test.pl";
  9. }
  10. use Test::More tests => 9;
  11. use Config;
  12. my $i=0;
  13. my $todo = <<'EOS';
  14. # === compiled ===
  15. my ($pid, $out, $in);
  16. BEGIN {
  17. local(*FPID);
  18. $pid = open(FPID, 'echo <<EOF |'); #impossible
  19. open($out, '>&STDOUT'); #easy
  20. open(my $tmp, '>', 'pcc.tmp'); #hard to gather filename
  21. print $tmp "test\n";
  22. close $tmp; #ok closed, easy
  23. open($in, '<', 'pcc.tmp'); #hard to gather filename
  24. }
  25. # === run-time ===
  26. print $out 'o';
  27. kill 0, $pid; # BAD! warn? die? how?
  28. read $in, my $x, 4;
  29. print 'k' if 'test' eq $x;
  30. unlink 'pcc.tmp';
  31. EOS
  32. my $ok = <<'EOF';
  33. my $out;open($out,'>&STDOUT');print $out qq(ok\n);
  34. EOF
  35. my $work = <<'EOF';
  36. my $out;BEGIN{open($out,'>&STDOUT');}print $out qq(ok\n);
  37. EOF
  38. sub test3 {
  39. my $name = shift;
  40. my $script = shift;
  41. my $cmt = shift;
  42. my $todobc = (($name eq 'ccode93iw' and $] < 5.014)?"TODO needs 5.14 ":"");
  43. plctestok($i*3+1, $name, $script,$todobc."BC $cmt");
  44. ctestok($i*3+2, "C", $name, $script, "C $cmt");
  45. ctestok($i*3+3, "CC", $name, $script, "CC $cmt");
  46. $i++;
  47. }
  48. TODO: {
  49. local $TODO = "recover IO state generally";
  50. test3('ccode93ib', $todo, 'various hard IO BEGIN problems');
  51. }
  52. test3('ccode93ig', $ok, '&STDOUT at run-time');
  53. TODO: {
  54. local $TODO = "recover STDIO state";
  55. test3('ccode93iw', $work, '&STDOUT restore');
  56. }
  57. END {unlink "pcc.tmp" if -f "pcc.tmp";}