NodeTestRunner.js 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  1. define(["amber/boot", "amber_core/Kernel-Objects"], function($boot){"use strict";
  2. if(!("nilAsValue" in $boot))$boot.nilAsValue=$boot.nilAsReceiver;
  3. var $core=$boot.api,nil=$boot.nilAsValue,$nil=$boot.nilAsReceiver,$recv=$boot.asReceiver,$globals=$boot.globals;
  4. $core.addPackage("NodeTestRunner");
  5. ($core.packageDescriptors||$core.packages)["NodeTestRunner"].innerEval = function (expr) { return eval(expr); };
  6. ($core.packageDescriptors||$core.packages)["NodeTestRunner"].transport = {"type":"amd","amdNamespace":"amber_devkit"};
  7. $core.addClass("NodeTestRunner", $globals.Object, [], "NodeTestRunner");
  8. $core.addMethod(
  9. $core.method({
  10. selector: "main",
  11. protocol: "not yet classified",
  12. fn: function (){
  13. var self=this,$self=this;
  14. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  15. return $core.withContext(function($ctx1) {
  16. //>>excludeEnd("ctx");
  17. $self._runTestSuite();
  18. return self;
  19. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  20. }, function($ctx1) {$ctx1.fill(self,"main",{},$globals.NodeTestRunner.a$cls)});
  21. //>>excludeEnd("ctx");
  22. },
  23. //>>excludeStart("ide", pragmas.excludeIdeData);
  24. args: [],
  25. source: "main\x0a\x09self runTestSuite",
  26. referencedClasses: [],
  27. //>>excludeEnd("ide");
  28. messageSends: ["runTestSuite"]
  29. }),
  30. $globals.NodeTestRunner.a$cls);
  31. $core.addMethod(
  32. $core.method({
  33. selector: "runTestSuite",
  34. protocol: "not yet classified",
  35. fn: function (){
  36. var self=this,$self=this;
  37. var suite,worker;
  38. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  39. return $core.withContext(function($ctx1) {
  40. //>>excludeEnd("ctx");
  41. var $2,$1,$3,$9,$8,$12,$11,$10,$7,$6,$15,$14,$13,$5,$4,$17,$16,$19,$18,$26,$25,$24,$23,$22,$28,$27,$21,$20,$30,$29,$32,$31,$39,$38,$37,$36,$35,$34,$33;
  42. suite=$recv($globals.OrderedCollection)._new();
  43. $recv($recv($recv($globals.TestCase)._allSubclasses())._select_((function(each){
  44. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  45. return $core.withContext(function($ctx2) {
  46. //>>excludeEnd("ctx");
  47. return $recv($recv(each)._isAbstract())._not();
  48. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  49. }, function($ctx2) {$ctx2.fillBlock({each:each},$ctx1,1)});
  50. //>>excludeEnd("ctx");
  51. })))._do_((function(each){
  52. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  53. return $core.withContext(function($ctx2) {
  54. //>>excludeEnd("ctx");
  55. return $recv(suite)._addAll_($recv(each)._buildSuite());
  56. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  57. }, function($ctx2) {$ctx2.fillBlock({each:each},$ctx1,2)});
  58. //>>excludeEnd("ctx");
  59. }));
  60. worker=$recv($globals.TestSuiteRunner)._on_(suite);
  61. $recv($recv(worker)._announcer())._on_do_($globals.ResultAnnouncement,(function(ann){
  62. var result;
  63. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  64. return $core.withContext(function($ctx2) {
  65. //>>excludeEnd("ctx");
  66. result=$recv(ann)._result();
  67. result;
  68. $2=$recv(result)._runs();
  69. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  70. $ctx2.sendIdx["runs"]=1;
  71. //>>excludeEnd("ctx");
  72. $1=$recv($2).__eq($recv(result)._total());
  73. if($core.assert($1)){
  74. $3=console;
  75. $9=$recv($recv(result)._runs())._asString();
  76. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  77. $ctx2.sendIdx["asString"]=1;
  78. //>>excludeEnd("ctx");
  79. $8=$recv($9).__comma(" tests run, ");
  80. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  81. $ctx2.sendIdx[","]=5;
  82. //>>excludeEnd("ctx");
  83. $12=$recv(result)._failures();
  84. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  85. $ctx2.sendIdx["failures"]=1;
  86. //>>excludeEnd("ctx");
  87. $11=$recv($12)._size();
  88. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  89. $ctx2.sendIdx["size"]=1;
  90. //>>excludeEnd("ctx");
  91. $10=$recv($11)._asString();
  92. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  93. $ctx2.sendIdx["asString"]=2;
  94. //>>excludeEnd("ctx");
  95. $7=$recv($8).__comma($10);
  96. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  97. $ctx2.sendIdx[","]=4;
  98. //>>excludeEnd("ctx");
  99. $6=$recv($7).__comma(" failures, ");
  100. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  101. $ctx2.sendIdx[","]=3;
  102. //>>excludeEnd("ctx");
  103. $15=$recv(result)._errors();
  104. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  105. $ctx2.sendIdx["errors"]=1;
  106. //>>excludeEnd("ctx");
  107. $14=$recv($15)._size();
  108. $13=$recv($14)._asString();
  109. $5=$recv($6).__comma($13);
  110. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  111. $ctx2.sendIdx[","]=2;
  112. //>>excludeEnd("ctx");
  113. $4=$recv($5).__comma(" errors.");
  114. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  115. $ctx2.sendIdx[","]=1;
  116. //>>excludeEnd("ctx");
  117. $recv($3)._log_($4);
  118. $17=$recv(result)._failures();
  119. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  120. $ctx2.sendIdx["failures"]=2;
  121. //>>excludeEnd("ctx");
  122. $16=$recv($17)._isEmpty();
  123. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  124. $ctx2.sendIdx["isEmpty"]=1;
  125. //>>excludeEnd("ctx");
  126. if(!$core.assert($16)){
  127. $19=$recv(result)._failures();
  128. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  129. $ctx2.sendIdx["failures"]=3;
  130. //>>excludeEnd("ctx");
  131. $18=$recv($19)._first();
  132. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  133. $ctx2.sendIdx["first"]=1;
  134. //>>excludeEnd("ctx");
  135. $recv($18)._runCase();
  136. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  137. $ctx2.sendIdx["runCase"]=1;
  138. //>>excludeEnd("ctx");
  139. $26=$recv(result)._failures();
  140. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  141. $ctx2.sendIdx["failures"]=4;
  142. //>>excludeEnd("ctx");
  143. $25=$recv($26)._first();
  144. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  145. $ctx2.sendIdx["first"]=2;
  146. //>>excludeEnd("ctx");
  147. $24=$recv($25)._class();
  148. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  149. $ctx2.sendIdx["class"]=1;
  150. //>>excludeEnd("ctx");
  151. $23=$recv($24)._name();
  152. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  153. $ctx2.sendIdx["name"]=1;
  154. //>>excludeEnd("ctx");
  155. $22=$recv($23).__comma(" >> ");
  156. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  157. $ctx2.sendIdx[","]=8;
  158. //>>excludeEnd("ctx");
  159. $28=$recv($recv(result)._failures())._first();
  160. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  161. $ctx2.sendIdx["first"]=3;
  162. //>>excludeEnd("ctx");
  163. $27=$recv($28)._selector();
  164. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  165. $ctx2.sendIdx["selector"]=1;
  166. //>>excludeEnd("ctx");
  167. $21=$recv($22).__comma($27);
  168. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  169. $ctx2.sendIdx[","]=7;
  170. //>>excludeEnd("ctx");
  171. $20=$recv($21).__comma(" is failing!");
  172. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  173. $ctx2.sendIdx[","]=6;
  174. //>>excludeEnd("ctx");
  175. $self._throw_($20);
  176. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  177. $ctx2.sendIdx["throw:"]=1;
  178. //>>excludeEnd("ctx");
  179. }
  180. $30=$recv(result)._errors();
  181. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  182. $ctx2.sendIdx["errors"]=2;
  183. //>>excludeEnd("ctx");
  184. $29=$recv($30)._isEmpty();
  185. if(!$core.assert($29)){
  186. $32=$recv(result)._errors();
  187. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  188. $ctx2.sendIdx["errors"]=3;
  189. //>>excludeEnd("ctx");
  190. $31=$recv($32)._first();
  191. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  192. $ctx2.sendIdx["first"]=4;
  193. //>>excludeEnd("ctx");
  194. $recv($31)._runCase();
  195. $39=$recv(result)._errors();
  196. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  197. $ctx2.sendIdx["errors"]=4;
  198. //>>excludeEnd("ctx");
  199. $38=$recv($39)._first();
  200. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  201. $ctx2.sendIdx["first"]=5;
  202. //>>excludeEnd("ctx");
  203. $37=$recv($38)._class();
  204. $36=$recv($37)._name();
  205. $35=$recv($36).__comma(" >> ");
  206. $34=$recv($35).__comma($recv($recv($recv(result)._errors())._first())._selector());
  207. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  208. $ctx2.sendIdx[","]=10;
  209. //>>excludeEnd("ctx");
  210. $33=$recv($34).__comma(" has errors!");
  211. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  212. $ctx2.sendIdx[","]=9;
  213. //>>excludeEnd("ctx");
  214. return $self._throw_($33);
  215. }
  216. }
  217. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  218. }, function($ctx2) {$ctx2.fillBlock({ann:ann,result:result},$ctx1,3)});
  219. //>>excludeEnd("ctx");
  220. }));
  221. $recv(worker)._run();
  222. return self;
  223. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  224. }, function($ctx1) {$ctx1.fill(self,"runTestSuite",{suite:suite,worker:worker},$globals.NodeTestRunner.a$cls)});
  225. //>>excludeEnd("ctx");
  226. },
  227. //>>excludeStart("ide", pragmas.excludeIdeData);
  228. args: [],
  229. source: "runTestSuite\x0a\x09| suite worker |\x0a\x0a\x09suite := OrderedCollection new.\x0a (TestCase allSubclasses select: [ :each | each isAbstract not ])\x0a\x09do: [ :each | suite addAll: each buildSuite ].\x0a\x0a\x09worker := TestSuiteRunner on: suite.\x0a\x09worker announcer on: ResultAnnouncement do:\x0a\x09[ :ann | | result |\x0a \x09result := ann result.\x0a result runs = result total ifTrue: [\x0a\x09 console log: result runs asString, ' tests run, ', result failures size asString, ' failures, ', result errors size asString, ' errors.'.\x0a\x0a result failures isEmpty ifFalse: [\x0a result failures first runCase.\x0a \x22the line above should throw, normally, but just in case I leave the line below\x22\x0a self throw: result failures first class name, ' >> ', result failures first selector, ' is failing!' ].\x0a result errors isEmpty ifFalse: [\x0a result errors first runCase.\x0a \x22the line above should throw, normally, but just in case I leave the line below\x22\x0a self throw: result errors first class name, ' >> ', result errors first selector, ' has errors!' ].\x0a ]].\x0a worker run",
  230. referencedClasses: ["OrderedCollection", "TestCase", "TestSuiteRunner", "ResultAnnouncement"],
  231. //>>excludeEnd("ide");
  232. messageSends: ["new", "do:", "select:", "allSubclasses", "not", "isAbstract", "addAll:", "buildSuite", "on:", "on:do:", "announcer", "result", "ifTrue:", "=", "runs", "total", "log:", ",", "asString", "size", "failures", "errors", "ifFalse:", "isEmpty", "runCase", "first", "throw:", "name", "class", "selector", "run"]
  233. }),
  234. $globals.NodeTestRunner.a$cls);
  235. });