2
0

Test.js 4.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. (function(smalltalk,nil,_st){
  2. smalltalk.addPackage('Test');
  3. smalltalk.addClass('NodeTestRunner', smalltalk.Object, [], 'Test');
  4. smalltalk.addMethod(
  5. smalltalk.method({
  6. selector: "initialize",
  7. category: 'not yet classified',
  8. fn: function (){
  9. var self=this;
  10. return smalltalk.withContext(function($ctx1) {
  11. self._runTestSuite();
  12. return self}, function($ctx1) {$ctx1.fill(self,"initialize",{},smalltalk.NodeTestRunner.klass)})},
  13. args: [],
  14. source: "initialize\x0a\x09self runTestSuite",
  15. messageSends: ["runTestSuite"],
  16. referencedClasses: []
  17. }),
  18. smalltalk.NodeTestRunner.klass);
  19. smalltalk.addMethod(
  20. smalltalk.method({
  21. selector: "runTestSuite",
  22. category: 'not yet classified',
  23. fn: function (){
  24. var self=this;
  25. var suite,worker;
  26. function $OrderedCollection(){return smalltalk.OrderedCollection||(typeof OrderedCollection=="undefined"?nil:OrderedCollection)}
  27. function $TestCase(){return smalltalk.TestCase||(typeof TestCase=="undefined"?nil:TestCase)}
  28. function $TestSuiteRunner(){return smalltalk.TestSuiteRunner||(typeof TestSuiteRunner=="undefined"?nil:TestSuiteRunner)}
  29. function $ResultAnnouncement(){return smalltalk.ResultAnnouncement||(typeof ResultAnnouncement=="undefined"?nil:ResultAnnouncement)}
  30. return smalltalk.withContext(function($ctx1) {
  31. var $1,$2,$3;
  32. suite=_st($OrderedCollection())._new();
  33. _st(_st(_st($TestCase())._allSubclasses())._select_((function(each){
  34. return smalltalk.withContext(function($ctx2) {
  35. return _st(_st(each)._isAbstract())._not();
  36. }, function($ctx2) {$ctx2.fillBlock({each:each},$ctx1)})})))._do_((function(each){
  37. return smalltalk.withContext(function($ctx2) {
  38. return _st(suite)._addAll_(_st(each)._buildSuite());
  39. }, function($ctx2) {$ctx2.fillBlock({each:each},$ctx1)})}));
  40. worker=_st($TestSuiteRunner())._on_(suite);
  41. _st(_st(worker)._announcer())._on_do_($ResultAnnouncement(),(function(ann){
  42. var result;
  43. return smalltalk.withContext(function($ctx2) {
  44. result=_st(ann)._result();
  45. result;
  46. $1=_st(_st(result)._runs()).__eq(_st(result)._total());
  47. if(smalltalk.assert($1)){
  48. _st(console)._log_(_st(_st(_st(_st(_st(_st(_st(result)._runs())._asString()).__comma(" tests run, ")).__comma(_st(_st(_st(result)._failures())._size())._asString())).__comma(" failures, ")).__comma(_st(_st(_st(result)._errors())._size())._asString())).__comma(" errors."));
  49. $2=_st(_st(result)._failures())._isEmpty();
  50. if(! smalltalk.assert($2)){
  51. _st(_st(_st(result)._failures())._first())._runCase();
  52. self._throw_(_st(_st(_st(_st(_st(_st(_st(result)._failures())._first())._class())._name()).__comma(" >> ")).__comma(_st(_st(_st(result)._failures())._first())._selector())).__comma(" is failing!"));
  53. };
  54. $3=_st(_st(result)._errors())._isEmpty();
  55. if(! smalltalk.assert($3)){
  56. _st(_st(_st(result)._errors())._first())._runCase();
  57. return self._throw_(_st(_st(_st(_st(_st(_st(_st(result)._errors())._first())._class())._name()).__comma(" >> ")).__comma(_st(_st(_st(result)._errors())._first())._selector())).__comma(" has errors!"));
  58. };
  59. };
  60. }, function($ctx2) {$ctx2.fillBlock({ann:ann,result:result},$ctx1)})}));
  61. _st(worker)._run();
  62. return self}, function($ctx1) {$ctx1.fill(self,"runTestSuite",{suite:suite,worker:worker},smalltalk.NodeTestRunner.klass)})},
  63. args: [],
  64. 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",
  65. messageSends: ["new", "do:", "addAll:", "buildSuite", "select:", "not", "isAbstract", "allSubclasses", "on:", "on:do:", "result", "ifTrue:", "log:", ",", "asString", "size", "errors", "failures", "runs", "ifFalse:", "runCase", "first", "throw:", "selector", "name", "class", "isEmpty", "=", "total", "announcer", "run"],
  66. referencedClasses: ["OrderedCollection", "TestCase", "TestSuiteRunner", "ResultAnnouncement"]
  67. }),
  68. smalltalk.NodeTestRunner.klass);
  69. })(global_smalltalk,global_nil,global__st);