e_perlcc.t 6.4 KB

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