issue305.t 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. #! /usr/bin/env perl
  2. # http://code.google.com/p/perl-compiler/issues/detail?id=305
  3. # wrong compile-time Encode::XS &ascii_encoding
  4. # fix in perl_init2_aaaa:
  5. # #include <dlfcn.h>
  6. # void *handle = dlopen(sv_list[5032].sv_u.svu_pv, RTLD_NOW|RTLD_NOLOAD); // <pathto/Encode.so>
  7. # void *ascii_encoding = dlsym(handle, "ascii_encoding");
  8. # SvIV_set(&sv_list[1], PTR2IV(ascii_encoding)); PVMG->iv
  9. use strict;
  10. BEGIN {
  11. unshift @INC, 't';
  12. require TestBC;
  13. }
  14. use Test::More;
  15. if ($] < 5.007) {
  16. plan skip_all => "No Encode with perl-$]";
  17. exit;
  18. } elsif ($] > 5.025003) {
  19. plan skip_all => "No Encode support yet with v5.26";
  20. exit;
  21. } else {
  22. require Encode;
  23. plan tests => 3;
  24. }
  25. use Config;
  26. my $ITHREADS = $Config{useithreads};
  27. # fixed with 1.49_07 even for older Encode versions
  28. my $todo = $Encode::VERSION lt '2.58'
  29. ? "Old Encode-$Encode::VERSION < 2.58 "
  30. : "New Encode-$Encode::VERSION >= 2.58 ";
  31. #if ($ITHREADS and ($] > 5.015 or $] < 5.01)) {
  32. # $todo = "TODO $] thr ".$todo if $] < 5.020;
  33. #}
  34. #$todo = 'TODO 5.22 ' if $] > 5.021; # fixed with 1.52_13
  35. $todo = $] > 5.025003 ? 'TODO 5.26 ' : '';
  36. my $cmt = '#305 compile-time Encode::XS encodings';
  37. my $script = 'use constant ASCII => eval { require Encode; Encode::find_encoding("ASCII"); } || 0;
  38. print ASCII->encode("www.google.com")';
  39. my $exp = "www.google.com";
  40. ctest(1, $exp, 'C,-O3', 'ccode305i', $script, $todo.'C '.$cmt);
  41. $script = 'INIT{ sub ASCII { eval { require Encode; Encode::find_encoding("ASCII"); } || 0; }}
  42. print ASCII->encode("www.google.com")';
  43. ctest(2, $exp, 'C,-O3', 'ccode305i', $script, 'C run-time init');
  44. # fixed with 1.49_07, and for 5.22 with 1.52_13
  45. #$todo = $] > 5.021 ? 'TODO 5.22 ' : '';
  46. $todo = $] > 5.025003 ? 'TODO 5.26 ' : '';
  47. ctest(3, $exp, 'C,-O3', 'ccode305i', <<'EOF', $todo.'C #365 compile-time Encode subtypes');
  48. use constant JP => eval { require Encode; Encode::find_encoding("euc-jp"); } || 0;
  49. print JP->encode("www.google.com")
  50. EOF