issue197.t 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. #! /usr/bin/env perl
  2. # http://code.google.com/p/perl-compiler/issues/detail?id=197
  3. # missing package DESTROY
  4. use strict;
  5. BEGIN {
  6. unshift @INC, 't';
  7. require "test.pl";
  8. }
  9. use Test::More tests => 5;
  10. my $exp = "ok - dynamic destruction
  11. ok - lexical destruction
  12. ok - package destruction";
  13. use B::C ();
  14. my $todo = ($] >= 5.018 or $B::C::VERSION ge "1.45_01") ? "" : "TODO ";
  15. my $todo280 = ($B::C::VERSION ge "1.45_08") ? "" : "TODO "; #-O3 fixed with 49bd030
  16. my $script197 = <<'EOF';
  17. package FINALE;
  18. {
  19. $ref3 = bless ["ok - package destruction"];
  20. my $ref2 = bless ["ok - lexical destruction\n"];
  21. local $ref1 = bless ["ok - dynamic destruction\n"];
  22. 1;
  23. }
  24. DESTROY {
  25. print $_[0][0];
  26. }
  27. EOF
  28. ctest(1,$exp,'C,-O2','ccode197i',$script197,$todo.'missing package DESTROY #197');
  29. ctest(2,$exp,'C,-O3','ccode197i',$script197,$todo280.'missing -O3 package DESTROY #197, #280');
  30. $exp = $] > 5.013005 ? "RUN MyKooh DESTRUCT OurKooh" : " MyKooh OurKooh";
  31. my $script208 = <<'EOF';
  32. sub MyKooh::DESTROY { print "${^GLOBAL_PHASE} MyKooh " } my $k=bless {}, MyKooh;
  33. sub OurKooh::DESTROY { print "${^GLOBAL_PHASE} OurKooh" }our $k=bless {}, OurKooh;
  34. EOF
  35. ctest(3,$exp,'C,-O2','ccode197i',$script208,$todo.'missing our DESTROY #208');
  36. ctest(4,$exp,'C,-O3','ccode197i',$script208,$todo280.'missing our -O3 DESTROY #208, #280');
  37. # if the bless happens inside BEGIN: wontfix
  38. ctestok(5,'C,-O3','ccode197i',<<'EOF','TODO destroy upgraded lexvar #254');
  39. my $flag = 0;
  40. sub X::DESTROY { $flag = 1 }
  41. {
  42. my $x; # x only exists in that scope
  43. BEGIN { $x = 42 } # pre-initialized as IV
  44. $x = bless {}, "X"; # run-time upgrade and bless to call DESTROY
  45. # undef($x); # value should be freed when exiting scope
  46. }
  47. print "ok\n" if $flag;
  48. EOF