Test.js 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. define("amber_core/Test", ["amber_vm/smalltalk", "amber_vm/nil", "amber_vm/_st", "amber_core/Kernel-Objects"], function(smalltalk,nil,_st){
  2. smalltalk.addPackage('Test');
  3. smalltalk.packages["Test"].transport = {"type":"amd","amdNamespace":"amber_core"};
  4. smalltalk.addClass('NodeTestRunner', smalltalk.Object, [], 'Test');
  5. smalltalk.addMethod(
  6. smalltalk.method({
  7. selector: "main",
  8. category: 'not yet classified',
  9. fn: function (){
  10. var self=this;
  11. return smalltalk.withContext(function($ctx1) {
  12. self._runTestSuite();
  13. return self}, function($ctx1) {$ctx1.fill(self,"main",{},smalltalk.NodeTestRunner.klass)})},
  14. args: [],
  15. source: "main\x0a\x09self runTestSuite",
  16. messageSends: ["runTestSuite"],
  17. referencedClasses: []
  18. }),
  19. smalltalk.NodeTestRunner.klass);
  20. smalltalk.addMethod(
  21. smalltalk.method({
  22. selector: "runTestSuite",
  23. category: 'not yet classified',
  24. fn: function (){
  25. var self=this;
  26. var suite,worker;
  27. function $OrderedCollection(){return smalltalk.OrderedCollection||(typeof OrderedCollection=="undefined"?nil:OrderedCollection)}
  28. function $TestCase(){return smalltalk.TestCase||(typeof TestCase=="undefined"?nil:TestCase)}
  29. function $TestSuiteRunner(){return smalltalk.TestSuiteRunner||(typeof TestSuiteRunner=="undefined"?nil:TestSuiteRunner)}
  30. function $ResultAnnouncement(){return smalltalk.ResultAnnouncement||(typeof ResultAnnouncement=="undefined"?nil:ResultAnnouncement)}
  31. return smalltalk.withContext(function($ctx1) {
  32. var $2,$1,$3,$10,$9,$8,$13,$12,$11,$7,$6,$16,$15,$14,$5,$4,$18,$17,$20,$19,$27,$26,$25,$24,$23,$30,$29,$28,$22,$21,$32,$31,$34,$33,$41,$40,$39,$38,$37,$44,$43,$42,$36,$35;
  33. suite=_st($OrderedCollection())._new();
  34. _st(_st(_st($TestCase())._allSubclasses())._select_((function(each){
  35. return smalltalk.withContext(function($ctx2) {
  36. return _st(_st(each)._isAbstract())._not();
  37. }, function($ctx2) {$ctx2.fillBlock({each:each},$ctx1,1)})})))._do_((function(each){
  38. return smalltalk.withContext(function($ctx2) {
  39. return _st(suite)._addAll_(_st(each)._buildSuite());
  40. }, function($ctx2) {$ctx2.fillBlock({each:each},$ctx1,2)})}));
  41. worker=_st($TestSuiteRunner())._on_(suite);
  42. _st(_st(worker)._announcer())._on_do_($ResultAnnouncement(),(function(ann){
  43. var result;
  44. return smalltalk.withContext(function($ctx2) {
  45. result=_st(ann)._result();
  46. result;
  47. $2=_st(result)._runs();
  48. $ctx2.sendIdx["runs"]=1;
  49. $1=_st($2).__eq(_st(result)._total());
  50. if(smalltalk.assert($1)){
  51. $3=console;
  52. $10=_st(result)._runs();
  53. $9=_st($10)._asString();
  54. $ctx2.sendIdx["asString"]=1;
  55. $8=_st($9).__comma(" tests run, ");
  56. $ctx2.sendIdx[","]=5;
  57. $13=_st(result)._failures();
  58. $ctx2.sendIdx["failures"]=1;
  59. $12=_st($13)._size();
  60. $ctx2.sendIdx["size"]=1;
  61. $11=_st($12)._asString();
  62. $ctx2.sendIdx["asString"]=2;
  63. $7=_st($8).__comma($11);
  64. $ctx2.sendIdx[","]=4;
  65. $6=_st($7).__comma(" failures, ");
  66. $ctx2.sendIdx[","]=3;
  67. $16=_st(result)._errors();
  68. $ctx2.sendIdx["errors"]=1;
  69. $15=_st($16)._size();
  70. $14=_st($15)._asString();
  71. $5=_st($6).__comma($14);
  72. $ctx2.sendIdx[","]=2;
  73. $4=_st($5).__comma(" errors.");
  74. $ctx2.sendIdx[","]=1;
  75. _st($3)._log_($4);
  76. $18=_st(result)._failures();
  77. $ctx2.sendIdx["failures"]=2;
  78. $17=_st($18)._isEmpty();
  79. $ctx2.sendIdx["isEmpty"]=1;
  80. if(! smalltalk.assert($17)){
  81. $20=_st(result)._failures();
  82. $ctx2.sendIdx["failures"]=3;
  83. $19=_st($20)._first();
  84. $ctx2.sendIdx["first"]=1;
  85. _st($19)._runCase();
  86. $ctx2.sendIdx["runCase"]=1;
  87. $27=_st(result)._failures();
  88. $ctx2.sendIdx["failures"]=4;
  89. $26=_st($27)._first();
  90. $ctx2.sendIdx["first"]=2;
  91. $25=_st($26)._class();
  92. $ctx2.sendIdx["class"]=1;
  93. $24=_st($25)._name();
  94. $ctx2.sendIdx["name"]=1;
  95. $23=_st($24).__comma(" >> ");
  96. $ctx2.sendIdx[","]=8;
  97. $30=_st(result)._failures();
  98. $29=_st($30)._first();
  99. $ctx2.sendIdx["first"]=3;
  100. $28=_st($29)._selector();
  101. $ctx2.sendIdx["selector"]=1;
  102. $22=_st($23).__comma($28);
  103. $ctx2.sendIdx[","]=7;
  104. $21=_st($22).__comma(" is failing!");
  105. $ctx2.sendIdx[","]=6;
  106. self._throw_($21);
  107. $ctx2.sendIdx["throw:"]=1;
  108. };
  109. $32=_st(result)._errors();
  110. $ctx2.sendIdx["errors"]=2;
  111. $31=_st($32)._isEmpty();
  112. if(! smalltalk.assert($31)){
  113. $34=_st(result)._errors();
  114. $ctx2.sendIdx["errors"]=3;
  115. $33=_st($34)._first();
  116. $ctx2.sendIdx["first"]=4;
  117. _st($33)._runCase();
  118. $41=_st(result)._errors();
  119. $ctx2.sendIdx["errors"]=4;
  120. $40=_st($41)._first();
  121. $ctx2.sendIdx["first"]=5;
  122. $39=_st($40)._class();
  123. $38=_st($39)._name();
  124. $37=_st($38).__comma(" >> ");
  125. $44=_st(result)._errors();
  126. $43=_st($44)._first();
  127. $42=_st($43)._selector();
  128. $36=_st($37).__comma($42);
  129. $ctx2.sendIdx[","]=10;
  130. $35=_st($36).__comma(" has errors!");
  131. $ctx2.sendIdx[","]=9;
  132. return self._throw_($35);
  133. };
  134. };
  135. }, function($ctx2) {$ctx2.fillBlock({ann:ann,result:result},$ctx1,3)})}));
  136. _st(worker)._run();
  137. return self}, function($ctx1) {$ctx1.fill(self,"runTestSuite",{suite:suite,worker:worker},smalltalk.NodeTestRunner.klass)})},
  138. args: [],
  139. 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",
  140. 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"],
  141. referencedClasses: ["OrderedCollection", "TestCase", "TestSuiteRunner", "ResultAnnouncement"]
  142. }),
  143. smalltalk.NodeTestRunner.klass);
  144. });