Test.js 5.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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: "initialize",
  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,"initialize",{},smalltalk.NodeTestRunner.klass)})},
  14. args: [],
  15. source: "initialize\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 $1,$2,$3;
  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. $1=_st(_st(result)._runs()).__eq(_st(result)._total());
  48. if(smalltalk.assert($1)){
  49. _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."));
  50. $2=_st(_st(result)._failures())._isEmpty();
  51. if(! smalltalk.assert($2)){
  52. _st(_st(_st(result)._failures())._first())._runCase();
  53. 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!"));
  54. };
  55. $3=_st(_st(result)._errors())._isEmpty();
  56. if(! smalltalk.assert($3)){
  57. _st(_st(_st(result)._errors())._first())._runCase();
  58. 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!"));
  59. };
  60. };
  61. }, function($ctx2) {$ctx2.fillBlock({ann:ann,result:result},$ctx1,3)})}));
  62. _st(worker)._run();
  63. return self}, function($ctx1) {$ctx1.fill(self,"runTestSuite",{suite:suite,worker:worker},smalltalk.NodeTestRunner.klass)})},
  64. args: [],
  65. 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",
  66. 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"],
  67. referencedClasses: ["OrderedCollection", "TestCase", "TestSuiteRunner", "ResultAnnouncement"]
  68. }),
  69. smalltalk.NodeTestRunner.klass);
  70. });