e_perlcc.t 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. # -*- cperl -*-
  2. # t/e_perlcc.t - after c, before i(ssue*.t) and m(modules.t)
  3. # test most perlcc options
  4. use strict;
  5. use Test::More tests => 76;
  6. use Config;
  7. my $usedl = $Config{usedl} eq 'define';
  8. my $X = $^X =~ m/\s/ ? qq{"$^X"} : $^X;
  9. # TODO: no global output 'a' and 'a.c' to enable parallel testing (test speedup)
  10. my $exe = $^O =~ /MSWin32|cygwin|msys/ ? 'pcc.exe' : './pcc';
  11. my $a_exe = $^O =~ /MSWin32|cygwin|msys/ ? 'a.exe' : './a.out';
  12. my $a = $^O eq 'MSWin32' ? 'pcc.exe' : './pcc';
  13. my $redir = $^O eq 'MSWin32' ? '' : '2>&1';
  14. my $devnull = $^O eq 'MSWin32' ? '' : '2>/dev/null';
  15. #my $o = '';
  16. #$o = "-Wb=-fno-warnings" if $] >= 5.013005;
  17. #$o = "-Wb=-fno-fold,-fno-warnings" if $] >= 5.013009;
  18. my $perlcc = "$X -Iblib/arch -Iblib/lib blib/script/perlcc";
  19. sub cleanup { unlink ('pcc.c','pcc.c.lst','a.out.c', "a.c", $exe, $a, "a.out.c.lst", "a.c.lst"); }
  20. my $e = q("print q(ok)");
  21. is(`$perlcc -S -o pcc -r -e $e $devnull`, "ok", "-S -o pcc -r -e");
  22. ok(-e 'pcc.c', "-S => pcc.c file");
  23. ok(-e $a, "keep pcc executable"); #3
  24. cleanup;
  25. is(`$perlcc -o pcc -r -e $e $devnull`, "ok", "-o pcc r -e");
  26. ok(! -e 'pcc.c', "no pcc.c file");
  27. ok(-e $a, "keep pcc executable"); # 6
  28. cleanup;
  29. my @c = <*.c>;
  30. is(`$perlcc -r -e $e $devnull`, "ok", "-r -e"); #7
  31. my @c1 = <*.c>;
  32. is(length @c, length @c1, "no temp cfile");
  33. ok(-e $a_exe, "keep default executable"); #9
  34. cleanup;
  35. system(qq($perlcc -o pcc -e $e $devnull));
  36. ok(-e $a, '-o pcc -e');
  37. is(`$a`, "ok", "$a => ok"); #11
  38. cleanup;
  39. # Try a simple XS module which exists in 5.6.2 and blead (test 45)
  40. $e = q("use Data::Dumper ();Data::Dumper::Dumpxs({});print q(ok)");
  41. is(`$perlcc -r -e $e $devnull`, "ok", "-r xs ".($usedl ? "dynamic" : "static")); #12
  42. cleanup;
  43. SKIP: {
  44. #skip "--staticxs hangs on darwin", 10 if $^O eq 'darwin';
  45. TODO: {
  46. # fails 5.8 and darwin, msvc also
  47. local $TODO = '--staticxs is experimental' if $^O eq 'darwin' or $] < 5.010;
  48. is(`$perlcc --staticxs -r -e $e $devnull`, "ok", "-r --staticxs xs"); #13
  49. ok(-e $a_exe, "keep default executable"); #14
  50. }
  51. ok(! -e 'a.out.c', "delete a.out.c file without -S");
  52. ok(! -e 'a.out.c.lst', "delete a.out.c.lst without -S");
  53. cleanup;
  54. TODO: {
  55. local $TODO = '--staticxs is experimental' if $^O eq 'darwin' or $] < 5.010;
  56. is(`$perlcc --staticxs -S -o pcc -r -e $e $devnull`, "ok",
  57. "-S -o -r --staticxs xs"); #17
  58. ok(-e $a, "keep executable"); #18
  59. }
  60. ok(-e 'pcc.c', "keep pcc.c file with -S");
  61. ok(-e 'pcc.c.lst', "keep pcc.c.lst with -S");
  62. cleanup;
  63. is(`$perlcc --staticxs -S -o pcc -O3 -r -e "print q(ok)" $devnull`, "ok",
  64. "-S -o -r --staticxs without xs");
  65. TODO: {
  66. local $TODO = '5.18' if $] >= 5.018;
  67. ok(! -e 'pcc.c.lst', "no pcc.c.lst without xs"); #22
  68. }
  69. cleanup;
  70. }
  71. my $f = "pcc.pl";
  72. open F,">",$f;
  73. print F q(print q(ok));
  74. close F;
  75. $e = q("print q(ok)");
  76. is(`$perlcc -S -o pcc -r $f $devnull`, "ok", "-S -o -r file");
  77. ok(-e 'pcc.c', "-S => pcc.c file");
  78. cleanup;
  79. is(`$perlcc -o pcc -r $f $devnull`, "ok", "-r -o file");
  80. ok(! -e 'pcc.c', "no pcc.c file");
  81. ok(-e $a, "keep executable");
  82. cleanup;
  83. is(`$perlcc -o pcc $f $devnull`, "", "-o file");
  84. ok(! -e 'pcc.c', "no pcc.c file");
  85. ok(-e $a, "executable");
  86. is(`$a`, "ok", "./pcc => ok");
  87. cleanup;
  88. is(`$perlcc -S -o pcc $f $devnull`, "", "-S -o file");
  89. ok(-e $a, "executable");
  90. is(`$a`, "ok", "./pcc => ok");
  91. cleanup;
  92. is(`$perlcc -Sc -o pcc $f $devnull`, "", "-Sc -o file");
  93. ok(-e 'pcc.c', "pcc.c file");
  94. ok(! -e $a, "-Sc no executable, compile only");
  95. cleanup;
  96. is(`$perlcc -c -o pcc $f $devnull`, "", "-c -o file");
  97. ok(-e 'pcc.c', "pcc.c file");
  98. ok(! -e $a, "-c no executable, compile only"); #40
  99. cleanup;
  100. #SKIP: {
  101. TODO: {
  102. #skip "--stash hangs < 5.12", 3 if $] < 5.012; #because of DB?
  103. #skip "--stash hangs >= 5.14", 3 if $] >= 5.014; #because of DB?
  104. local $TODO = "B::Stash imports too many";
  105. is(`$perlcc -stash -r -o pcc $f $devnull`, "ok", "old-style -stash -o file"); #41
  106. is(`$perlcc --stash -r -opcc $f $devnull`, "ok", "--stash -o file");
  107. ok(-e $a, "executable");
  108. cleanup;
  109. }#}
  110. is(`$perlcc -t -O3 -o pcc $f $devnull`, "", "-t -o file"); #44
  111. TODO: {
  112. local $TODO = '-t unsupported with 5.6' if $] < 5.007;
  113. ok(-e $a, "executable"); #45
  114. is(`$a`, "ok", "./pcc => ok"); #46
  115. }
  116. cleanup;
  117. is(`$perlcc -T -O3 -o pcc $f $devnull`, "", "-T -o file");
  118. ok(-e $a, "executable");
  119. is(`$a`, "ok", "./pcc => ok");
  120. cleanup;
  121. # compiler verboseness
  122. isnt(`$perlcc --Wb=-fno-fold,-v -o pcc $f $redir`, '/Writing output/m',
  123. "--Wb=-fno-fold,-v -o file");
  124. TODO: {
  125. local $TODO = "catch STDERR not STDOUT" if $^O =~ /bsd$/i; # fails freebsd only
  126. like(`$perlcc -B --Wb=-DG,-v -o pcc $f $redir`, "/-PV-/m",
  127. "-B -v5 --Wb=-DG -o file"); #51
  128. }
  129. cleanup;
  130. is(`$perlcc -Wb=-O1 -r $f $devnull`, "ok", "old-style -Wb=-O1");
  131. # perlcc verboseness
  132. isnt(`$perlcc -v 1 -o pcc $f $devnull`, "", "-v 1 -o file");
  133. isnt(`$perlcc -v1 -o pcc $f $devnull`, "", "-v1 -o file");
  134. isnt(`$perlcc -v2 -o pcc $f $devnull`, "", "-v2 -o file");
  135. isnt(`$perlcc -v3 -o pcc $f $devnull`, "", "-v3 -o file");
  136. isnt(`$perlcc -v4 -o pcc $f $devnull`, "", "-v4 -o file");
  137. TODO: {
  138. local $TODO = "catch STDERR not STDOUT" if $^O =~ /bsd$/i; # fails freebsd only
  139. like(`$perlcc -v5 $f $redir`, '/Writing output/m',
  140. "-v5 turns on -Wb=-v"); #58
  141. like(`$perlcc -v5 -B $f $redir`, '/-PV-/m',
  142. "-B -v5 turns on -Wb=-v"); #59
  143. like(`$perlcc -v6 $f $redir`, '/saving magic for AV/m',
  144. "-v6 turns on -Dfull"); #60
  145. like(`$perlcc -v6 -B $f $redir`, '/nextstate/m',
  146. "-B -v6 turns on -DM,-DG,-DA"); #61
  147. }
  148. cleanup;
  149. # switch bundling since 2.10
  150. is(`$perlcc -r -e$e $devnull`, "ok", "-e$e");
  151. cleanup;
  152. like(`$perlcc -v1 -r -e$e $devnull`, '/ok$/m', "-v1");
  153. cleanup;
  154. is(`$perlcc -opcc -r -e$e $devnull`, "ok", "-opcc");
  155. cleanup;
  156. is(`$perlcc -OSr -opcc $f $devnull`, "ok", "-OSr -o file");
  157. ok(-e 'pcc.c', "-S => pcc.c file");
  158. cleanup;
  159. is(`$perlcc -Or -opcc $f $devnull`, "ok", "-Or -o file");
  160. ok(! -e 'pcc.c', "no pcc.c file");
  161. ok(-e $a, "keep executable");
  162. cleanup;
  163. # -BS: ignore -S
  164. like(`$perlcc -BSr -opcc.plc -e $e $redir`, '/-S ignored/', "-BSr -o -e");
  165. ok(-e 'pcc.plc', "pcc.plc file");
  166. cleanup;
  167. is(`$perlcc -Br -opcc.plc $f $devnull`, "ok", "-Br -o file");
  168. ok(-e 'pcc.plc', "pcc.plc file");
  169. cleanup;
  170. is(`$perlcc -B -opcc.plc -e$e $devnull`, "", "-B -o -e");
  171. ok(-e 'pcc.plc', "pcc.plc");
  172. TODO: {
  173. local $TODO = 'yet unsupported 5.6' if $] < 5.007;
  174. is(`$X -Iblib/arch -Iblib/lib pcc.plc`, "ok", "executable plc"); #76
  175. }
  176. cleanup;
  177. #TODO: -m
  178. unlink ($f);