2
0

Test.js 9.8 KB

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