issue90.t 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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. or ($] >= 5.018 and $Config{'useithreads'});
  21. # passes BC threaded 5.10-16
  22. $todobc = '' if $name eq 'ccode90i_c'
  23. and $] >= 5.010 and $] < 5.018 and $Config{'useithreads'};
  24. if ($name eq 'ccode90i_c' and ($B::C::VERSION lt '1.42_61' or $] >= 5.018)) {
  25. $todocc = 'TODO '; #3 CC %+ includes Tie::Hash::NamedCapture
  26. } elsif ($name eq 'ccode90i_ca' and $] >= 5.010) {
  27. $todocc = ''; #6 CC @+ fixed with 1.44
  28. } elsif ($name eq 'ccode90i_er' and $] >= 5.010 and $Config{'useithreads'}) {
  29. $todocc = 'TODO '; #12 CC Errno loaded automagically
  30. }
  31. plctestok($i*3+1, $name, $script, $todobc."BC ".$cmt);
  32. ctestok($i*3+2, "C,-O3", $name, $script, "C $cmt");
  33. ctestok($i*3+3, "CC", $name, $script, $todocc."CC $cmt");
  34. $i++;
  35. }
  36. SKIP: {
  37. skip "Tie::Named::Capture requires Perl v5.10", 3 if $] < 5.010;
  38. test3('ccode90i_c', <<'EOF', '%+ includes Tie::Hash::NamedCapture');
  39. my $s = 'test string';
  40. $s =~ s/(?<first>test) (?<second>string)/\2 \1/g;
  41. print q(o) if $s eq 'string test';
  42. 'test string' =~ /(?<first>\w+) (?<second>\w+)/;
  43. print q(k) if $+{first} eq 'test';
  44. EOF
  45. }
  46. test3('ccode90i_ca', <<'EOF', '@+');
  47. "abc" =~ /(.)./; print "ok" if "21" eq join"",@+;
  48. EOF
  49. test3('ccode90i_es', <<'EOF', '%! magic');
  50. my %errs = %!; # t/op/magic.t Errno compiled in
  51. print q(ok) if defined ${"!"}{ENOENT};
  52. EOF
  53. # %{"!"} detected at compile-time
  54. test3('ccode90i_er', <<'EOF', 'Errno loaded automagically');
  55. my %errs = %{"!"}; # t/op/magic.t Errno to be loaded at run-time
  56. print q(ok) if defined ${"!"}{ENOENT};
  57. EOF
  58. test3('ccode90i_ep', <<'EOF', '%! pure IV');
  59. print FH "foo"; print "ok" if $! == 9;
  60. EOF