issue90.t 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. #! /usr/bin/env perl
  2. # http://code.google.com/p/perl-compiler/issues/detail?id=90
  3. # Magic Tie::Named::Capture <=> *main::+ main::*- and Errno vs !
  4. # op/leaky-magic.t: defer loading of Tie::Named::Capture and Errno to run-time
  5. use strict;
  6. BEGIN {
  7. unshift @INC, 't';
  8. require "test.pl";
  9. }
  10. use Test::More tests => 15;
  11. use B::C ();
  12. use Config;
  13. my $i=0;
  14. sub test3 {
  15. my $name = shift;
  16. my $script = shift;
  17. my $cmt = join('',@_);
  18. my ($todobc,$todocc) = ("","");
  19. $todobc = 'TODO ' if $name eq 'ccode90i_c';
  20. # passes BC threaded 5.10-16
  21. $todobc = '' if $name eq 'ccode90i_c'
  22. and $] >= 5.010 and $Config{'useithreads'};
  23. if ($name eq 'ccode90i_c' and ($B::C::VERSION lt '1.42_61')) {
  24. $todocc = 'TODO '; #3 CC %+ includes Tie::Hash::NamedCapture
  25. } elsif ($name eq 'ccode90i_ca' and $] >= 5.010) {
  26. $todocc = ''; #6 CC @+ fixed with 1.44
  27. #} elsif ($name eq 'ccode90i_er' and $] >= 5.010 and $Config{'useithreads'}) {
  28. # $todocc = 'TODO '; #12 CC Errno loaded automagically. fixed with 1.48
  29. }
  30. plctestok($i*3+1, $name, $script, $todobc."BC ".$cmt);
  31. ctestok($i*3+2, "C,-O3", $name, $script, "C $cmt");
  32. ctestok($i*3+3, "CC", $name, $script, $todocc."CC $cmt");
  33. $i++;
  34. }
  35. SKIP: {
  36. skip "Tie::Named::Capture requires Perl v5.10", 3 if $] < 5.010;
  37. test3('ccode90i_c', <<'EOF', '%+ includes Tie::Hash::NamedCapture');
  38. my $s = 'test string';
  39. $s =~ s/(?<first>test) (?<second>string)/\2 \1/g;
  40. print q(o) if $s eq 'string test';
  41. 'test string' =~ /(?<first>\w+) (?<second>\w+)/;
  42. print q(k) if $+{first} eq 'test';
  43. EOF
  44. }
  45. test3('ccode90i_ca', <<'EOF', '@+');
  46. "abc" =~ /(.)./; print "ok" if "21" eq join"",@+;
  47. EOF
  48. test3('ccode90i_es', <<'EOF', '%! magic');
  49. my %errs = %!; # t/op/magic.t Errno compiled in
  50. print q(ok) if defined ${"!"}{ENOENT};
  51. EOF
  52. # %{"!"} detected at compile-time
  53. test3('ccode90i_er', <<'EOF', 'Errno loaded automagically');
  54. my %errs = %{"!"}; # t/op/magic.t Errno to be loaded at run-time
  55. print q(ok) if defined ${"!"}{ENOENT};
  56. EOF
  57. test3('ccode90i_ep', <<'EOF', '%! pure IV');
  58. print FH "foo"; print "ok" if $! == 9;
  59. EOF