SUnit-Tests.deploy.js 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. smalltalk.addPackage('SUnit-Tests', {});
  2. smalltalk.addClass('SUnitAsyncTest', smalltalk.TestCase, ['flag'], 'SUnit-Tests');
  3. smalltalk.addMethod(
  4. "_fakeError",
  5. smalltalk.method({
  6. selector: "fakeError",
  7. fn: function (){
  8. var self=this;
  9. self["@flag"]="bad";
  10. smalltalk.send(self,"_graceTime_",[(10)]);
  11. self["@flag"]=smalltalk.send(smalltalk.send(self,"_async_",[(function(){
  12. smalltalk.send(self,"_error_",["Intentional"]);
  13. smalltalk.send(self,"_finished",[]);
  14. self["@flag"]="ok";
  15. return self["@flag"];
  16. })]),"_valueWithTimeout_",[(5)]);
  17. return self}
  18. }),
  19. smalltalk.SUnitAsyncTest);
  20. smalltalk.addMethod(
  21. "_fakeFailure",
  22. smalltalk.method({
  23. selector: "fakeFailure",
  24. fn: function (){
  25. var self=this;
  26. self["@flag"]="bad";
  27. smalltalk.send(self,"_graceTime_",[(10)]);
  28. self["@flag"]=smalltalk.send(smalltalk.send(self,"_async_",[(function(){
  29. smalltalk.send(self,"_assert_",[false]);
  30. smalltalk.send(self,"_finished",[]);
  31. self["@flag"]="ok";
  32. return self["@flag"];
  33. })]),"_valueWithTimeout_",[(5)]);
  34. return self}
  35. }),
  36. smalltalk.SUnitAsyncTest);
  37. smalltalk.addMethod(
  38. "_setUp",
  39. smalltalk.method({
  40. selector: "setUp",
  41. fn: function (){
  42. var self=this;
  43. self["@flag"]="ok";
  44. return self}
  45. }),
  46. smalltalk.SUnitAsyncTest);
  47. smalltalk.addMethod(
  48. "_tearDown",
  49. smalltalk.method({
  50. selector: "tearDown",
  51. fn: function (){
  52. var self=this;
  53. smalltalk.send(self,"_assert_equals_",["ok",self["@flag"]]);
  54. return self}
  55. }),
  56. smalltalk.SUnitAsyncTest);
  57. smalltalk.addMethod(
  58. "_testAsyncErrorsAndFailuresWork",
  59. smalltalk.method({
  60. selector: "testAsyncErrorsAndFailuresWork",
  61. fn: function (){
  62. var self=this;
  63. var $1,$2;
  64. var suite;
  65. var runner;
  66. var result;
  67. var assertBlock;
  68. suite=[smalltalk.send(smalltalk.send(self,"_class",[]),"_selector_",["fakeError"]),smalltalk.send(smalltalk.send(self,"_class",[]),"_selector_",["fakeFailure"]),smalltalk.send(smalltalk.send(self,"_class",[]),"_selector_",["testPass"])];
  69. runner=smalltalk.send((smalltalk.TestSuiteRunner || TestSuiteRunner),"_on_",[suite]);
  70. smalltalk.send(self,"_graceTime_",[(200)]);
  71. result=smalltalk.send(runner,"_result",[]);
  72. assertBlock=smalltalk.send(self,"_async_",[(function(){
  73. smalltalk.send(self,"_assert_equals_",[(1),smalltalk.send(smalltalk.send(result,"_errors",[]),"_size",[])]);
  74. smalltalk.send(self,"_assert_equals_",["fakeError",smalltalk.send(smalltalk.send(smalltalk.send(result,"_errors",[]),"_first",[]),"_selector",[])]);
  75. smalltalk.send(self,"_assert_equals_",[(1),smalltalk.send(smalltalk.send(result,"_failures",[]),"_size",[])]);
  76. smalltalk.send(self,"_assert_equals_",["fakeFailure",smalltalk.send(smalltalk.send(smalltalk.send(result,"_failures",[]),"_first",[]),"_selector",[])]);
  77. return smalltalk.send(self,"_finished",[]);
  78. })]);
  79. smalltalk.send(smalltalk.send(runner,"_announcer",[]),"_on_do_",[(smalltalk.ResultAnnouncement || ResultAnnouncement),(function(ann){
  80. $1=smalltalk.send(smalltalk.send(ann,"_result",[]),"__eq_eq",[result]);
  81. if(smalltalk.assert($1)){
  82. $2=smalltalk.send(smalltalk.send(result,"_runs",[]),"__eq",[smalltalk.send(result,"_total",[])]);
  83. return smalltalk.send($2,"_ifTrue_",[assertBlock]);
  84. };
  85. })]);
  86. smalltalk.send(runner,"_run",[]);
  87. return self}
  88. }),
  89. smalltalk.SUnitAsyncTest);
  90. smalltalk.addMethod(
  91. "_testAsyncNeedsGraceTime",
  92. smalltalk.method({
  93. selector: "testAsyncNeedsGraceTime",
  94. fn: function (){
  95. var self=this;
  96. smalltalk.send(self,"_should_raise_",[(function(){
  97. return smalltalk.send(self,"_async_",[(function(){
  98. })]);
  99. }),(smalltalk.Error || Error)]);
  100. smalltalk.send(self,"_graceTime_",[(0)]);
  101. smalltalk.send(self,"_shouldnt_raise_",[(function(){
  102. return smalltalk.send(self,"_async_",[(function(){
  103. })]);
  104. }),(smalltalk.Error || Error)]);
  105. smalltalk.send(self,"_finished",[]);
  106. return self}
  107. }),
  108. smalltalk.SUnitAsyncTest);
  109. smalltalk.addMethod(
  110. "_testFinishedNeedsGraceTime",
  111. smalltalk.method({
  112. selector: "testFinishedNeedsGraceTime",
  113. fn: function (){
  114. var self=this;
  115. smalltalk.send(self,"_should_raise_",[(function(){
  116. return smalltalk.send(self,"_finished",[]);
  117. }),(smalltalk.Error || Error)]);
  118. smalltalk.send(self,"_graceTime_",[(0)]);
  119. smalltalk.send(self,"_shouldnt_raise_",[(function(){
  120. return smalltalk.send(self,"_finished",[]);
  121. }),(smalltalk.Error || Error)]);
  122. return self}
  123. }),
  124. smalltalk.SUnitAsyncTest);
  125. smalltalk.addMethod(
  126. "_testIsAsyncReturnsCorrectValues",
  127. smalltalk.method({
  128. selector: "testIsAsyncReturnsCorrectValues",
  129. fn: function (){
  130. var self=this;
  131. smalltalk.send(self,"_deny_",[smalltalk.send(self,"_isAsync",[])]);
  132. smalltalk.send(self,"_graceTime_",[(0)]);
  133. smalltalk.send(self,"_assert_",[smalltalk.send(self,"_isAsync",[])]);
  134. smalltalk.send(self,"_finished",[]);
  135. smalltalk.send(self,"_deny_",[smalltalk.send(self,"_isAsync",[])]);
  136. return self}
  137. }),
  138. smalltalk.SUnitAsyncTest);
  139. smalltalk.addMethod(
  140. "_testPass",
  141. smalltalk.method({
  142. selector: "testPass",
  143. fn: function (){
  144. var self=this;
  145. self["@flag"]="bad";
  146. smalltalk.send(self,"_graceTime_",[(10)]);
  147. self["@flag"]=smalltalk.send(smalltalk.send(self,"_async_",[(function(){
  148. smalltalk.send(self,"_assert_",[true]);
  149. smalltalk.send(self,"_finished",[]);
  150. self["@flag"]="ok";
  151. return self["@flag"];
  152. })]),"_valueWithTimeout_",[(5)]);
  153. return self}
  154. }),
  155. smalltalk.SUnitAsyncTest);