Test.js 6.2 KB

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