1
0

Test.js 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. smalltalk.addPackage('Test', {});
  2. smalltalk.addClass('NodeTestRunner', smalltalk.Object, [], 'Test');
  3. smalltalk.addMethod(
  4. "_initialize",
  5. smalltalk.method({
  6. selector: "initialize",
  7. category: 'not yet classified',
  8. fn: function (){
  9. var self=this;
  10. smalltalk.send(self, "_runTestSuite", []);
  11. return self;},
  12. args: [],
  13. source: "initialize\x0d\x0a\x09self runTestSuite",
  14. messageSends: ["runTestSuite"],
  15. referencedClasses: []
  16. }),
  17. smalltalk.NodeTestRunner.klass);
  18. smalltalk.addMethod(
  19. "_runTestSuite",
  20. smalltalk.method({
  21. selector: "runTestSuite",
  22. category: 'not yet classified',
  23. fn: function (){
  24. var self=this;
  25. var $1,$2,$3;
  26. var suite;
  27. var worker;
  28. suite=smalltalk.send((smalltalk.OrderedCollection || OrderedCollection),"_new",[]);
  29. smalltalk.send(smalltalk.send(smalltalk.send((smalltalk.TestCase || TestCase),"_allSubclasses",[]),"_select_",[(function(each){
  30. return smalltalk.send(smalltalk.send(each,"_isAbstract",[]),"_not",[]);
  31. })]),"_do_",[(function(each){
  32. return smalltalk.send(suite,"_addAll_",[smalltalk.send(each,"_buildSuite",[])]);
  33. })]);
  34. worker=smalltalk.send((smalltalk.TestSuiteRunner || TestSuiteRunner),"_on_",[suite]);
  35. smalltalk.send(smalltalk.send(worker,"_announcer",[]),"_on_do_",[(smalltalk.ResultAnnouncement || ResultAnnouncement),(function(ann){
  36. var result;
  37. result=smalltalk.send(ann,"_result",[]);
  38. result;
  39. $1=smalltalk.send(smalltalk.send(result,"_runs",[]),"__eq",[smalltalk.send(result,"_total",[])]);
  40. if(smalltalk.assert($1)){
  41. smalltalk.send(console,"_log_",[smalltalk.send(smalltalk.send(smalltalk.send(smalltalk.send(smalltalk.send(smalltalk.send(smalltalk.send(result,"_runs",[]),"_asString",[]),"__comma",[" tests run, "]),"__comma",[smalltalk.send(smalltalk.send(smalltalk.send(result,"_failures",[]),"_size",[]),"_asString",[])]),"__comma",[" failures, "]),"__comma",[smalltalk.send(smalltalk.send(smalltalk.send(result,"_errors",[]),"_size",[]),"_asString",[])]),"__comma",[" errors."])]);
  42. $2=smalltalk.send(smalltalk.send(result,"_failures",[]),"_isEmpty",[]);
  43. if(! smalltalk.assert($2)){
  44. smalltalk.send(self,"_throw_",[smalltalk.send(smalltalk.send(smalltalk.send(smalltalk.send(smalltalk.send(smalltalk.send(smalltalk.send(result,"_failures",[]),"_first",[]),"_class",[]),"_name",[]),"__comma",[" >> "]),"__comma",[smalltalk.send(smalltalk.send(smalltalk.send(result,"_failures",[]),"_first",[]),"_selector",[])]),"__comma",[" is failing!"])]);
  45. };
  46. $3=smalltalk.send(smalltalk.send(result,"_errors",[]),"_isEmpty",[]);
  47. if(! smalltalk.assert($3)){
  48. return smalltalk.send(self,"_throw_",[smalltalk.send(smalltalk.send(smalltalk.send(smalltalk.send(smalltalk.send(smalltalk.send(smalltalk.send(result,"_errors",[]),"_first",[]),"_class",[]),"_name",[]),"__comma",[" >> "]),"__comma",[smalltalk.send(smalltalk.send(smalltalk.send(result,"_errors",[]),"_first",[]),"_selector",[])]),"__comma",[" has errors!"])]);
  49. };
  50. };
  51. })]);
  52. smalltalk.send(worker,"_run",[]);
  53. return self},
  54. args: [],
  55. 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",
  56. 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"],
  57. referencedClasses: ["OrderedCollection", "TestCase", "TestSuiteRunner", "ResultAnnouncement"]
  58. }),
  59. smalltalk.NodeTestRunner.klass);