issue90.t 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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. use strict;
  5. BEGIN {
  6. unshift @INC, 't';
  7. require "test.pl";
  8. }
  9. use Test::More tests => 16;
  10. use B::C ();
  11. use Config;
  12. my $i=0;
  13. sub test3 {
  14. my $name = shift;
  15. my $script = shift;
  16. my $cmt = join('',@_);
  17. my ($todobc,$todocc) = ("","");
  18. $todobc = 'TODO ' if $name eq 'ccode90i_c' or ($] >= 5.018 and $Config{'useithreads'});
  19. if ($name eq 'ccode90i_c' and ($B::C::VERSION lt '1.42_61' or $] >= 5.018)) {
  20. $todocc = 'TODO '; #3 CC %+ includes Tie::Hash::NamedCapture
  21. } elsif ($name eq 'ccode90i_ca' and $] >= 5.010) {
  22. $todocc = 'TODO '; #6 CC @+
  23. } elsif ($name eq 'ccode90i_er' and $] >= 5.010 and $Config{'useithreads'}) {
  24. $todocc = 'TODO '; #12 CC Errno loaded automagically
  25. }
  26. plctestok($i*3+1, $name, $script, $todobc." BC ".$cmt);
  27. ctestok($i*3+2, "C,-O3", $name, $script, "C $cmt");
  28. ctestok($i*3+3, "CC", $name, $script, $todocc."CC $cmt");
  29. $i++;
  30. }
  31. SKIP: {
  32. skip "Tie::Named::Capture requires Perl v5.10", 3 if $] < 5.010;
  33. test3('ccode90i_c', <<'EOF', '%+ includes Tie::Hash::NamedCapture');
  34. my $s = 'test string';
  35. $s =~ s/(?<first>test) (?<second>string)/\2 \1/g;
  36. print q(o) if $s eq 'string test';
  37. 'test string' =~ /(?<first>\w+) (?<second>\w+)/;
  38. print q(k) if $+{first} eq 'test';
  39. EOF
  40. }
  41. test3('ccode90i_ca', <<'EOF', '@+');
  42. "abc" =~ /(.)./; print "ok" if "21" eq join"",@+;
  43. EOF
  44. test3('ccode90i_es', <<'EOF', '%! magic');
  45. my %errs = %!; # t/op/magic.t Errno compiled in
  46. print q(ok) if defined ${"!"}{ENOENT};
  47. EOF
  48. # this fails so far, %{"!"} is not detected at compile-time. requires -uErrno
  49. test3('ccode90i_er', <<'EOF', 'Errno loaded automagically');
  50. my %errs = %{"!"}; # t/op/magic.t Errno to be loaded at run-time
  51. print q(ok) if defined ${"!"}{ENOENT};
  52. EOF
  53. test3('ccode90i_ep', <<'EOF', '%! pure IV');
  54. print FH "foo"; print "ok" if $! == 9;
  55. EOF
  56. ctestok(16, 'C,-O3', 'ccode90i_ce', <<'EOF', 'TODO C more @+');
  57. my $content = "ok\n";
  58. while ( $content =~ m{\w}g ) {
  59. $_ .= "$-[0]$+[0]";
  60. }
  61. print "ok" if $_ eq "0112";
  62. EOF