issue93.t 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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. my $i=0;
  12. my $todo = <<'EOF';
  13. # === compiled ===
  14. my ($pid, $out, $in);
  15. BEGIN {
  16. local(*FPID);
  17. $pid = open(FPID, 'echo <<EOF |'); #impossible
  18. open($out, '>&STDOUT'); #easy
  19. open(my $tmp, '>', 'pcc.tmp'); #hard to gather filename
  20. print $tmp "test\n";
  21. close $tmp; #ok closed, easy
  22. open($in, '<', 'pcc.tmp'); #hard to gather filename
  23. }
  24. # === run-time ===
  25. print $out 'o';
  26. kill 0, $pid; # BAD! warn? die? how?
  27. read $in, my $x, 4;
  28. print 'k' if 'test' eq $x;
  29. unlink 'pcc.tmp';
  30. EOF
  31. my $ok = <<'EOF';
  32. my $out;open($out,'>&STDOUT');print $out qq(ok\n);
  33. EOF
  34. my $work = <<'EOF';
  35. my $out;BEGIN{open($out,'>&STDOUT');}print $out qq(ok\n);
  36. EOF
  37. sub test3 {
  38. my $name = shift;
  39. my $script = shift;
  40. my $cmt = shift;
  41. plctestok($i*3+1, $name, $script,
  42. (($name eq 'ccode93iw' and $] < 5.014)?"TODO needs 5.14 ":"")."BC $cmt");
  43. ctestok($i*3+2, "C", $name, $script, "C $cmt");
  44. ctestok($i*3+3, "CC", $name, $script, "CC $cmt");
  45. $i++;
  46. }
  47. TODO: {
  48. local $TODO = "recover IO state generally";
  49. test3('ccode93ib', $todo, 'various hard IO BEGIN problems');
  50. }
  51. test3('ccode93ig', $ok, '&STDOUT at run-time');
  52. TODO: {
  53. local $TODO = "recover STDIO state";
  54. test3('ccode93iw', $work, '&STDOUT restore');
  55. }
  56. END {unlink "pcc.tmp" if -f "pcc.tmp";}