issue90.t 1.6 KB

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