1
0

NodeTestRunner.js 9.5 KB

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