e_perlcc.t 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  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. ok(! -e 'pcc.c.lst', "no pcc.c.lst without xs"); #22
  66. cleanup;
  67. }
  68. my $f = "pcc.pl";
  69. open F,">",$f;
  70. print F q(print q(ok));
  71. close F;
  72. $e = q("print q(ok)");
  73. is(`$perlcc -S -o pcc -r $f $devnull`, "ok", "-S -o -r file");
  74. ok(-e 'pcc.c', "-S => pcc.c file");
  75. cleanup;
  76. is(`$perlcc -o pcc -r $f $devnull`, "ok", "-r -o file");
  77. ok(! -e 'pcc.c', "no pcc.c file");
  78. ok(-e $a, "keep executable");
  79. cleanup;
  80. is(`$perlcc -o pcc $f $devnull`, "", "-o file");
  81. ok(! -e 'pcc.c', "no pcc.c file");
  82. ok(-e $a, "executable");
  83. is(`$a`, "ok", "./pcc => ok");
  84. cleanup;
  85. is(`$perlcc -S -o pcc $f $devnull`, "", "-S -o file");
  86. ok(-e $a, "executable");
  87. is(`$a`, "ok", "./pcc => ok");
  88. cleanup;
  89. is(`$perlcc -Sc -o pcc $f $devnull`, "", "-Sc -o file");
  90. ok(-e 'pcc.c', "pcc.c file");
  91. ok(! -e $a, "-Sc no executable, compile only");
  92. cleanup;
  93. is(`$perlcc -c -o pcc $f $devnull`, "", "-c -o file");
  94. ok(-e 'pcc.c', "pcc.c file");
  95. ok(! -e $a, "-c no executable, compile only"); #40
  96. cleanup;
  97. #SKIP: {
  98. TODO: {
  99. #skip "--stash hangs < 5.12", 3 if $] < 5.012; #because of DB?
  100. #skip "--stash hangs >= 5.14", 3 if $] >= 5.014; #because of DB?
  101. local $TODO = "B::Stash imports too many";
  102. is(`$perlcc -stash -r -o pcc $f $devnull`, "ok", "old-style -stash -o file"); #41
  103. is(`$perlcc --stash -r -opcc $f $devnull`, "ok", "--stash -o file");
  104. ok(-e $a, "executable");
  105. cleanup;
  106. }#}
  107. is(`$perlcc -t -O3 -o pcc $f $devnull`, "", "-t -o file"); #44
  108. TODO: {
  109. local $TODO = '-t unsupported with 5.6' if $] < 5.007;
  110. ok(-e $a, "executable"); #45
  111. is(`$a`, "ok", "./pcc => ok"); #46
  112. }
  113. cleanup;
  114. is(`$perlcc -T -O3 -o pcc $f $devnull`, "", "-T -o file");
  115. ok(-e $a, "executable");
  116. is(`$a`, "ok", "./pcc => ok");
  117. cleanup;
  118. # compiler verboseness
  119. isnt(`$perlcc --Wb=-fno-fold,-v -o pcc $f $redir`, '/Writing output/m',
  120. "--Wb=-fno-fold,-v -o file");
  121. TODO: {
  122. local $TODO = "catch STDERR not STDOUT" if $^O =~ /bsd$/i; # fails freebsd only
  123. like(`$perlcc -B --Wb=-DG,-v -o pcc $f $redir`, "/-PV-/m",
  124. "-B -v5 --Wb=-DG -o file"); #51
  125. }
  126. cleanup;
  127. is(`$perlcc -Wb=-O1 -r $f $devnull`, "ok", "old-style -Wb=-O1");
  128. # perlcc verboseness
  129. isnt(`$perlcc -v 1 -o pcc $f $devnull`, "", "-v 1 -o file");
  130. isnt(`$perlcc -v1 -o pcc $f $devnull`, "", "-v1 -o file");
  131. isnt(`$perlcc -v2 -o pcc $f $devnull`, "", "-v2 -o file");
  132. isnt(`$perlcc -v3 -o pcc $f $devnull`, "", "-v3 -o file");
  133. isnt(`$perlcc -v4 -o pcc $f $devnull`, "", "-v4 -o file");
  134. TODO: {
  135. local $TODO = "catch STDERR not STDOUT" if $^O =~ /bsd$/i; # fails freebsd only
  136. like(`$perlcc -v5 $f $redir`, '/Writing output/m',
  137. "-v5 turns on -Wb=-v"); #58
  138. like(`$perlcc -v5 -B $f $redir`, '/-PV-/m',
  139. "-B -v5 turns on -Wb=-v"); #59
  140. like(`$perlcc -v6 $f $redir`, '/saving magic for AV/m',
  141. "-v6 turns on -Dfull"); #60
  142. like(`$perlcc -v6 -B $f $redir`, '/nextstate/m',
  143. "-B -v6 turns on -DM,-DG,-DA"); #61
  144. }
  145. cleanup;
  146. # switch bundling since 2.10
  147. is(`$perlcc -r -e$e $devnull`, "ok", "-e$e");
  148. cleanup;
  149. like(`$perlcc -v1 -r -e$e $devnull`, '/ok$/m', "-v1");
  150. cleanup;
  151. is(`$perlcc -opcc -r -e$e $devnull`, "ok", "-opcc");
  152. cleanup;
  153. is(`$perlcc -OSr -opcc $f $devnull`, "ok", "-OSr -o file");
  154. ok(-e 'pcc.c', "-S => pcc.c file");
  155. cleanup;
  156. is(`$perlcc -Or -opcc $f $devnull`, "ok", "-Or -o file");
  157. ok(! -e 'pcc.c', "no pcc.c file");
  158. ok(-e $a, "keep executable");
  159. cleanup;
  160. # -BS: ignore -S
  161. like(`$perlcc -BSr -opcc.plc -e $e $redir`, '/-S ignored/', "-BSr -o -e");
  162. ok(-e 'pcc.plc', "pcc.plc file");
  163. cleanup;
  164. is(`$perlcc -Br -opcc.plc $f $devnull`, "ok", "-Br -o file");
  165. ok(-e 'pcc.plc', "pcc.plc file");
  166. cleanup;
  167. is(`$perlcc -B -opcc.plc -e$e $devnull`, "", "-B -o -e");
  168. ok(-e 'pcc.plc', "pcc.plc");
  169. TODO: {
  170. local $TODO = 'yet unsupported 5.6' if $] < 5.007;
  171. is(`$X -Iblib/arch -Iblib/lib pcc.plc`, "ok", "executable plc"); #76
  172. }
  173. cleanup;
  174. #TODO: -m
  175. unlink ($f);