SUnit-Tests.deploy.js 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314
  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. "_testAsyncErrorsAndFailures",
  130. smalltalk.method({
  131. selector: "testAsyncErrorsAndFailures",
  132. fn: function (){
  133. var self=this;
  134. var $1,$2,$4,$6,$5,$3;
  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. $1=smalltalk.send(runner,"_announcer",[]);
  151. $2=(smalltalk.ResultAnnouncement || ResultAnnouncement);
  152. $3=(function(ann){
  153. $4=smalltalk.send(smalltalk.send(ann,"_result",[]),"__eq_eq",[result]);
  154. $5=(function(){
  155. $6=smalltalk.send(smalltalk.send(result,"_runs",[]),"__eq",[smalltalk.send(result,"_total",[])]);
  156. return smalltalk.send($6,"_ifTrue_",[assertBlock]);
  157. });
  158. return smalltalk.send($4,"_ifTrue_",[$5]);
  159. });
  160. smalltalk.send($1,"_on_do_",[$2,$3]);
  161. smalltalk.send(runner,"_run",[]);
  162. return self}
  163. }),
  164. smalltalk.SUnitAsyncTest);
  165. smalltalk.addMethod(
  166. "_testAsyncNeedsGraceTime",
  167. smalltalk.method({
  168. selector: "testAsyncNeedsGraceTime",
  169. fn: function (){
  170. var self=this;
  171. smalltalk.send(self,"_should_raise_",[(function(){
  172. return smalltalk.send(self,"_async_",[(function(){
  173. })]);
  174. }),(smalltalk.Error || Error)]);
  175. smalltalk.send(self,"_graceTime_",[(0)]);
  176. smalltalk.send(self,"_shouldnt_raise_",[(function(){
  177. return smalltalk.send(self,"_async_",[(function(){
  178. })]);
  179. }),(smalltalk.Error || Error)]);
  180. smalltalk.send(self,"_finished",[]);
  181. return self}
  182. }),
  183. smalltalk.SUnitAsyncTest);
  184. smalltalk.addMethod(
  185. "_testFinishedNeedsGraceTime",
  186. smalltalk.method({
  187. selector: "testFinishedNeedsGraceTime",
  188. fn: function (){
  189. var self=this;
  190. smalltalk.send(self,"_should_raise_",[(function(){
  191. return smalltalk.send(self,"_finished",[]);
  192. }),(smalltalk.Error || Error)]);
  193. smalltalk.send(self,"_graceTime_",[(0)]);
  194. smalltalk.send(self,"_shouldnt_raise_",[(function(){
  195. return smalltalk.send(self,"_finished",[]);
  196. }),(smalltalk.Error || Error)]);
  197. return self}
  198. }),
  199. smalltalk.SUnitAsyncTest);
  200. smalltalk.addMethod(
  201. "_testIsAsyncReturnsCorrectValues",
  202. smalltalk.method({
  203. selector: "testIsAsyncReturnsCorrectValues",
  204. fn: function (){
  205. var self=this;
  206. smalltalk.send(self,"_deny_",[smalltalk.send(self,"_isAsync",[])]);
  207. smalltalk.send(self,"_graceTime_",[(0)]);
  208. smalltalk.send(self,"_assert_",[smalltalk.send(self,"_isAsync",[])]);
  209. smalltalk.send(self,"_finished",[]);
  210. smalltalk.send(self,"_deny_",[smalltalk.send(self,"_isAsync",[])]);
  211. return self}
  212. }),
  213. smalltalk.SUnitAsyncTest);
  214. smalltalk.addMethod(
  215. "_testPass",
  216. smalltalk.method({
  217. selector: "testPass",
  218. fn: function (){
  219. var self=this;
  220. self["@flag"]="bad";
  221. smalltalk.send(self,"_graceTime_",[(10)]);
  222. self["@flag"]=smalltalk.send(smalltalk.send(self,"_async_",[(function(){
  223. smalltalk.send(self,"_assert_",[true]);
  224. smalltalk.send(self,"_finished",[]);
  225. self["@flag"]="ok";
  226. return self["@flag"];
  227. })]),"_valueWithTimeout_",[(5)]);
  228. return self}
  229. }),
  230. smalltalk.SUnitAsyncTest);
  231. smalltalk.addMethod(
  232. "_testTimeouts",
  233. smalltalk.method({
  234. selector: "testTimeouts",
  235. fn: function (){
  236. var self=this;
  237. var $1,$2,$4,$6,$5,$3;
  238. var suite;
  239. var runner;
  240. var result;
  241. var assertBlock;
  242. suite=smalltalk.send(["fakeTimeout", "fakeMultipleGraceTimeFailing", "fakeMultipleGraceTimePassing", "testPass"],"_collect_",[(function(each){
  243. return smalltalk.send(smalltalk.send(self,"_class",[]),"_selector_",[each]);
  244. })]);
  245. runner=smalltalk.send((smalltalk.TestSuiteRunner || TestSuiteRunner),"_on_",[suite]);
  246. smalltalk.send(self,"_graceTime_",[(200)]);
  247. result=smalltalk.send(runner,"_result",[]);
  248. assertBlock=smalltalk.send(self,"_async_",[(function(){
  249. smalltalk.send(self,"_assert_",[smalltalk.send(smalltalk.send(result,"_errors",[]),"_isEmpty",[])]);
  250. smalltalk.send(self,"_assert_equals_",[["fakeMultipleGraceTimeFailing", "fakeTimeout"],smalltalk.send(self,"_sortedSelectors_",[smalltalk.send(result,"_failures",[])])]);
  251. return smalltalk.send(self,"_finished",[]);
  252. })]);
  253. $1=smalltalk.send(runner,"_announcer",[]);
  254. $2=(smalltalk.ResultAnnouncement || ResultAnnouncement);
  255. $3=(function(ann){
  256. $4=smalltalk.send(smalltalk.send(ann,"_result",[]),"__eq_eq",[result]);
  257. $5=(function(){
  258. $6=smalltalk.send(smalltalk.send(result,"_runs",[]),"__eq",[smalltalk.send(result,"_total",[])]);
  259. return smalltalk.send($6,"_ifTrue_",[assertBlock]);
  260. });
  261. return smalltalk.send($4,"_ifTrue_",[$5]);
  262. });
  263. smalltalk.send($1,"_on_do_",[$2,$3]);
  264. smalltalk.send(runner,"_run",[]);
  265. return self}
  266. }),
  267. smalltalk.SUnitAsyncTest);
  268. smalltalk.addMethod(
  269. "_testTwoAsyncPassesWithFinishedOnlyOneIsRun",
  270. smalltalk.method({
  271. selector: "testTwoAsyncPassesWithFinishedOnlyOneIsRun",
  272. fn: function (){
  273. var self=this;
  274. var x;
  275. self["@flag"]="bad";
  276. smalltalk.send(self,"_graceTime_",[(10)]);
  277. x=(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. self["@flag"]=smalltalk.send(smalltalk.send(self,"_async_",[(function(){
  287. smalltalk.send(self,"_finished",[]);
  288. self["@flag"]="ok";
  289. self["@flag"];
  290. x=smalltalk.send(x,"__plus",[(1)]);
  291. x;
  292. return smalltalk.send(self,"_assert_equals_",[(1),x]);
  293. })]),"_valueWithTimeout_",[(0)]);
  294. return self}
  295. }),
  296. smalltalk.SUnitAsyncTest);