issue93.t 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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 = <<'EOF';
  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. EOF
  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. $todobc = 'TODO 5.18thr ' if $] >= 5.018 and $Config{useithreads};
  44. plctestok($i*3+1, $name, $script,$todobc."BC $cmt");
  45. ctestok($i*3+2, "C", $name, $script, "C $cmt");
  46. ctestok($i*3+3, "CC", $name, $script, "CC $cmt");
  47. $i++;
  48. }
  49. TODO: {
  50. local $TODO = "recover IO state generally";
  51. test3('ccode93ib', $todo, 'various hard IO BEGIN problems');
  52. }
  53. test3('ccode93ig', $ok, '&STDOUT at run-time');
  54. TODO: {
  55. local $TODO = "recover STDIO state";
  56. test3('ccode93iw', $work, '&STDOUT restore');
  57. }
  58. END {unlink "pcc.tmp" if -f "pcc.tmp";}