SUnit-Tests.deploy.js 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306
  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. "_fakeMultipleGraceTimeFailing",
  51. smalltalk.method({
  52. selector: "fakeMultipleGraceTimeFailing",
  53. fn: function (){
  54. var self=this;
  55. smalltalk.send(self,"_graceTime_",[(100)]);
  56. smalltalk.send(smalltalk.send(self,"_async_",[(function(){
  57. smalltalk.send(self,"_graceTime_",[(5)]);
  58. return smalltalk.send(smalltalk.send(self,"_async_",[(function(){
  59. return smalltalk.send(self,"_finished",[]);
  60. })]),"_valueWithTimeout_",[(10)]);
  61. })]),"_valueWithTimeout_",[(5)]);
  62. return self}
  63. }),
  64. smalltalk.SUnitAsyncTest);
  65. smalltalk.addMethod(
  66. "_fakeMultipleGraceTimePassing",
  67. smalltalk.method({
  68. selector: "fakeMultipleGraceTimePassing",
  69. fn: function (){
  70. var self=this;
  71. smalltalk.send(self,"_graceTime_",[(10)]);
  72. smalltalk.send(smalltalk.send(self,"_async_",[(function(){
  73. smalltalk.send(self,"_graceTime_",[(20)]);
  74. return smalltalk.send(smalltalk.send(self,"_async_",[(function(){
  75. return smalltalk.send(self,"_finished",[]);
  76. })]),"_valueWithTimeout_",[(10)]);
  77. })]),"_valueWithTimeout_",[(5)]);
  78. return self}
  79. }),
  80. smalltalk.SUnitAsyncTest);
  81. smalltalk.addMethod(
  82. "_fakeTimeout",
  83. smalltalk.method({
  84. selector: "fakeTimeout",
  85. fn: function (){
  86. var self=this;
  87. smalltalk.send(self,"_graceTime_",[(4)]);
  88. smalltalk.send(smalltalk.send(self,"_async_",[(function(){
  89. return smalltalk.send(self,"_finished",[]);
  90. })]),"_valueWithTimeout_",[(5)]);
  91. return self}
  92. }),
  93. smalltalk.SUnitAsyncTest);
  94. smalltalk.addMethod(
  95. "_setUp",
  96. smalltalk.method({
  97. selector: "setUp",
  98. fn: function (){
  99. var self=this;
  100. self["@flag"]="ok";
  101. return self}
  102. }),
  103. smalltalk.SUnitAsyncTest);
  104. smalltalk.addMethod(
  105. "_sortedSelectors_",
  106. smalltalk.method({
  107. selector: "sortedSelectors:",
  108. fn: function (aCollection){
  109. var self=this;
  110. var $1;
  111. $1=smalltalk.send(smalltalk.send(aCollection,"_collect_",[(function(each){
  112. return smalltalk.send(each,"_selector",[]);
  113. })]),"_sorted",[]);
  114. return $1;
  115. }
  116. }),
  117. smalltalk.SUnitAsyncTest);
  118. smalltalk.addMethod(
  119. "_tearDown",
  120. smalltalk.method({
  121. selector: "tearDown",
  122. fn: function (){
  123. var self=this;
  124. smalltalk.send(self,"_assert_equals_",["ok",self["@flag"]]);
  125. return self}
  126. }),
  127. smalltalk.SUnitAsyncTest);
  128. smalltalk.addMethod(
  129. "_testAsyncErrorsAndFailuresWork",
  130. smalltalk.method({
  131. selector: "testAsyncErrorsAndFailuresWork",
  132. fn: function (){
  133. var self=this;
  134. var $1,$2;
  135. var suite;
  136. var runner;
  137. var result;
  138. var assertBlock;
  139. suite=smalltalk.send(["fakeError", "fakeErrorFailingInTearDown", "fakeFailure", "testPass"],"_collect_",[(function(each){
  140. return smalltalk.send(smalltalk.send(self,"_class",[]),"_selector_",[each]);
  141. })]);
  142. runner=smalltalk.send((smalltalk.TestSuiteRunner || TestSuiteRunner),"_on_",[suite]);
  143. smalltalk.send(self,"_graceTime_",[(200)]);
  144. result=smalltalk.send(runner,"_result",[]);
  145. assertBlock=smalltalk.send(self,"_async_",[(function(){
  146. smalltalk.send(self,"_assert_equals_",[["fakeError"],smalltalk.send(self,"_sortedSelectors_",[smalltalk.send(result,"_errors",[])])]);
  147. smalltalk.send(self,"_assert_equals_",[["fakeErrorFailingInTearDown", "fakeFailure"],smalltalk.send(self,"_sortedSelectors_",[smalltalk.send(result,"_failures",[])])]);
  148. return smalltalk.send(self,"_finished",[]);
  149. })]);
  150. smalltalk.send(smalltalk.send(runner,"_announcer",[]),"_on_do_",[(smalltalk.ResultAnnouncement || ResultAnnouncement),(function(ann){
  151. $1=smalltalk.send(smalltalk.send(ann,"_result",[]),"__eq_eq",[result]);
  152. if(smalltalk.assert($1)){
  153. $2=smalltalk.send(smalltalk.send(result,"_runs",[]),"__eq",[smalltalk.send(result,"_total",[])]);
  154. return smalltalk.send($2,"_ifTrue_",[assertBlock]);
  155. };
  156. })]);
  157. smalltalk.send(runner,"_run",[]);
  158. return self}
  159. }),
  160. smalltalk.SUnitAsyncTest);
  161. smalltalk.addMethod(
  162. "_testAsyncNeedsGraceTime",
  163. smalltalk.method({
  164. selector: "testAsyncNeedsGraceTime",
  165. fn: function (){
  166. var self=this;
  167. smalltalk.send(self,"_should_raise_",[(function(){
  168. return smalltalk.send(self,"_async_",[(function(){
  169. })]);
  170. }),(smalltalk.Error || Error)]);
  171. smalltalk.send(self,"_graceTime_",[(0)]);
  172. smalltalk.send(self,"_shouldnt_raise_",[(function(){
  173. return smalltalk.send(self,"_async_",[(function(){
  174. })]);
  175. }),(smalltalk.Error || Error)]);
  176. smalltalk.send(self,"_finished",[]);
  177. return self}
  178. }),
  179. smalltalk.SUnitAsyncTest);
  180. smalltalk.addMethod(
  181. "_testFinishedNeedsGraceTime",
  182. smalltalk.method({
  183. selector: "testFinishedNeedsGraceTime",
  184. fn: function (){
  185. var self=this;
  186. smalltalk.send(self,"_should_raise_",[(function(){
  187. return smalltalk.send(self,"_finished",[]);
  188. }),(smalltalk.Error || Error)]);
  189. smalltalk.send(self,"_graceTime_",[(0)]);
  190. smalltalk.send(self,"_shouldnt_raise_",[(function(){
  191. return smalltalk.send(self,"_finished",[]);
  192. }),(smalltalk.Error || Error)]);
  193. return self}
  194. }),
  195. smalltalk.SUnitAsyncTest);
  196. smalltalk.addMethod(
  197. "_testIsAsyncReturnsCorrectValues",
  198. smalltalk.method({
  199. selector: "testIsAsyncReturnsCorrectValues",
  200. fn: function (){
  201. var self=this;
  202. smalltalk.send(self,"_deny_",[smalltalk.send(self,"_isAsync",[])]);
  203. smalltalk.send(self,"_graceTime_",[(0)]);
  204. smalltalk.send(self,"_assert_",[smalltalk.send(self,"_isAsync",[])]);
  205. smalltalk.send(self,"_finished",[]);
  206. smalltalk.send(self,"_deny_",[smalltalk.send(self,"_isAsync",[])]);
  207. return self}
  208. }),
  209. smalltalk.SUnitAsyncTest);
  210. smalltalk.addMethod(
  211. "_testPass",
  212. smalltalk.method({
  213. selector: "testPass",
  214. fn: function (){
  215. var self=this;
  216. self["@flag"]="bad";
  217. smalltalk.send(self,"_graceTime_",[(10)]);
  218. self["@flag"]=smalltalk.send(smalltalk.send(self,"_async_",[(function(){
  219. smalltalk.send(self,"_assert_",[true]);
  220. smalltalk.send(self,"_finished",[]);
  221. self["@flag"]="ok";
  222. return self["@flag"];
  223. })]),"_valueWithTimeout_",[(5)]);
  224. return self}
  225. }),
  226. smalltalk.SUnitAsyncTest);
  227. smalltalk.addMethod(
  228. "_testTimeoutsWork",
  229. smalltalk.method({
  230. selector: "testTimeoutsWork",
  231. fn: function (){
  232. var self=this;
  233. var $1,$2;
  234. var suite;
  235. var runner;
  236. var result;
  237. var assertBlock;
  238. suite=smalltalk.send(["fakeTimeout", "fakeMultipleGraceTimeFailing", "fakeMultipleGraceTimePassing", "testPass"],"_collect_",[(function(each){
  239. return smalltalk.send(smalltalk.send(self,"_class",[]),"_selector_",[each]);
  240. })]);
  241. runner=smalltalk.send((smalltalk.TestSuiteRunner || TestSuiteRunner),"_on_",[suite]);
  242. smalltalk.send(self,"_graceTime_",[(200)]);
  243. result=smalltalk.send(runner,"_result",[]);
  244. assertBlock=smalltalk.send(self,"_async_",[(function(){
  245. smalltalk.send(self,"_assert_",[smalltalk.send(smalltalk.send(result,"_errors",[]),"_isEmpty",[])]);
  246. smalltalk.send(self,"_assert_equals_",[["fakeMultipleGraceTimeFailing", "fakeTimeout"],smalltalk.send(self,"_sortedSelectors_",[smalltalk.send(result,"_failures",[])])]);
  247. return smalltalk.send(self,"_finished",[]);
  248. })]);
  249. smalltalk.send(smalltalk.send(runner,"_announcer",[]),"_on_do_",[(smalltalk.ResultAnnouncement || ResultAnnouncement),(function(ann){
  250. $1=smalltalk.send(smalltalk.send(ann,"_result",[]),"__eq_eq",[result]);
  251. if(smalltalk.assert($1)){
  252. $2=smalltalk.send(smalltalk.send(result,"_runs",[]),"__eq",[smalltalk.send(result,"_total",[])]);
  253. return smalltalk.send($2,"_ifTrue_",[assertBlock]);
  254. };
  255. })]);
  256. smalltalk.send(runner,"_run",[]);
  257. return self}
  258. }),
  259. smalltalk.SUnitAsyncTest);
  260. smalltalk.addMethod(
  261. "_testTwoAsyncPassesWithFinishedOnlyOneIsRun",
  262. smalltalk.method({
  263. selector: "testTwoAsyncPassesWithFinishedOnlyOneIsRun",
  264. fn: function (){
  265. var self=this;
  266. var x;
  267. self["@flag"]="bad";
  268. smalltalk.send(self,"_graceTime_",[(10)]);
  269. x=(0);
  270. self["@flag"]=smalltalk.send(smalltalk.send(self,"_async_",[(function(){
  271. smalltalk.send(self,"_finished",[]);
  272. self["@flag"]="ok";
  273. self["@flag"];
  274. x=smalltalk.send(x,"__plus",[(1)]);
  275. x;
  276. return smalltalk.send(self,"_assert_equals_",[(1),x]);
  277. })]),"_valueWithTimeout_",[(0)]);
  278. self["@flag"]=smalltalk.send(smalltalk.send(self,"_async_",[(function(){
  279. smalltalk.send(self,"_finished",[]);
  280. self["@flag"]="ok";
  281. self["@flag"];
  282. x=smalltalk.send(x,"__plus",[(1)]);
  283. x;
  284. return smalltalk.send(self,"_assert_equals_",[(1),x]);
  285. })]),"_valueWithTimeout_",[(0)]);
  286. return self}
  287. }),
  288. smalltalk.SUnitAsyncTest);