test.pl 35 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069
  1. #
  2. # t/test.pl - from CORE
  3. use Test::More;
  4. use File::Spec;
  5. sub curr_test {
  6. $test = shift if @_;
  7. return $test;
  8. }
  9. sub next_test {
  10. my $retval = $test;
  11. $test = $test + 1; # don't use ++
  12. $retval;
  13. }
  14. my $cp_0037 = # EBCDIC code page 0037
  15. '\x00\x01\x02\x03\x37\x2D\x2E\x2F\x16\x05\x25\x0B\x0C\x0D\x0E\x0F' .
  16. '\x10\x11\x12\x13\x3C\x3D\x32\x26\x18\x19\x3F\x27\x1C\x1D\x1E\x1F' .
  17. '\x40\x5A\x7F\x7B\x5B\x6C\x50\x7D\x4D\x5D\x5C\x4E\x6B\x60\x4B\x61' .
  18. '\xF0\xF1\xF2\xF3\xF4\xF5\xF6\xF7\xF8\xF9\x7A\x5E\x4C\x7E\x6E\x6F' .
  19. '\x7C\xC1\xC2\xC3\xC4\xC5\xC6\xC7\xC8\xC9\xD1\xD2\xD3\xD4\xD5\xD6' .
  20. '\xD7\xD8\xD9\xE2\xE3\xE4\xE5\xE6\xE7\xE8\xE9\xBA\xE0\xBB\xB0\x6D' .
  21. '\x79\x81\x82\x83\x84\x85\x86\x87\x88\x89\x91\x92\x93\x94\x95\x96' .
  22. '\x97\x98\x99\xA2\xA3\xA4\xA5\xA6\xA7\xA8\xA9\xC0\x4F\xD0\xA1\x07' .
  23. '\x20\x21\x22\x23\x24\x15\x06\x17\x28\x29\x2A\x2B\x2C\x09\x0A\x1B' .
  24. '\x30\x31\x1A\x33\x34\x35\x36\x08\x38\x39\x3A\x3B\x04\x14\x3E\xFF' .
  25. '\x41\xAA\x4A\xB1\x9F\xB2\x6A\xB5\xBD\xB4\x9A\x8A\x5F\xCA\xAF\xBC' .
  26. '\x90\x8F\xEA\xFA\xBE\xA0\xB6\xB3\x9D\xDA\x9B\x8B\xB7\xB8\xB9\xAB' .
  27. '\x64\x65\x62\x66\x63\x67\x9E\x68\x74\x71\x72\x73\x78\x75\x76\x77' .
  28. '\xAC\x69\xED\xEE\xEB\xEF\xEC\xBF\x80\xFD\xFE\xFB\xFC\xAD\xAE\x59' .
  29. '\x44\x45\x42\x46\x43\x47\x9C\x48\x54\x51\x52\x53\x58\x55\x56\x57' .
  30. '\x8C\x49\xCD\xCE\xCB\xCF\xCC\xE1\x70\xDD\xDE\xDB\xDC\x8D\x8E\xDF';
  31. my $cp_1047 = # EBCDIC code page 1047
  32. '\x00\x01\x02\x03\x37\x2D\x2E\x2F\x16\x05\x15\x0B\x0C\x0D\x0E\x0F' .
  33. '\x10\x11\x12\x13\x3C\x3D\x32\x26\x18\x19\x3F\x27\x1C\x1D\x1E\x1F' .
  34. '\x40\x5A\x7F\x7B\x5B\x6C\x50\x7D\x4D\x5D\x5C\x4E\x6B\x60\x4B\x61' .
  35. '\xF0\xF1\xF2\xF3\xF4\xF5\xF6\xF7\xF8\xF9\x7A\x5E\x4C\x7E\x6E\x6F' .
  36. '\x7C\xC1\xC2\xC3\xC4\xC5\xC6\xC7\xC8\xC9\xD1\xD2\xD3\xD4\xD5\xD6' .
  37. '\xD7\xD8\xD9\xE2\xE3\xE4\xE5\xE6\xE7\xE8\xE9\xAD\xE0\xBD\x5F\x6D' .
  38. '\x79\x81\x82\x83\x84\x85\x86\x87\x88\x89\x91\x92\x93\x94\x95\x96' .
  39. '\x97\x98\x99\xA2\xA3\xA4\xA5\xA6\xA7\xA8\xA9\xC0\x4F\xD0\xA1\x07' .
  40. '\x20\x21\x22\x23\x24\x25\x06\x17\x28\x29\x2A\x2B\x2C\x09\x0A\x1B' .
  41. '\x30\x31\x1A\x33\x34\x35\x36\x08\x38\x39\x3A\x3B\x04\x14\x3E\xFF' .
  42. '\x41\xAA\x4A\xB1\x9F\xB2\x6A\xB5\xBB\xB4\x9A\x8A\xB0\xCA\xAF\xBC' .
  43. '\x90\x8F\xEA\xFA\xBE\xA0\xB6\xB3\x9D\xDA\x9B\x8B\xB7\xB8\xB9\xAB' .
  44. '\x64\x65\x62\x66\x63\x67\x9E\x68\x74\x71\x72\x73\x78\x75\x76\x77' .
  45. '\xAC\x69\xED\xEE\xEB\xEF\xEC\xBF\x80\xFD\xFE\xFB\xFC\xBA\xAE\x59' .
  46. '\x44\x45\x42\x46\x43\x47\x9C\x48\x54\x51\x52\x53\x58\x55\x56\x57' .
  47. '\x8C\x49\xCD\xCE\xCB\xCF\xCC\xE1\x70\xDD\xDE\xDB\xDC\x8D\x8E\xDF';
  48. my $cp_bc = # EBCDIC code page POSiX-BC
  49. '\x00\x01\x02\x03\x37\x2D\x2E\x2F\x16\x05\x15\x0B\x0C\x0D\x0E\x0F' .
  50. '\x10\x11\x12\x13\x3C\x3D\x32\x26\x18\x19\x3F\x27\x1C\x1D\x1E\x1F' .
  51. '\x40\x5A\x7F\x7B\x5B\x6C\x50\x7D\x4D\x5D\x5C\x4E\x6B\x60\x4B\x61' .
  52. '\xF0\xF1\xF2\xF3\xF4\xF5\xF6\xF7\xF8\xF9\x7A\x5E\x4C\x7E\x6E\x6F' .
  53. '\x7C\xC1\xC2\xC3\xC4\xC5\xC6\xC7\xC8\xC9\xD1\xD2\xD3\xD4\xD5\xD6' .
  54. '\xD7\xD8\xD9\xE2\xE3\xE4\xE5\xE6\xE7\xE8\xE9\xBB\xBC\xBD\x6A\x6D' .
  55. '\x4A\x81\x82\x83\x84\x85\x86\x87\x88\x89\x91\x92\x93\x94\x95\x96' .
  56. '\x97\x98\x99\xA2\xA3\xA4\xA5\xA6\xA7\xA8\xA9\xFB\x4F\xFD\xFF\x07' .
  57. '\x20\x21\x22\x23\x24\x25\x06\x17\x28\x29\x2A\x2B\x2C\x09\x0A\x1B' .
  58. '\x30\x31\x1A\x33\x34\x35\x36\x08\x38\x39\x3A\x3B\x04\x14\x3E\x5F' .
  59. '\x41\xAA\xB0\xB1\x9F\xB2\xD0\xB5\x79\xB4\x9A\x8A\xBA\xCA\xAF\xA1' .
  60. '\x90\x8F\xEA\xFA\xBE\xA0\xB6\xB3\x9D\xDA\x9B\x8B\xB7\xB8\xB9\xAB' .
  61. '\x64\x65\x62\x66\x63\x67\x9E\x68\x74\x71\x72\x73\x78\x75\x76\x77' .
  62. '\xAC\x69\xED\xEE\xEB\xEF\xEC\xBF\x80\xE0\xFE\xDD\xFC\xAD\xAE\x59' .
  63. '\x44\x45\x42\x46\x43\x47\x9C\x48\x54\x51\x52\x53\x58\x55\x56\x57' .
  64. '\x8C\x49\xCD\xCE\xCB\xCF\xCC\xE1\x70\xC0\xDE\xDB\xDC\x8D\x8E\xDF';
  65. my $straight = # Avoid ranges
  66. '\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0A\x0B\x0C\x0D\x0E\x0F' .
  67. '\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1A\x1B\x1C\x1D\x1E\x1F' .
  68. '\x20\x21\x22\x23\x24\x25\x26\x27\x28\x29\x2A\x2B\x2C\x2D\x2E\x2F' .
  69. '\x30\x31\x32\x33\x34\x35\x36\x37\x38\x39\x3A\x3B\x3C\x3D\x3E\x3F' .
  70. '\x40\x41\x42\x43\x44\x45\x46\x47\x48\x49\x4A\x4B\x4C\x4D\x4E\x4F' .
  71. '\x50\x51\x52\x53\x54\x55\x56\x57\x58\x59\x5A\x5B\x5C\x5D\x5E\x5F' .
  72. '\x60\x61\x62\x63\x64\x65\x66\x67\x68\x69\x6A\x6B\x6C\x6D\x6E\x6F' .
  73. '\x70\x71\x72\x73\x74\x75\x76\x77\x78\x79\x7A\x7B\x7C\x7D\x7E\x7F' .
  74. '\x80\x81\x82\x83\x84\x85\x86\x87\x88\x89\x8A\x8B\x8C\x8D\x8E\x8F' .
  75. '\x90\x91\x92\x93\x94\x95\x96\x97\x98\x99\x9A\x9B\x9C\x9D\x9E\x9F' .
  76. '\xA0\xA1\xA2\xA3\xA4\xA5\xA6\xA7\xA8\xA9\xAA\xAB\xAC\xAD\xAE\xAF' .
  77. '\xB0\xB1\xB2\xB3\xB4\xB5\xB6\xB7\xB8\xB9\xBA\xBB\xBC\xBD\xBE\xBF' .
  78. '\xC0\xC1\xC2\xC3\xC4\xC5\xC6\xC7\xC8\xC9\xCA\xCB\xCC\xCD\xCE\xCF' .
  79. '\xD0\xD1\xD2\xD3\xD4\xD5\xD6\xD7\xD8\xD9\xDA\xDB\xDC\xDD\xDE\xDF' .
  80. '\xE0\xE1\xE2\xE3\xE4\xE5\xE6\xE7\xE8\xE9\xEA\xEB\xEC\xED\xEE\xEF' .
  81. '\xF0\xF1\xF2\xF3\xF4\xF5\xF6\xF7\xF8\xF9\xFA\xFB\xFC\xFD\xFE\xFF';
  82. # The following 2 functions allow tests to work on both EBCDIC and
  83. # ASCII-ish platforms. They convert string scalars between the native
  84. # character set and the set of 256 characters which is usually called
  85. # Latin1.
  86. #
  87. # These routines don't work on UTF-EBCDIC and UTF-8.
  88. sub native_to_latin1($) {
  89. my $string = shift;
  90. return $string if ord('^') == 94; # ASCII, Latin1
  91. my $cp;
  92. if (ord('^') == 95) { # EBCDIC 1047
  93. $cp = \$cp_1047;
  94. }
  95. elsif (ord('^') == 106) { # EBCDIC POSIX-BC
  96. $cp = \$cp_bc;
  97. }
  98. elsif (ord('^') == 176) { # EBCDIC 037 */
  99. $cp = \$cp_0037;
  100. }
  101. else {
  102. die "Unknown native character set";
  103. }
  104. eval '$string =~ tr/' . $$cp . '/' . $straight . '/';
  105. return $string;
  106. }
  107. sub latin1_to_native($) {
  108. my $string = shift;
  109. return $string if ord('^') == 94; # ASCII, Latin1
  110. my $cp;
  111. if (ord('^') == 95) { # EBCDIC 1047
  112. $cp = \$cp_1047;
  113. }
  114. elsif (ord('^') == 106) { # EBCDIC POSIX-BC
  115. $cp = \$cp_bc;
  116. }
  117. elsif (ord('^') == 176) { # EBCDIC 037 */
  118. $cp = \$cp_0037;
  119. }
  120. else {
  121. die "Unknown native character set";
  122. }
  123. eval '$string =~ tr/' . $straight . '/' . $$cp . '/';
  124. return $string;
  125. }
  126. sub ord_latin1_to_native {
  127. # given an input code point, return the platform's native
  128. # equivalent value. Anything above latin1 is itself.
  129. my $ord = shift;
  130. return $ord if $ord > 255;
  131. return ord latin1_to_native(chr $ord);
  132. }
  133. sub ord_native_to_latin1 {
  134. # given an input platform code point, return the latin1 equivalent value.
  135. # Anything above latin1 is itself.
  136. my $ord = shift;
  137. return $ord if $ord > 255;
  138. return ord native_to_latin1(chr $ord);
  139. }
  140. sub _where {
  141. my @caller = caller($Level);
  142. return "at $caller[1] line $caller[2]";
  143. }
  144. # runperl - Runs a separate perl interpreter.
  145. # Arguments :
  146. # switches => [ command-line switches ]
  147. # nolib => 1 # don't use -I../lib (included by default)
  148. # prog => one-liner (avoid quotes)
  149. # progs => [ multi-liner (avoid quotes) ]
  150. # progfile => perl script
  151. # stdin => string to feed the stdin
  152. # stderr => redirect stderr to stdout
  153. # args => [ command-line arguments to the perl program ]
  154. # verbose => print the command line
  155. my $is_mswin = $^O eq 'MSWin32';
  156. my $is_netware = $^O eq 'NetWare';
  157. my $is_macos = $^O eq 'MacOS';
  158. my $is_vms = $^O eq 'VMS';
  159. my $is_cygwin = $^O eq 'cygwin';
  160. sub _quote_args {
  161. my ($runperl, $args) = @_;
  162. foreach (@$args) {
  163. # In VMS protect with doublequotes because otherwise
  164. # DCL will lowercase -- unless already doublequoted.
  165. $_ = q(").$_.q(") if $is_vms && !/^\"/ && length($_) > 0;
  166. $$runperl .= ' ' . $_;
  167. }
  168. }
  169. sub _create_runperl { # Create the string to qx in runperl().
  170. my %args = @_;
  171. my $runperl = $^X =~ m/\s/ ? qq{"$^X"} : $^X;
  172. #- this allows, for example, to set PERL_RUNPERL_DEBUG=/usr/bin/valgrind
  173. if ($ENV{PERL_RUNPERL_DEBUG}) {
  174. $runperl = "$ENV{PERL_RUNPERL_DEBUG} $runperl";
  175. }
  176. unless ($args{nolib}) {
  177. if ($is_macos) {
  178. $runperl .= ' -I::lib';
  179. # Use UNIX style error messages instead of MPW style.
  180. $runperl .= ' -MMac::err=unix' if $args{stderr};
  181. }
  182. else {
  183. $runperl .= ' "-I../lib"'; # doublequotes because of VMS
  184. }
  185. }
  186. if ($args{switches}) {
  187. local $Level = 2;
  188. die "test.pl:runperl(): 'switches' must be an ARRAYREF " . _where()
  189. unless ref $args{switches} eq "ARRAY";
  190. _quote_args(\$runperl, $args{switches});
  191. }
  192. if (defined $args{prog}) {
  193. die "test.pl:runperl(): both 'prog' and 'progs' cannot be used " . _where()
  194. if defined $args{progs};
  195. $args{progs} = [$args{prog}]
  196. }
  197. if (defined $args{progs}) {
  198. die "test.pl:runperl(): 'progs' must be an ARRAYREF " . _where()
  199. unless ref $args{progs} eq "ARRAY";
  200. foreach my $prog (@{$args{progs}}) {
  201. if ($is_mswin || $is_netware || $is_vms) {
  202. $runperl .= qq ( -e "$prog" );
  203. }
  204. else {
  205. $runperl .= qq ( -e '$prog' );
  206. }
  207. }
  208. } elsif (defined $args{progfile}) {
  209. $runperl .= qq( "$args{progfile}");
  210. } else {
  211. # You probaby didn't want to be sucking in from the upstream stdin
  212. die "test.pl:runperl(): none of prog, progs, progfile, args, "
  213. . " switches or stdin specified"
  214. unless defined $args{args} or defined $args{switches}
  215. or defined $args{stdin};
  216. }
  217. if (defined $args{stdin}) {
  218. # so we don't try to put literal newlines and crs onto the
  219. # command line.
  220. $args{stdin} =~ s/\n/\\n/g;
  221. $args{stdin} =~ s/\r/\\r/g;
  222. if ($is_mswin || $is_netware || $is_vms) {
  223. $runperl = qq{$^X -e "print qq(} .
  224. $args{stdin} . q{)" | } . $runperl;
  225. }
  226. elsif ($is_macos) {
  227. # MacOS can only do two processes under MPW at once;
  228. # the test itself is one; we can't do two more, so
  229. # write to temp file
  230. my $stdin = qq{$^X -e 'print qq(} . $args{stdin} . qq{)' > teststdin; };
  231. if ($args{verbose}) {
  232. my $stdindisplay = $stdin;
  233. $stdindisplay =~ s/\n/\n\#/g;
  234. print STDERR "# $stdindisplay\n";
  235. }
  236. `$stdin`;
  237. $runperl .= q{ < teststdin };
  238. }
  239. else {
  240. $runperl = qq{$^X -e 'print qq(} .
  241. $args{stdin} . q{)' | } . $runperl;
  242. }
  243. }
  244. if (defined $args{args}) {
  245. _quote_args(\$runperl, $args{args});
  246. }
  247. $runperl .= ' 2>&1' if $args{stderr} && !$is_mswin && !$is_macos;
  248. $runperl .= " \xB3 Dev:Null" if !$args{stderr} && $is_macos;
  249. if ($args{verbose}) {
  250. my $runperldisplay = $runperl;
  251. $runperldisplay =~ s/\n/\n\#/g;
  252. print STDERR "# $runperldisplay\n";
  253. }
  254. return $runperl;
  255. }
  256. sub runperl {
  257. die "test.pl:runperl() does not take a hashref"
  258. if ref $_[0] and ref $_[0] eq 'HASH';
  259. my $runperl = &_create_runperl;
  260. # ${^TAINT} is invalid in perl5.00505
  261. my $tainted;
  262. eval '$tainted = ${^TAINT};' if $] >= 5.006;
  263. my %args = @_;
  264. exists $args{switches} && grep m/^-T$/, @{$args{switches}} and $tainted = $tainted + 1;
  265. if ($tainted) {
  266. # We will assume that if you're running under -T, you really mean to
  267. # run a fresh perl, so we'll brute force launder everything for you
  268. my $sep;
  269. eval "require Config; Config->import";
  270. if ($@) {
  271. warn "test.pl had problems loading Config: $@";
  272. $sep = ':';
  273. } else {
  274. $sep = $Config{path_sep};
  275. }
  276. my @keys = grep {exists $ENV{$_}} qw(CDPATH IFS ENV BASH_ENV);
  277. local @ENV{@keys} = ();
  278. # Untaint, plus take out . and empty string:
  279. local $ENV{'DCL$PATH'} = $1 if $is_vms && ($ENV{'DCL$PATH'} =~ /(.*)/s);
  280. $ENV{PATH} =~ /(.*)/s;
  281. local $ENV{PATH} =
  282. join $sep, grep { $_ ne "" and $_ ne "." and -d $_ and
  283. ($is_mswin or $is_vms or !(stat && (stat _)[2]&0022)) }
  284. split quotemeta ($sep), $1;
  285. $ENV{PATH} .= "$sep/bin" if $is_cygwin; # Must have /bin under Cygwin
  286. $runperl =~ /(.*)/s;
  287. $runperl = $1;
  288. my ($err,$result,$stderr) = run_cmd($runperl, $args{timeout});
  289. $result =~ s/\n\n/\n/ if $is_vms; # XXX pipes sometimes double these
  290. return $result;
  291. } else {
  292. my ($err,$result,$stderr) = run_cmd($runperl, $args{timeout});
  293. $result =~ s/\n\n/\n/ if $is_vms; # XXX pipes sometimes double these
  294. return $result;
  295. }
  296. }
  297. *run_perl = \&runperl; # Nice alias.
  298. sub DIE {
  299. print STDERR "# @_\n";
  300. exit 1;
  301. }
  302. # A somewhat safer version of the sometimes wrong $^X.
  303. my $Perl;
  304. sub which_perl {
  305. unless (defined $Perl) {
  306. $Perl = $^X;
  307. # VMS should have 'perl' aliased properly
  308. return $Perl if $^O eq 'VMS';
  309. my $exe;
  310. eval "require Config; Config->import";
  311. if ($@) {
  312. warn "test.pl had problems loading Config: $@";
  313. $exe = '';
  314. } else {
  315. $exe = $Config{exe_ext};
  316. }
  317. $exe = '' unless defined $exe;
  318. # This doesn't absolutize the path: beware of future chdirs().
  319. # We could do File::Spec->abs2rel() but that does getcwd()s,
  320. # which is a bit heavyweight to do here.
  321. if ($Perl =~ /^perl\Q$exe\E$/i) {
  322. my $perl = "perl$exe";
  323. eval "require File::Spec";
  324. if ($@) {
  325. warn "test.pl had problems loading File::Spec: $@";
  326. $Perl = "./$perl";
  327. } else {
  328. $Perl = File::Spec->catfile(File::Spec->curdir(), $perl);
  329. }
  330. }
  331. # Build up the name of the executable file from the name of
  332. # the command.
  333. if ($Perl !~ /\Q$exe\E$/i) {
  334. $Perl .= $exe;
  335. }
  336. warn "which_perl: cannot find $Perl from $^X" unless -f $Perl;
  337. # For subcommands to use.
  338. $ENV{PERLEXE} = $Perl;
  339. }
  340. return $Perl;
  341. }
  342. sub unlink_all {
  343. my $count = 0;
  344. foreach my $file (@_) {
  345. 1 while unlink $file;
  346. if( -f $file ){
  347. print STDERR "# Couldn't unlink '$file': $!\n";
  348. }else{
  349. ++$count;
  350. }
  351. }
  352. $count;
  353. }
  354. my %tmpfiles;
  355. END { unlink_all keys %tmpfiles }
  356. # A regexp that matches the tempfile names
  357. $::tempfile_regexp = 'tmp\d+[A-Z][A-Z]?';
  358. # Avoid ++, avoid ranges, avoid split //
  359. my @letters = qw(A B C D E F G H I J K L M N O P Q R S T U V W X Y Z);
  360. sub tempfile {
  361. my $count = 0;
  362. do {
  363. my $temp = $count;
  364. my $try = "tmp$$";
  365. do {
  366. $try = $try . $letters[$temp % 26];
  367. $temp = int ($temp / 26);
  368. } while $temp;
  369. # Need to note all the file names we allocated, as a second request may
  370. # come before the first is created.
  371. if (!-e $try && !$tmpfiles{$try}) {
  372. # We have a winner
  373. $tmpfiles{$try} = 1;
  374. return $try;
  375. }
  376. $count = $count + 1;
  377. } while $count < 26 * 26;
  378. die "Can't find temporary file name starting 'tmp$$'";
  379. }
  380. # This is the temporary file for _fresh_perl
  381. my $tmpfile = tempfile();
  382. #
  383. # _fresh_perl
  384. #
  385. # The $resolve must be a subref that tests the first argument
  386. # for success, or returns the definition of success (e.g. the
  387. # expected scalar) if given no arguments.
  388. #
  389. sub _fresh_perl {
  390. my($prog, $resolve, $runperl_args, $name) = @_;
  391. $runperl_args ||= {};
  392. $runperl_args->{progfile} = $tmpfile;
  393. $runperl_args->{stderr} = 1;
  394. open TEST, ">", $tmpfile or die "Cannot open $tmpfile: $!";
  395. # VMS adjustments
  396. if( $^O eq 'VMS' ) {
  397. $prog =~ s#/dev/null#NL:#;
  398. # VMS file locking
  399. $prog =~ s{if \(-e _ and -f _ and -r _\)}
  400. {if (-e _ and -f _)}
  401. }
  402. print TEST $prog;
  403. close TEST or die "Cannot close $tmpfile: $!";
  404. my $results = runperl(%$runperl_args);
  405. my $status = $?;
  406. # Clean up the results into something a bit more predictable.
  407. $results =~ s/\n+$//;
  408. $results =~ s/at\s+misctmp\d+\s+line/at - line/g;
  409. $results =~ s/of\s+misctmp\d+\s+aborted/of - aborted/g;
  410. # bison says 'parse error' instead of 'syntax error',
  411. # various yaccs may or may not capitalize 'syntax'.
  412. $results =~ s/^(syntax|parse) error/syntax error/mig;
  413. if ($^O eq 'VMS') {
  414. # some tests will trigger VMS messages that won't be expected
  415. $results =~ s/\n?%[A-Z]+-[SIWEF]-[A-Z]+,.*//;
  416. # pipes double these sometimes
  417. $results =~ s/\n\n/\n/g;
  418. }
  419. my $pass = $resolve->($results);
  420. unless ($pass) {
  421. diag "# PROG: \n$prog\n";
  422. diag "# EXPECTED:\n", $resolve->(), "\n";
  423. diag "# GOT:\n$results\n";
  424. diag "# STATUS: $status\n";
  425. }
  426. # Use the first line of the program as a name if none was given
  427. unless( $name ) {
  428. ($first_line, $name) = $prog =~ /^((.{1,50}).*)/;
  429. $name .= '...' if length $first_line > length $name;
  430. }
  431. ok($pass, "fresh_perl - $name");
  432. }
  433. #
  434. # fresh_perl_is
  435. #
  436. # Combination of run_perl() and is().
  437. #
  438. sub fresh_perl_is {
  439. my($prog, $expected, $runperl_args, $name) = @_;
  440. local $Level = 2;
  441. _fresh_perl($prog,
  442. sub { @_ ? $_[0] eq $expected : $expected },
  443. $runperl_args, $name);
  444. }
  445. #
  446. # fresh_perl_like
  447. #
  448. # Combination of run_perl() and like().
  449. #
  450. sub fresh_perl_like {
  451. my($prog, $expected, $runperl_args, $name) = @_;
  452. local $Level = 2;
  453. _fresh_perl($prog,
  454. sub { @_ ?
  455. $_[0] =~ (ref $expected ? $expected : /$expected/) :
  456. $expected },
  457. $runperl_args, $name);
  458. }
  459. # now my new B::C functions
  460. sub run_cmd {
  461. my ($cmd, $timeout) = @_;
  462. my ($result, $out, $err) = (0, '', '');
  463. if ( ! defined $IPC::Run::VERSION ) {
  464. local $@;
  465. if (ref($cmd) eq 'ARRAY') {
  466. $cmd = join " ", @$cmd;
  467. }
  468. # No real way to trap STDERR?
  469. $cmd .= " 2>&1" if ($^O !~ /^MSWin32|VMS/);
  470. warn $cmd."\n" if $ENV{TEST_VERBOSE};
  471. $out = `$cmd`;
  472. warn $out."\n" if $ENV{TEST_VERBOSE};
  473. $result = $?;
  474. }
  475. else {
  476. my $in;
  477. # XXX TODO this fails with spaces in path. pass and check ARRAYREF then
  478. my @cmd = ref($cmd) eq 'ARRAY' ? @$cmd : split /\s+/, $cmd;
  479. warn join(" ", @cmd)."\n" if $ENV{TEST_VERBOSE};
  480. eval {
  481. # XXX TODO hanging or stacktrace'd children are not killed on cygwin
  482. my $h = IPC::Run::start(\@cmd, \$in, \$out, \$err);
  483. if ($timeout) {
  484. my $secs10 = $timeout/10;
  485. for (1..$secs10) {
  486. if(!$h->pumpable) {
  487. last;
  488. }
  489. else {
  490. $h->pump_nb;
  491. diag sprintf("waiting %d[s]",$_*10) if $_ > 30;
  492. sleep 10;
  493. }
  494. }
  495. if($h->pumpable) {
  496. $h->kill_kill;
  497. $err .= "Timed out waiting for process exit";
  498. }
  499. }
  500. $h->finish or die "cmd returned $?";
  501. $result = $h->result(0);
  502. };
  503. warn $out."\n" if $ENV{TEST_VERBOSE};
  504. $err .= "\$\@ = $@" if($@);
  505. warn $err."\n" if $ENV{TEST_VERBOSE};
  506. }
  507. return ($result, $out, $err);
  508. }
  509. sub Mblib {
  510. $^O eq 'MSWin32' ? '-Iblib\arch -Iblib\lib' : "-Iblib/arch -Iblib/lib";
  511. }
  512. sub tests {
  513. my $in = shift || "t/TESTS";
  514. $in = "TESTS" unless -f $in;
  515. undef $/;
  516. open TEST, "< $in" or die "Cannot open $in";
  517. my @tests = split /\n####+.*##\n/, <TEST>;
  518. close TEST;
  519. delete $tests[$#tests] unless $tests[$#tests];
  520. @tests;
  521. }
  522. sub run_cc_test {
  523. my ($cnt, $backend, $script, $expect, $keep_c, $keep_c_fail, $todo) = @_;
  524. my ($opt, $got);
  525. local($\, $,); # guard against -l and other things that screw with
  526. # print
  527. $expect =~ s/\n$//;
  528. my ($out,$result,$stderr) = ('');
  529. my $fnbackend = lc($backend); #C,-O2
  530. ($fnbackend,$opt) = $fnbackend =~ /^(cc?)(,-o.)?/;
  531. $opt =~ s/,-/_/ if $opt;
  532. $opt = '' unless $opt;
  533. use Config;
  534. require B::C::Flags;
  535. # note that the smokers run the c.t and c_o3.t tests in parallel, with possible
  536. # interleaving file writes even for the .pl.
  537. my $test = $fnbackend."code".$cnt.$opt.".pl";
  538. my $cfile = $fnbackend."code".$cnt.$opt.".c";
  539. my @obj;
  540. @obj = ($fnbackend."code".$cnt.$opt.".obj",
  541. $fnbackend."code".$cnt.$opt.".ilk",
  542. $fnbackend."code".$cnt.$opt.".pdb")
  543. if $Config{cc} =~ /^cl/i; # MSVC uses a lot of intermediate files
  544. my $exe = $fnbackend."code".$cnt.$opt.$Config{exe_ext};
  545. unlink ($test, $cfile, $exe, @obj);
  546. open T, ">", $test; print T $script; close T;
  547. # Being able to test also the CORE B in older perls
  548. my $Mblib = $] >= 5.009005 ? Mblib() : "";
  549. my $useshrplib = $Config{useshrplib} eq 'true';
  550. unless ($Mblib) { # check for -Mblib from the testsuite
  551. if (grep { m{blib(/|\\)arch$} } @INC) {
  552. $Mblib = Mblib(); # forced -Mblib via cmdline without
  553. # printing to stderr
  554. $backend = "-qq,$backend,-q" if !$ENV{TEST_VERBOSE} and $] > 5.007;
  555. }
  556. } else {
  557. $backend = "-qq,$backend,-q" if !$ENV{TEST_VERBOSE} and $] > 5.007;
  558. }
  559. $backend .= ",-fno-warnings" if $] >= 5.013005;
  560. $backend .= ",-fno-fold" if $] >= 5.013009;
  561. $got = run_perl(switches => [ "$Mblib -MO=$backend,-o${cfile}" ],
  562. verbose => $ENV{TEST_VERBOSE}, # for debugging
  563. nolib => $ENV{PERL_CORE} ? 0 : 1, # include ../lib only in CORE
  564. stderr => 1, # to capture the "ccode.pl syntax ok"
  565. timeout => 120,
  566. progfile => $test);
  567. if (! $? and -s $cfile) {
  568. use ExtUtils::Embed ();
  569. my $command = ExtUtils::Embed::ccopts;
  570. $command .= " -DHAVE_INDEPENDENT_COMALLOC "
  571. if $B::C::Flags::have_independent_comalloc;
  572. $command .= " -o $exe $cfile ".$B::C::Flags::extra_cflags . " ";
  573. if ($Config{cc} eq 'cl') {
  574. if ($^O eq 'MSWin32' and $Config{ccversion} eq '12.0.8804' and $Config{cc} eq 'cl') {
  575. $command =~ s/ -opt:ref,icf//;
  576. }
  577. my $obj = $obj[0];
  578. $command =~ s/ \Q-o $exe\E / -c -Fo$obj /;
  579. my $cmdline = "$Config{cc} $command";
  580. diag ($cmdline) if $ENV{TEST_VERBOSE} and $ENV{TEST_VERBOSE} == 2;
  581. run_cmd($cmdline, 20);
  582. $command = '';
  583. }
  584. my $coredir = $ENV{PERL_SRC} || File::Spec->catdir($Config{installarchlib}, "CORE");
  585. my $libdir = File::Spec->catdir($Config{prefix}, "lib");
  586. my $so = $Config{so};
  587. my $linkargs = ExtUtils::Embed::ldopts('-std');
  588. # At least cygwin gcc-4.3 crashes with 2x -fstack-protector
  589. $linkargs =~ s/-fstack-protector\b//
  590. if $command =~ /-fstack-protector\b/ and $linkargs =~ /-fstack-protector\b/;
  591. if ( -e "$coredir/$Config{libperl}" and $Config{libperl} !~ /\.$so$/) {
  592. $command .= $linkargs;
  593. } elsif ( $useshrplib and (-e "$libdir/$Config{libperl}" or -e "/usr/lib/$Config{libperl}")) {
  594. # debian: /usr/lib/libperl.so.5.10.1 and broken ExtUtils::Embed::ldopts
  595. if ($Config{libperl} =~ /\.$so$/) {
  596. my $libperl = File::Spec->catfile($coredir, $Config{libperl});
  597. $linkargs =~ s|-lperl |$libperl |; # link directly
  598. }
  599. $command .= $linkargs;
  600. } else {
  601. $command .= $linkargs;
  602. $command .= " -lperl" if $command !~ /(-lperl|CORE\/libperl5)/ and $^O ne 'MSWin32';
  603. }
  604. $command .= $B::C::Flags::extra_libs;
  605. my $NULL = $^O eq 'MSWin32' ? '' : '2>/dev/null';
  606. my $cmdline = "$Config{cc} $command $NULL";
  607. if ($Config{cc} eq 'cl') {
  608. $cmdline = "$Config{ld} $linkargs -out:$exe $obj[0] $command";
  609. }
  610. diag ($cmdline) if $ENV{TEST_VERBOSE} and $ENV{TEST_VERBOSE} == 2;
  611. run_cmd($cmdline, 20);
  612. unless (-e $exe) {
  613. print "not ok $cnt $todo failed $cmdline\n";
  614. print STDERR "# ",system("$Config{cc} $command"), "\n";
  615. #unlink ($test, $cfile, $exe, @obj) unless $keep_c_fail;
  616. return 0;
  617. }
  618. $exe = "./".$exe unless $^O eq 'MSWin32';
  619. # system("/bin/bash -c ulimit -d 1000000") if -e "/bin/bash";
  620. ($result,$out,$stderr) = run_cmd($exe, 5);
  621. if (defined($out) and !$result) {
  622. if ($out =~ /^$expect$/) {
  623. print "ok $cnt", $todo eq '#' ? "\n" : " $todo\n";
  624. unlink ($test, $cfile, $exe, @obj) unless $keep_c;
  625. return 1;
  626. } else {
  627. # cc test failed, double check uncompiled
  628. $got = run_perl(verbose => $ENV{TEST_VERBOSE}, # for debugging
  629. nolib => $ENV{PERL_CORE} ? 0 : 1, # include ../lib only in CORE
  630. stderr => 1, # to capture the "ccode.pl syntax ok"
  631. timeout => 10,
  632. progfile => $test);
  633. if (! $? and $got =~ /^$expect$/) {
  634. print "not ok $cnt $todo wanted: \"$expect\", got: \"$out\"\n";
  635. } else {
  636. print "ok $cnt # skip also fails uncompiled\n";
  637. return 1;
  638. }
  639. unlink ($test, $cfile, $exe, @obj) unless $keep_c_fail;
  640. return 0;
  641. }
  642. } else {
  643. $out = '';
  644. }
  645. }
  646. print "not ok $cnt $todo wanted: \"$expect\", \$\? = $?, got: \"$out\"\n";
  647. if ($stderr) {
  648. $stderr =~ s/\n./\n# /xmsg;
  649. print "# $stderr\n";
  650. }
  651. unlink ($test, $cfile, $exe, @obj) unless $keep_c_fail;
  652. return 0;
  653. }
  654. sub prepare_c_tests {
  655. BEGIN {
  656. use Config;
  657. if ($^O eq 'VMS') {
  658. print "1..0 # skip - B::C doesn't work on VMS\n";
  659. exit 0;
  660. }
  661. if (($Config{'extensions'} !~ /\bB\b/) ) {
  662. print "1..0 # Skip -- Perl configured without B module\n";
  663. exit 0;
  664. }
  665. # with 5.10 and 5.8.9 PERL_COPY_ON_WRITE was renamed to PERL_OLD_COPY_ON_WRITE
  666. if ($Config{ccflags} =~ /-DPERL_OLD_COPY_ON_WRITE/) {
  667. print "1..0 # skip - no OLD COW for now\n";
  668. exit 0;
  669. }
  670. }
  671. }
  672. sub run_c_tests {
  673. my $backend = $_[0];
  674. my @todo = @{$_[1]};
  675. my @skip = @{$_[2]};
  676. use Config;
  677. my $AUTHOR = (-d ".git" and !$ENV{NO_AUTHOR}) ? 1 : 0;
  678. my $keep_c = 0; # set it to keep the pl, c and exe files
  679. my $keep_c_fail = 1; # keep on failures
  680. my %todo = map { $_ => 1 } @todo;
  681. my %skip = map { $_ => 1 } @skip;
  682. my @tests = tests();
  683. # add some CC specific tests after 100
  684. # perl -lne "/^\s*sub pp_(\w+)/ && print \$1" lib/B/CC.pm > ccpp
  685. # for p in `cat ccpp`; do echo -n "$p "; grep -m1 " $p[(\[ ]" *.concise; done
  686. #
  687. # grep -A1 "coverage: ny" lib/B/CC.pm|grep sub
  688. # pp_stub pp_cond_expr pp_dbstate pp_reset pp_stringify pp_ncmp pp_preinc
  689. # pp_formline pp_enterwrite pp_leavewrite pp_entergiven pp_leavegiven
  690. # pp_dofile pp_grepstart pp_mapstart pp_grepwhile pp_mapwhile
  691. if ($backend =~ /^CC/) {
  692. local $/;
  693. my $cctests = <<'CCTESTS';
  694. my ($r_i,$i_i,$d_d)=(0,2,3.0); $r_i=$i_i*$i_i; $r_i*=$d_d; print $r_i;
  695. >>>>
  696. 12
  697. ######### 101 - CC types and arith ###############
  698. if ($x eq "2"){}else{print "ok"}
  699. >>>>
  700. ok
  701. ######### 102 - CC cond_expr,stub,scope ############
  702. require B; my $x=1e1; my $s="$x"; print ref B::svref_2object(\$s)
  703. >>>>
  704. B::PV
  705. ######### 103 - CC stringify srefgen ############
  706. @a=(1..4);while($a=shift@a){print $a;}continue{$a=~/2/ and reset q(a);}
  707. >>>>
  708. 12
  709. ######### 104 CC reset ###############################
  710. use blib;use B::CC;my int $r;my $i:int=2;our double $d=3.0; $r=$i*$i; $r*=$d; print $r;
  711. >>>>
  712. 12
  713. ######### 105 CC attrs ###############################
  714. my $s=q{ok};END{print $s}END{$x = 0}
  715. >>>>
  716. ok
  717. ######### 106 CC 296/297 ###############################
  718. CCTESTS
  719. my $i = 100;
  720. for (split /\n####+.*##\n/, $cctests) {
  721. next unless $_;
  722. $tests[$i] = $_;
  723. $i++;
  724. }
  725. }
  726. print "1..".(scalar @tests)."\n";
  727. my $cnt = 1;
  728. for (@tests) {
  729. my $todo = $todo{$cnt} ? "#TODO" : "#";
  730. # skip empty CC holes to have the same test indices in STATUS and t/testcc.sh
  731. unless ($_) {
  732. print sprintf("ok %d # skip hole for CC\n", $cnt);
  733. $cnt++;
  734. next;
  735. }
  736. # only once. skip subsequent tests 29 on MSVC. 7:30min!
  737. if ($cnt == 29 and !$AUTHOR) {
  738. $todo{$cnt} = $skip{$cnt} = 1;
  739. }
  740. if ($todo{$cnt} and $skip{$cnt} and
  741. # those are currently blocking the system
  742. # do not even run them at home if TODO+SKIP
  743. (!$AUTHOR
  744. or ($cnt==15 and $backend eq 'C,-O1') # hanging
  745. or ($cnt==103 and $backend eq 'CC,-O2') # hanging
  746. ))
  747. {
  748. print sprintf("ok %d # skip\n", $cnt);
  749. } else {
  750. my ($script, $expect) = split />>>+\n/;
  751. die "Invalid empty t/TESTS" if !$script or $expect eq '';
  752. if ($cnt == 4 and $] >= 5.017005) {
  753. $expect = 'zzz2y2y2';
  754. }
  755. run_cc_test($cnt, $backend.($cnt == 46 ? ',-fstash' : ''),
  756. $script, $expect, $keep_c, $keep_c_fail, $todo);
  757. }
  758. $cnt++;
  759. }
  760. }
  761. sub plctestok {
  762. my ($num, $base, $script, $todo) = @_;
  763. plctest($num,'^ok', $base, $script, $todo);
  764. }
  765. sub plctest {
  766. my ($num, $expected, $base, $script, $todo) = @_;
  767. my $name = $base."_$num";
  768. unlink($name, "$name.plc", "$name.pl", "$name.exe");
  769. open F, ">", "$base.pl";
  770. print F $script;
  771. print F "\n";
  772. close F;
  773. my $runperl = $^X =~ m/\s/ ? qq{"$^X"} : $^X;
  774. # we don't want to change STDOUT/STDERR on STDOUT/STDERR tests, so no -qq
  775. my $nostdoutclobber = $base !~ /^ccode93i/;
  776. my $b = ($] > 5.008 and $nostdoutclobber) ? "-qq,Bytecode" : "Bytecode";
  777. my $Mblib = Mblib;
  778. my $cmd = "$runperl $Mblib -MO=$b,-o$name.plc $base.pl";
  779. diag($cmd) if $ENV{TEST_VERBOSE} and $ENV{TEST_VERBOSE} > 1;
  780. system $cmd;
  781. # $out =~ s/^$base.pl syntax OK\n//m;
  782. unless (-e "$name.plc") {
  783. print "not ok $num #B::Bytecode failed\n";
  784. exit;
  785. }
  786. $cmd = "$runperl $Mblib -MByteLoader $name.plc";
  787. diag($cmd) if $ENV{TEST_VERBOSE} and $ENV{TEST_VERBOSE} > 1;
  788. my $out = qx($cmd);
  789. chomp $out;
  790. my $ok = $out =~ /$expected/;
  791. if ($todo and $todo =~ /TODO/) {
  792. $todo =~ s/TODO //;
  793. TODO: {
  794. local $TODO = $todo;
  795. ok($ok);
  796. }
  797. } else {
  798. ok($ok, $todo ? "$todo" : '');
  799. }
  800. if ($ok) {
  801. unlink("$name.plc", "$base.pl");
  802. }
  803. }
  804. sub ctestok {
  805. my ($num, $backend, $base, $script, $todo) = @_;
  806. my $qr = '^ok'; # how lame
  807. ctest($num, $qr, $backend, $base, $script, $todo);
  808. }
  809. sub ctest {
  810. my ($num, $expected, $backend, $base, $script, $todo) = @_;
  811. my $name = $base."_$num";
  812. my $b = $backend; # protect against parallel test name clashes
  813. $b =~ s/-(D.*|f.*|v),//g;
  814. $b =~ s/-/_/g;
  815. $b =~ s/[, ]//g;
  816. $b = lc($b);
  817. $name .= $b;
  818. unlink($name, "$name.c", "$name.pl", "$name.exe");
  819. open F, ">", "$name.pl";
  820. print F $script;
  821. close F;
  822. my $runperl = $^X =~ m/\s/ ? qq{"$^X"} : $^X;
  823. # we don't want to change STDOUT/STDERR on STDOUT/STDERR tests, so no -qq
  824. my $nostdoutclobber = $base !~ /^ccode93i/;
  825. my $post = '';
  826. $b = ($] > 5.008 and $nostdoutclobber) ? "-qq,$backend" : "$backend";
  827. ($b, $post) = split(" ", $b);
  828. $post = '' unless $post;
  829. $b .= q(,-fno-fold,-fno-warnings) if $] >= 5.013005 and $b !~ /-(O3|ffold|fwarnings)/;
  830. diag("$runperl ".Mblib." -MO=$b,-o$name.c $post $name.pl")
  831. if $ENV{TEST_VERBOSE} and $ENV{TEST_VERBOSE} > 1;
  832. system "$runperl ".Mblib." -MO=$b,-o$name.c $post $name.pl";
  833. unless (-e "$name.c") {
  834. print "not ok $num #B::$backend failed\n";
  835. exit;
  836. }
  837. diag("$runperl ".Mblib." blib/script/cc_harness -q -o $name $name.c")
  838. if $ENV{TEST_VERBOSE} and $ENV{TEST_VERBOSE} > 1;
  839. system "$runperl ".Mblib." blib/script/cc_harness -q -o $name $name.c";
  840. my $exe = $name.$Config{exe_ext};
  841. unless (-e $exe) {
  842. if ($todo and $todo =~ /TODO/) {
  843. $todo =~ s/TODO //;
  844. TODO: {
  845. local $TODO = $todo;
  846. ok(undef, "failed to compile");
  847. }
  848. } else {
  849. ok(undef, "failed to compile $todo");
  850. }
  851. return;
  852. }
  853. $exe = "./".$exe unless $^O eq 'MSWin32';
  854. ($result,$out,$stderr) = run_cmd($exe, 5);
  855. my $ok;
  856. if (defined($out) and !$result) {
  857. chomp $out;
  858. $ok = $out =~ /$expected/;
  859. diag($out) if $ENV{TEST_VERBOSE};
  860. unless ($ok) { #crosscheck uncompiled
  861. my $out1 = `$runperl $name.pl`;
  862. unless ($out1 =~ /$expected/) {
  863. ok(1, "skip also fails uncompiled $todo");
  864. return 1;
  865. }
  866. }
  867. if ($todo and $todo =~ /TODO/) {
  868. $todo =~ s/TODO //;
  869. TODO: {
  870. local $TODO = $todo;
  871. ok ($out =~ /$expected/);
  872. diag($out) if $ENV{TEST_VERBOSE};
  873. }
  874. } else {
  875. ok ($out =~ /$expected/, $todo);
  876. }
  877. } else {
  878. if ($todo and $todo =~ /TODO/) {
  879. $todo =~ s/TODO //;
  880. TODO: {
  881. local $TODO = $todo;
  882. ok (undef);
  883. }
  884. } else {
  885. #crosscheck uncompiled
  886. my $out1 = `$runperl $name.pl`;
  887. unless ($out1 =~ /$expected/) {
  888. ok(1, "skip also fails uncompiled");
  889. return $ok;
  890. }
  891. ok (undef, $todo);
  892. }
  893. }
  894. unlink("$name.pl");
  895. if ($ok) {
  896. unlink($name, "$name.c", "$name.exe");
  897. }
  898. $ok
  899. }
  900. sub ccompileok {
  901. my ($num, $backend, $base, $script, $todo) = @_;
  902. my $name = $base."_$num";
  903. unlink($name, "$name.c", "$name.pl", "$name.exe");
  904. open F, ">", "$name.pl";
  905. print F $script;
  906. close F;
  907. my $runperl = $^X =~ m/\s/ ? qq{"$^X"} : $^X;
  908. my $b = $] > 5.008 ? "-qq,$backend" : "$backend";
  909. my $Mblib = Mblib;
  910. system "$runperl $Mblib -MO=$b,-o$name.c $name.pl";
  911. unless (-e "$name.c") {
  912. print "not ok 1 #B::$backend failed\n";
  913. exit;
  914. }
  915. system "$runperl $Mblib blib/script/cc_harness -q -o $name $name.c";
  916. my $ok = -e $name or -e "$name.exe";
  917. if ($todo and $todo =~ /TODO/) {
  918. TODO: {
  919. $todo =~ s/TODO //;
  920. local $TODO = $todo;
  921. ok($ok);
  922. }
  923. } else {
  924. ok($ok, $todo);
  925. }
  926. unlink("$name.pl");
  927. if ($ok) {
  928. unlink($name, "$name.c", "$name.exe");
  929. }
  930. }
  931. sub todo_tests_default {
  932. my $what = shift;
  933. my $DEBUGGING = ($Config{ccflags} =~ m/-DDEBUGGING/);
  934. my $ITHREADS = ($Config{useithreads});
  935. my @todo = ();
  936. # no IO::Scalar
  937. push @todo, (15) if $] < 5.007;
  938. # broken by fbb32b8bebe8ad C: revert *-,*+,*! fetch magic, assign all core GVs to their global symbols
  939. push @todo, (42..43) if $] < 5.012;
  940. if ($what =~ /^c(|_o[1-4])$/) {
  941. # a regression
  942. push @todo, (41) if $] < 5.007; #regressions
  943. push @todo, (12) if $what eq 'c_o3' and !$ITHREADS and $] >= 5.008009 and $] < 5.010;
  944. push @todo, (48) if $what eq 'c_o4' and $ITHREADS;
  945. push @todo, (8,18,19,25,26,28) if $what eq 'c_o4' and !$ITHREADS;
  946. } elsif ($what =~ /^cc/) {
  947. push @todo, (21,30,105,106);
  948. push @todo, (22,41,45,103) if $] < 5.007; #regressions
  949. push @todo, (104,105) if $] < 5.007; # leaveloop, no cxstack
  950. push @todo, (42,43) if $] > 5.008 and $] <= 5.008005 and !$ITHREADS;
  951. #push @todo, (33,45) if $] >= 5.010 and $] < 5.012;
  952. push @todo, (10,16,50) if $what eq 'cc_o2';
  953. push @todo, (29) if $] < 5.008008;
  954. push @todo, (22) if $] < 5.010 and !$ITHREADS;
  955. push @todo, (46); # HvKEYS(%Exporter::) is 0 unless Heavy is included also
  956. # solaris also. I suspected nvx<=>cop_seq_*
  957. push @todo, (12) if $^O eq 'MSWin32' and $Config{cc} =~ /^cl/i;
  958. push @todo, (26) if $what =~ /^cc_o[12]/;
  959. push @todo, (27) if $] > 5.008008 and $] < 5.009;
  960. push @todo, (27) if $] > 5.008008 and $] < 5.009 and $what eq 'cc_o2';
  961. push @todo, (103) if ($] >= 5.012 and $] < 5.014 and !$ITHREADS);
  962. push @todo, (12,19,25) if $] >= 5.019;
  963. }
  964. push @todo, (48) if $] > 5.007 and $] < 5.009 and $^O =~ /MSWin32|cygwin/i;
  965. return @todo;
  966. }
  967. 1;
  968. # Local Variables:
  969. # mode: cperl
  970. # cperl-indent-level: 4
  971. # fill-column: 78
  972. # End:
  973. # vim: expandtab shiftwidth=4: