NodeTestRunner.js 9.6 KB

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