SUnit-Tests.deploy.js 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  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. self["@flag"]="ok";
  13. self["@flag"];
  14. return smalltalk.send(self,"_error_",["Intentional"]);
  15. })]),"_valueWithTimeout_",[(5)]);
  16. return self}
  17. }),
  18. smalltalk.SUnitAsyncTest);
  19. smalltalk.addMethod(
  20. "_fakeErrorFailingInTearDown",
  21. smalltalk.method({
  22. selector: "fakeErrorFailingInTearDown",
  23. fn: function (){
  24. var self=this;
  25. self["@flag"]="bad";
  26. smalltalk.send(self,"_graceTime_",[(10)]);
  27. self["@flag"]=smalltalk.send(smalltalk.send(self,"_async_",[(function(){
  28. return smalltalk.send(self,"_error_",["Intentional"]);
  29. })]),"_valueWithTimeout_",[(5)]);
  30. return self}
  31. }),
  32. smalltalk.SUnitAsyncTest);
  33. smalltalk.addMethod(
  34. "_fakeFailure",
  35. smalltalk.method({
  36. selector: "fakeFailure",
  37. fn: function (){
  38. var self=this;
  39. self["@flag"]="bad";
  40. smalltalk.send(self,"_graceTime_",[(10)]);
  41. self["@flag"]=smalltalk.send(smalltalk.send(self,"_async_",[(function(){
  42. self["@flag"]="ok";
  43. self["@flag"];
  44. return smalltalk.send(self,"_assert_",[false]);
  45. })]),"_valueWithTimeout_",[(5)]);
  46. return self}
  47. }),
  48. smalltalk.SUnitAsyncTest);
  49. smalltalk.addMethod(
  50. "_setUp",
  51. smalltalk.method({
  52. selector: "setUp",
  53. fn: function (){
  54. var self=this;
  55. self["@flag"]="ok";
  56. return self}
  57. }),
  58. smalltalk.SUnitAsyncTest);
  59. smalltalk.addMethod(
  60. "_sortedSelectors_",
  61. smalltalk.method({
  62. selector: "sortedSelectors:",
  63. fn: function (aCollection){
  64. var self=this;
  65. var $1;
  66. $1=smalltalk.send(smalltalk.send(aCollection,"_collect_",[(function(each){
  67. return smalltalk.send(each,"_selector",[]);
  68. })]),"_sorted",[]);
  69. return $1;
  70. }
  71. }),
  72. smalltalk.SUnitAsyncTest);
  73. smalltalk.addMethod(
  74. "_tearDown",
  75. smalltalk.method({
  76. selector: "tearDown",
  77. fn: function (){
  78. var self=this;
  79. smalltalk.send(self,"_assert_equals_",["ok",self["@flag"]]);
  80. return self}
  81. }),
  82. smalltalk.SUnitAsyncTest);
  83. smalltalk.addMethod(
  84. "_testAsyncErrorsAndFailuresWork",
  85. smalltalk.method({
  86. selector: "testAsyncErrorsAndFailuresWork",
  87. fn: function (){
  88. var self=this;
  89. var $1,$2;
  90. var suite;
  91. var runner;
  92. var result;
  93. var assertBlock;
  94. suite=smalltalk.send(["fakeError", "fakeErrorFailingInTearDown", "fakeFailure", "testPass"],"_collect_",[(function(each){
  95. return smalltalk.send(smalltalk.send(self,"_class",[]),"_selector_",[each]);
  96. })]);
  97. runner=smalltalk.send((smalltalk.TestSuiteRunner || TestSuiteRunner),"_on_",[suite]);
  98. smalltalk.send(self,"_graceTime_",[(200)]);
  99. result=smalltalk.send(runner,"_result",[]);
  100. assertBlock=smalltalk.send(self,"_async_",[(function(){
  101. smalltalk.send(self,"_assert_equals_",[["fakeError"],smalltalk.send(self,"_sortedSelectors_",[smalltalk.send(result,"_errors",[])])]);
  102. smalltalk.send(self,"_assert_equals_",[["fakeErrorFailingInTearDown", "fakeFailure"],smalltalk.send(self,"_sortedSelectors_",[smalltalk.send(result,"_failures",[])])]);
  103. return smalltalk.send(self,"_finished",[]);
  104. })]);
  105. smalltalk.send(smalltalk.send(runner,"_announcer",[]),"_on_do_",[(smalltalk.ResultAnnouncement || ResultAnnouncement),(function(ann){
  106. $1=smalltalk.send(smalltalk.send(ann,"_result",[]),"__eq_eq",[result]);
  107. if(smalltalk.assert($1)){
  108. $2=smalltalk.send(smalltalk.send(result,"_runs",[]),"__eq",[smalltalk.send(result,"_total",[])]);
  109. return smalltalk.send($2,"_ifTrue_",[assertBlock]);
  110. };
  111. })]);
  112. smalltalk.send(runner,"_run",[]);
  113. return self}
  114. }),
  115. smalltalk.SUnitAsyncTest);
  116. smalltalk.addMethod(
  117. "_testAsyncNeedsGraceTime",
  118. smalltalk.method({
  119. selector: "testAsyncNeedsGraceTime",
  120. fn: function (){
  121. var self=this;
  122. smalltalk.send(self,"_should_raise_",[(function(){
  123. return smalltalk.send(self,"_async_",[(function(){
  124. })]);
  125. }),(smalltalk.Error || Error)]);
  126. smalltalk.send(self,"_graceTime_",[(0)]);
  127. smalltalk.send(self,"_shouldnt_raise_",[(function(){
  128. return smalltalk.send(self,"_async_",[(function(){
  129. })]);
  130. }),(smalltalk.Error || Error)]);
  131. smalltalk.send(self,"_finished",[]);
  132. return self}
  133. }),
  134. smalltalk.SUnitAsyncTest);
  135. smalltalk.addMethod(
  136. "_testFinishedNeedsGraceTime",
  137. smalltalk.method({
  138. selector: "testFinishedNeedsGraceTime",
  139. fn: function (){
  140. var self=this;
  141. smalltalk.send(self,"_should_raise_",[(function(){
  142. return smalltalk.send(self,"_finished",[]);
  143. }),(smalltalk.Error || Error)]);
  144. smalltalk.send(self,"_graceTime_",[(0)]);
  145. smalltalk.send(self,"_shouldnt_raise_",[(function(){
  146. return smalltalk.send(self,"_finished",[]);
  147. }),(smalltalk.Error || Error)]);
  148. return self}
  149. }),
  150. smalltalk.SUnitAsyncTest);
  151. smalltalk.addMethod(
  152. "_testIsAsyncReturnsCorrectValues",
  153. smalltalk.method({
  154. selector: "testIsAsyncReturnsCorrectValues",
  155. fn: function (){
  156. var self=this;
  157. smalltalk.send(self,"_deny_",[smalltalk.send(self,"_isAsync",[])]);
  158. smalltalk.send(self,"_graceTime_",[(0)]);
  159. smalltalk.send(self,"_assert_",[smalltalk.send(self,"_isAsync",[])]);
  160. smalltalk.send(self,"_finished",[]);
  161. smalltalk.send(self,"_deny_",[smalltalk.send(self,"_isAsync",[])]);
  162. return self}
  163. }),
  164. smalltalk.SUnitAsyncTest);
  165. smalltalk.addMethod(
  166. "_testPass",
  167. smalltalk.method({
  168. selector: "testPass",
  169. fn: function (){
  170. var self=this;
  171. self["@flag"]="bad";
  172. smalltalk.send(self,"_graceTime_",[(10)]);
  173. self["@flag"]=smalltalk.send(smalltalk.send(self,"_async_",[(function(){
  174. smalltalk.send(self,"_assert_",[true]);
  175. smalltalk.send(self,"_finished",[]);
  176. self["@flag"]="ok";
  177. return self["@flag"];
  178. })]),"_valueWithTimeout_",[(5)]);
  179. return self}
  180. }),
  181. smalltalk.SUnitAsyncTest);
  182. smalltalk.addMethod(
  183. "_testTwoAsyncPassesWithFinishedOnlyOneIsRun",
  184. smalltalk.method({
  185. selector: "testTwoAsyncPassesWithFinishedOnlyOneIsRun",
  186. fn: function (){
  187. var self=this;
  188. var x;
  189. self["@flag"]="bad";
  190. smalltalk.send(self,"_graceTime_",[(10)]);
  191. x=(0);
  192. self["@flag"]=smalltalk.send(smalltalk.send(self,"_async_",[(function(){
  193. smalltalk.send(self,"_finished",[]);
  194. self["@flag"]="ok";
  195. self["@flag"];
  196. x=smalltalk.send(x,"__plus",[(1)]);
  197. x;
  198. return smalltalk.send(self,"_assert_equals_",[(1),x]);
  199. })]),"_valueWithTimeout_",[(0)]);
  200. self["@flag"]=smalltalk.send(smalltalk.send(self,"_async_",[(function(){
  201. smalltalk.send(self,"_finished",[]);
  202. self["@flag"]="ok";
  203. self["@flag"];
  204. x=smalltalk.send(x,"__plus",[(1)]);
  205. x;
  206. return smalltalk.send(self,"_assert_equals_",[(1),x]);
  207. })]),"_valueWithTimeout_",[(0)]);
  208. return self}
  209. }),
  210. smalltalk.SUnitAsyncTest);