Test.js 4.3 KB

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