e_perlcc.t 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322
  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 Config;
  6. my @plan;
  7. use File::Spec;
  8. BEGIN {
  9. @plan = (tests => 90);
  10. push @INC, 't';
  11. require TestBC;
  12. if ($ENV{PERL_CORE}) {
  13. if (-f File::Spec->catfile($Config{'sitearch'}, "Opcodes.pm")) {
  14. @plan = (skip_all => '<sitearch>/Opcodes.pm installed. Possible XS conflict');
  15. }
  16. if (-f File::Spec->catfile($Config{'sitearch'}, "B", "Flags.pm")) {
  17. @plan = (skip_all => '<sitearch>/B/Flags.pm installed. Possible XS conflict');
  18. }
  19. if ($Config{ccflags} =~ /-flto/ and is_CI()) {
  20. @plan = (skip_all => '-flto times out on CI');
  21. }
  22. if ($^O eq 'MSWin32') { # find perl5*.dll
  23. $ENV{PATH} .= ';..\..';
  24. }
  25. #if ($^O eq 'MSWin32' and $ENV{APPVEYOR}) {
  26. # # can be used with -Od though
  27. # @plan = (skip_all => 'Overlong tests, timeout on Appveyor CI');
  28. #}
  29. #if ($^O eq 'MSWin32' and $Config{cc} eq 'cl') {
  30. # # >= 3 c compiler warnings
  31. # @plan = (skip_all => 'Tests not yet ready for MSWin32 MSVC');
  32. #}
  33. }
  34. if ($^O eq 'VMS') {
  35. @plan = (skip_all => "B::C doesn't work on VMS");
  36. }
  37. if (($Config{'extensions'} !~ /\bB\b/) ) {
  38. @plan = (skip_all => "Perl configured without B module");
  39. }
  40. # with 5.10 and 5.8.9 PERL_COPY_ON_WRITE was renamed to PERL_OLD_COPY_ON_WRITE
  41. if ($Config{ccflags} =~ /-DPERL_OLD_COPY_ON_WRITE/) {
  42. @plan = (skip_all => "no OLD_COPY_ON_WRITE");
  43. }
  44. if ($Config{ccflags} =~ /-flto/) {
  45. $ENV{SKIP_SLOW_TESTS} = 1;
  46. }
  47. }
  48. use Test::More @plan;
  49. my $usedl = $Config{usedl} eq 'define';
  50. my $X = $^X =~ m/\s/ ? qq{"$^X"} : $^X;
  51. # TODO: no global output 'a' and 'a.c' to enable parallel testing (test speedup)
  52. my $exe = $^O =~ /MSWin32|cygwin|msys/ ? 'pcc.exe' : './pcc';
  53. my $a_exe = $^O =~ /MSWin32|cygwin|msys/ ? 'a.exe' : './a.out';
  54. my $a = $^O eq 'MSWin32' ? 'pcc.exe' : './pcc';
  55. my $redir = $^O eq 'MSWin32' ? '' : '2>&1';
  56. my $devnull = $^O eq 'MSWin32' ? '' : '2>/dev/null';
  57. # VC takes a couple hours to compile each executable in -O1
  58. my $Wcflags = $^O eq 'MSWin32' && $Config{cc} =~ /cl/ ? ' --Wc=-Od' : '';
  59. if ($^O eq 'MSWin32' && $Config{cc} =~ /gcc/) { # mingw is not much better
  60. $Wcflags = ' --Wc=-O0';
  61. }
  62. my $ITHREADS = $Config{useithreads};
  63. #my $o = '';
  64. #$o = "-Wb=-fno-warnings" if $] >= 5.013005;
  65. #$o = "-Wb=-fno-fold,-fno-warnings" if $] >= 5.013009;
  66. my $perlcc = "$X ".Mblib." ".perlcc.$Wcflags;
  67. sub cleanup { unlink ('pcc.c','pcc.c.lst','a.out.c', "a.c", $exe, $a, "a.out.c.lst", "a.c.lst"); }
  68. my $e = q("print q(ok)");
  69. is(`$perlcc -S -o pcc -r -e $e $devnull`, "ok", "-S -o pcc -r -e");
  70. ok(-e 'pcc.c', "-S => pcc.c file");
  71. ok(-e $a, "keep pcc executable"); #3
  72. cleanup;
  73. is(`$perlcc -o pcc -r -e $e $devnull`, "ok", "-o pcc r -e");
  74. ok(! -e 'pcc.c', "no pcc.c file");
  75. ok(-e $a, "keep pcc executable"); # 6
  76. cleanup;
  77. my @c = <*.c>;
  78. is(`$perlcc -r -e $e $devnull`, "ok", "-r -e"); #7
  79. my @c1 = <*.c>;
  80. if ($ENV{HARNESS_ACTIVE}) {
  81. ok(1, "skip temp cfile test on parallel tests"); #8
  82. } else {
  83. is(length @c, length @c1, "no temp cfile");
  84. }
  85. ok(-e $a_exe, "keep default executable"); #9
  86. cleanup;
  87. system(qq($perlcc -o pcc -e $e $devnull));
  88. ok(-e $a, '-o pcc -e');
  89. is(`$a`, "ok", "$a => ok"); #11
  90. cleanup;
  91. # Try a simple XS module which exists in 5.6.2 and blead (test 45)
  92. $e = q("use Data::Dumper ();Data::Dumper::Dumpxs({});print q(ok)");
  93. SKIP: {
  94. skip "slow tests", 9 if $ENV{SKIP_SLOW_TESTS};
  95. is(`$perlcc -r -e $e $devnull`, "ok", "-r xs ".($usedl ? "dynamic" : "static")); #12
  96. cleanup;
  97. TODO: {
  98. # fails 5.8 and before sometimes on darwin, msvc also.
  99. local $TODO = '--staticxs is experimental on darwin and <5.10' if $] < 5.010
  100. or $^O eq 'darwin';
  101. is(`$perlcc --staticxs -r -e $e $devnull`, "ok", "-r --staticxs xs"); #13
  102. ok(-e $a_exe, "keep default executable"); #14
  103. }
  104. ok(! -e 'a.out.c', "delete a.out.c file without -S");
  105. ok(! -e 'a.out.c.lst', "delete a.out.c.lst without -S");
  106. cleanup;
  107. TODO: {
  108. local $TODO = '--staticxs -S is experimental on darwin/win and <5.10'
  109. if $] < 5.010 or $^O eq 'darwin' or (is_CI() and $^O eq 'MSWin32');
  110. is(`$perlcc --staticxs -S -o pcc -r -e $e $devnull`, "ok",
  111. "-S -o -r --staticxs xs"); #17
  112. ok(-e $a, "keep executable"); #18
  113. }
  114. ok(-e 'pcc.c', "keep pcc.c file with -S");
  115. ok(-e 'pcc.c.lst', "keep pcc.c.lst with -S");
  116. cleanup;
  117. }
  118. is(`$perlcc --staticxs -S -o pcc -O3 -r -e "print q(ok)" $devnull`, "ok", #21
  119. "-S -o -r --staticxs without xs");
  120. ok(! -e 'pcc.c.lst', "no pcc.c.lst without xs"); #22
  121. cleanup;
  122. my $f = "pcc.pl";
  123. open F,">",$f;
  124. print F q(print q(ok));
  125. close F;
  126. $e = q("print q(ok)");
  127. is(`$perlcc -S -o pcc -r $f $devnull`, "ok", "-S -o -r file");
  128. ok(-e 'pcc.c', "-S => pcc.c file");
  129. cleanup;
  130. is(`$perlcc -o pcc -r $f $devnull`, "ok", "-r -o file");
  131. ok(! -e 'pcc.c', "no pcc.c file");
  132. ok(-e $a, "keep executable");
  133. cleanup;
  134. is(`$perlcc -o pcc $f $devnull`, "", "-o file");
  135. ok(! -e 'pcc.c', "no pcc.c file");
  136. ok(-e $a, "executable");
  137. is(`$a`, "ok", "./pcc => ok");
  138. cleanup;
  139. is(`$perlcc -S -o pcc $f $devnull`, "", "-S -o file");
  140. ok(-e $a, "executable");
  141. is(`$a`, "ok", "./pcc => ok");
  142. cleanup;
  143. is(`$perlcc -Sc -o pcc $f $devnull`, "", "-Sc -o file");
  144. ok(-e 'pcc.c', "pcc.c file");
  145. ok(! -e $a, "-Sc no executable, compile only");
  146. cleanup;
  147. is(`$perlcc -c -o pcc $f $devnull`, "", "-c -o file");
  148. ok(-e 'pcc.c', "pcc.c file");
  149. ok(! -e $a, "-c no executable, compile only"); #40
  150. cleanup;
  151. #SKIP: {
  152. TODO: {
  153. #skip "--stash hangs < 5.12", 3 if $] < 5.012; #because of DB?
  154. #skip "--stash hangs >= 5.14", 3 if $] >= 5.014; #because of DB?
  155. local $TODO = "B::Stash imports too many";
  156. is(`$perlcc -stash -r -o pcc $f $devnull`, "ok", "old-style -stash -o file"); #41
  157. is(`$perlcc --stash -r -opcc $f $devnull`, "ok", "--stash -o file");
  158. ok(-e $a, "executable");
  159. cleanup;
  160. }#}
  161. is(`$perlcc -t -O3 -o pcc $f $devnull`, "", "-t -o file"); #44
  162. TODO: {
  163. local $TODO = '-t unsupported with 5.6' if $] < 5.007;
  164. ok(-e $a, "executable"); #45
  165. is(`$a`, "ok", "./pcc => ok"); #46
  166. }
  167. cleanup;
  168. is(`$perlcc -T -O3 -o pcc $f $devnull`, "", "-T -o file");
  169. ok(-e $a, "executable");
  170. is(`$a`, "ok", "./pcc => ok");
  171. cleanup;
  172. # compiler verboseness
  173. isnt(`$perlcc --Wb=-fno-fold,-v -o pcc $f $redir`, '/Writing output/m',
  174. "--Wb=-fno-fold,-v -o file");
  175. TODO: {
  176. SKIP: {
  177. require B::C::Config if $] > 5.021006;
  178. local $TODO = "catch STDERR not STDOUT" if $^O =~ /bsd$/i; # fails freebsd only
  179. local $TODO = "5.6 BC does not understand -DG yet" if $] < 5.007;
  180. skip "perl5.22 broke ByteLoader", 1
  181. if $] > 5.021006 and !$B::C::Config::have_byteloader;
  182. like(`$perlcc -B --Wb=-DG,-v -o pcc $f $redir`, "/-PV-/m",
  183. "-B -v5 --Wb=-DG -o file"); #51
  184. }
  185. }
  186. cleanup;
  187. is(`$perlcc -Wb=-O1 -r $f $devnull`, "ok", "old-style -Wb=-O1");
  188. # perlcc verboseness
  189. isnt(`$perlcc -v 1 -o pcc $f $devnull`, "", "-v 1 -o file");
  190. isnt(`$perlcc -v1 -o pcc $f $devnull`, "", "-v1 -o file");
  191. isnt(`$perlcc -v2 -o pcc $f $devnull`, "", "-v2 -o file");
  192. isnt(`$perlcc -v3 -o pcc $f $devnull`, "", "-v3 -o file");
  193. isnt(`$perlcc -v4 -o pcc $f $devnull`, "", "-v4 -o file");
  194. TODO: {
  195. local $TODO = "catch STDERR not STDOUT" if $^O =~ /(bsd|MSWin32)$/i; # fails freebsd only
  196. like(`$perlcc -v5 $f $redir`, '/Writing output/m',
  197. "-v5 turns on -Wb=-v"); #58
  198. like(`$perlcc -v5 -B $f $redir`, '/-PV-/m',
  199. "-B -v5 turns on -Wb=-v"); #59
  200. like(`$perlcc -v6 $f $redir`, '/saving( stash and)? magic for AV/m',
  201. "-v6 turns on -Dfull"); #60
  202. like(`$perlcc -v6 -B $f $redir`, '/nextstate/m',
  203. "-B -v6 turns on -DM,-DG,-DA"); #61
  204. }
  205. cleanup;
  206. # switch bundling since 2.10
  207. is(`$perlcc -r -e$e $devnull`, "ok", "-e$e");
  208. cleanup;
  209. like(`$perlcc -v1 -r -e$e $devnull`, '/ok$/m', "-v1");
  210. cleanup;
  211. is(`$perlcc -opcc -r -e$e $devnull`, "ok", "-opcc");
  212. cleanup;
  213. is(`$perlcc -OSr -opcc $f $devnull`, "ok", "-OSr -o file");
  214. ok(-e 'pcc.c', "-S => pcc.c file");
  215. cleanup;
  216. is(`$perlcc -Or -opcc $f $devnull`, "ok", "-Or -o file");
  217. ok(! -e 'pcc.c', "no pcc.c file");
  218. ok(-e $a, "keep executable"); #69
  219. cleanup;
  220. # -BS: ignore -S
  221. SKIP: {
  222. skip "$^O redirection", 2 if $^O eq 'MSWin32';
  223. like(`$perlcc -BSr -opcc.plc -e $e $redir`, '/-S ignored/', "-BSr -o -e"); #70
  224. ok(-e 'pcc.plc', "pcc.plc file");
  225. cleanup;
  226. }
  227. SKIP: {
  228. skip "perl5.22 broke ByteLoader", 1
  229. if $] > 5.021006 and !$B::C::Config::have_byteloader;
  230. is(`$perlcc -Br -opcc.plc $f $devnull`, "ok", "-Br -o file");
  231. }
  232. ok(-e 'pcc.plc', "pcc.plc file");
  233. cleanup;
  234. is(`$perlcc -B -opcc.plc -e$e $devnull`, "", "-B -o -e");
  235. ok(-e 'pcc.plc', "pcc.plc");
  236. if ($] < 5.007) {
  237. TODO: {
  238. local $TODO = 'yet unsupported';
  239. is(`$X -MByteLoader pcc.plc`, "ok", "executable 5.6 plc"); #76
  240. }
  241. }
  242. elsif ($] > 5.021) {
  243. TODO: {
  244. local $TODO = 'yet unsupported';
  245. is(`$X -Iblib/arch -Iblib/lib -MByteLoader pcc.plc`, "ok", "executable 5.22 plc"); #76
  246. }
  247. } else {
  248. is(`$X -Iblib/arch -Iblib/lib pcc.plc`, "ok", "executable plc"); #76
  249. }
  250. cleanup;
  251. TODO: {
  252. local $TODO = "unreliable --check test";
  253. like(`$perlcc -o pcc --check -e"BEGIN{open(F,q(<xx))}"`, #77
  254. qr/^Warning: Read BEGIN-block main::F from FileHandle/, "--check");
  255. }
  256. ok(!-e "pcc.c", "no C file"); #78
  257. ok(!-e $a, "no executable"); #79
  258. cleanup;
  259. is(`$perlcc -It -O3 -o pcc $f $devnull`, "", "single -I");
  260. ok(-e $a, "=> executable");
  261. cleanup;
  262. is(`$perlcc -It -Iscript -O3 -o pcc $f $devnull`, "", "mult -I");
  263. ok(-e $a, "=> executable");
  264. cleanup;
  265. is(`$perlcc -Lt -O3 -o pcc $f $devnull`, "", "single -L");
  266. ok(-e $a, "=> executable");
  267. cleanup;
  268. is(`$perlcc -Lt -Lscript -O3 -o pcc $f $devnull`, "", "mult -L");
  269. ok(-e $a, "=> executable");
  270. cleanup;
  271. #TODO: -m
  272. open F,">",$f;
  273. print F q(use DoesNotExist;\n);
  274. close F;
  275. eval {
  276. isnt(system("$perlcc -o pcc $f $devnull"), 0, "die with missing module"); #445
  277. };
  278. ok(!-e 'pcc.c', "no pcc.c file");
  279. ok(!-e $a, "no executable");
  280. cleanup;
  281. unlink ($f);