SUnit-Tests.deploy.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408
  1. smalltalk.addPackage('SUnit-Tests', {});
  2. smalltalk.addClass('ExampleSetTest', smalltalk.TestCase, ['empty', 'full'], 'SUnit-Tests');
  3. smalltalk.addMethod(
  4. "_setUp",
  5. smalltalk.method({
  6. selector: "setUp",
  7. fn: function (){
  8. var self=this;
  9. self["@empty"]=smalltalk.send((smalltalk.Set || Set),"_new",[]);
  10. self["@full"]=smalltalk.send((smalltalk.Set || Set),"_with_with_",[(5),smalltalk.symbolFor("abc")]);
  11. return self}
  12. }),
  13. smalltalk.ExampleSetTest);
  14. smalltalk.addMethod(
  15. "_testAdd",
  16. smalltalk.method({
  17. selector: "testAdd",
  18. fn: function (){
  19. var self=this;
  20. smalltalk.send(self["@empty"],"_add_",[(5)]);
  21. smalltalk.send(self,"_assert_",[smalltalk.send(self["@empty"],"_includes_",[(5)])]);
  22. return self}
  23. }),
  24. smalltalk.ExampleSetTest);
  25. smalltalk.addMethod(
  26. "_testGrow",
  27. smalltalk.method({
  28. selector: "testGrow",
  29. fn: function (){
  30. var self=this;
  31. smalltalk.send(self["@empty"],"_addAll_",[smalltalk.send((1),"_to_",[(100)])]);
  32. smalltalk.send(self,"_assert_",[smalltalk.send(smalltalk.send(self["@empty"],"_size",[]),"__eq",[(100)])]);
  33. return self}
  34. }),
  35. smalltalk.ExampleSetTest);
  36. smalltalk.addMethod(
  37. "_testIllegal",
  38. smalltalk.method({
  39. selector: "testIllegal",
  40. fn: function (){
  41. var self=this;
  42. smalltalk.send(self,"_should_raise_",[(function(){
  43. return smalltalk.send(self["@empty"],"_at_",[(5)]);
  44. }),(smalltalk.Error || Error)]);
  45. smalltalk.send(self,"_should_raise_",[(function(){
  46. return smalltalk.send(self["@empty"],"_at_put_",[(5),smalltalk.symbolFor("abc")]);
  47. }),(smalltalk.Error || Error)]);
  48. return self}
  49. }),
  50. smalltalk.ExampleSetTest);
  51. smalltalk.addMethod(
  52. "_testIncludes",
  53. smalltalk.method({
  54. selector: "testIncludes",
  55. fn: function (){
  56. var self=this;
  57. smalltalk.send(self,"_assert_",[smalltalk.send(self["@full"],"_includes_",[(5)])]);
  58. smalltalk.send(self,"_assert_",[smalltalk.send(self["@full"],"_includes_",[smalltalk.symbolFor("abc")])]);
  59. return self}
  60. }),
  61. smalltalk.ExampleSetTest);
  62. smalltalk.addMethod(
  63. "_testOccurrences",
  64. smalltalk.method({
  65. selector: "testOccurrences",
  66. fn: function (){
  67. var self=this;
  68. smalltalk.send(self,"_assert_",[smalltalk.send(smalltalk.send(self["@empty"],"_occurrencesOf_",[(0)]),"__eq",[(0)])]);
  69. smalltalk.send(self,"_assert_",[smalltalk.send(smalltalk.send(self["@full"],"_occurrencesOf_",[(5)]),"__eq",[(1)])]);
  70. smalltalk.send(self["@full"],"_add_",[(5)]);
  71. smalltalk.send(self,"_assert_",[smalltalk.send(smalltalk.send(self["@full"],"_occurrencesOf_",[(5)]),"__eq",[(1)])]);
  72. return self}
  73. }),
  74. smalltalk.ExampleSetTest);
  75. smalltalk.addMethod(
  76. "_testRemove",
  77. smalltalk.method({
  78. selector: "testRemove",
  79. fn: function (){
  80. var self=this;
  81. smalltalk.send(self["@full"],"_remove_",[(5)]);
  82. smalltalk.send(self,"_assert_",[smalltalk.send(self["@full"],"_includes_",[smalltalk.symbolFor("abc")])]);
  83. smalltalk.send(self,"_deny_",[smalltalk.send(self["@full"],"_includes_",[(5)])]);
  84. return self}
  85. }),
  86. smalltalk.ExampleSetTest);
  87. smalltalk.addClass('SUnitAsyncTest', smalltalk.TestCase, ['flag'], 'SUnit-Tests');
  88. smalltalk.addMethod(
  89. "_fakeError",
  90. smalltalk.method({
  91. selector: "fakeError",
  92. fn: function (){
  93. var self=this;
  94. self["@flag"]="bad";
  95. smalltalk.send(self,"_timeout_",[(10)]);
  96. self["@flag"]=smalltalk.send(smalltalk.send(self,"_async_",[(function(){
  97. self["@flag"]="ok";
  98. self["@flag"];
  99. return smalltalk.send(self,"_error_",["Intentional"]);
  100. })]),"_valueWithTimeout_",[(5)]);
  101. return self}
  102. }),
  103. smalltalk.SUnitAsyncTest);
  104. smalltalk.addMethod(
  105. "_fakeErrorFailingInTearDown",
  106. smalltalk.method({
  107. selector: "fakeErrorFailingInTearDown",
  108. fn: function (){
  109. var self=this;
  110. self["@flag"]="bad";
  111. smalltalk.send(self,"_timeout_",[(10)]);
  112. self["@flag"]=smalltalk.send(smalltalk.send(self,"_async_",[(function(){
  113. return smalltalk.send(self,"_error_",["Intentional"]);
  114. })]),"_valueWithTimeout_",[(5)]);
  115. return self}
  116. }),
  117. smalltalk.SUnitAsyncTest);
  118. smalltalk.addMethod(
  119. "_fakeFailure",
  120. smalltalk.method({
  121. selector: "fakeFailure",
  122. fn: function (){
  123. var self=this;
  124. self["@flag"]="bad";
  125. smalltalk.send(self,"_timeout_",[(10)]);
  126. self["@flag"]=smalltalk.send(smalltalk.send(self,"_async_",[(function(){
  127. self["@flag"]="ok";
  128. self["@flag"];
  129. return smalltalk.send(self,"_assert_",[false]);
  130. })]),"_valueWithTimeout_",[(5)]);
  131. return self}
  132. }),
  133. smalltalk.SUnitAsyncTest);
  134. smalltalk.addMethod(
  135. "_fakeMultipleTimeoutFailing",
  136. smalltalk.method({
  137. selector: "fakeMultipleTimeoutFailing",
  138. fn: function (){
  139. var self=this;
  140. smalltalk.send(self,"_timeout_",[(100)]);
  141. smalltalk.send(smalltalk.send(self,"_async_",[(function(){
  142. smalltalk.send(self,"_timeout_",[(5)]);
  143. return smalltalk.send(smalltalk.send(self,"_async_",[(function(){
  144. return smalltalk.send(self,"_finished",[]);
  145. })]),"_valueWithTimeout_",[(10)]);
  146. })]),"_valueWithTimeout_",[(5)]);
  147. return self}
  148. }),
  149. smalltalk.SUnitAsyncTest);
  150. smalltalk.addMethod(
  151. "_fakeMultipleTimeoutPassing",
  152. smalltalk.method({
  153. selector: "fakeMultipleTimeoutPassing",
  154. fn: function (){
  155. var self=this;
  156. smalltalk.send(self,"_timeout_",[(10)]);
  157. smalltalk.send(smalltalk.send(self,"_async_",[(function(){
  158. smalltalk.send(self,"_timeout_",[(20)]);
  159. return smalltalk.send(smalltalk.send(self,"_async_",[(function(){
  160. return smalltalk.send(self,"_finished",[]);
  161. })]),"_valueWithTimeout_",[(10)]);
  162. })]),"_valueWithTimeout_",[(5)]);
  163. return self}
  164. }),
  165. smalltalk.SUnitAsyncTest);
  166. smalltalk.addMethod(
  167. "_fakeTimeout",
  168. smalltalk.method({
  169. selector: "fakeTimeout",
  170. fn: function (){
  171. var self=this;
  172. smalltalk.send(self,"_timeout_",[(4)]);
  173. smalltalk.send(smalltalk.send(self,"_async_",[(function(){
  174. return smalltalk.send(self,"_finished",[]);
  175. })]),"_valueWithTimeout_",[(5)]);
  176. return self}
  177. }),
  178. smalltalk.SUnitAsyncTest);
  179. smalltalk.addMethod(
  180. "_setUp",
  181. smalltalk.method({
  182. selector: "setUp",
  183. fn: function (){
  184. var self=this;
  185. self["@flag"]="ok";
  186. return self}
  187. }),
  188. smalltalk.SUnitAsyncTest);
  189. smalltalk.addMethod(
  190. "_sortedSelectors_",
  191. smalltalk.method({
  192. selector: "sortedSelectors:",
  193. fn: function (aCollection){
  194. var self=this;
  195. var $1;
  196. $1=smalltalk.send(smalltalk.send(aCollection,"_collect_",[(function(each){
  197. return smalltalk.send(each,"_selector",[]);
  198. })]),"_sorted",[]);
  199. return $1;
  200. }
  201. }),
  202. smalltalk.SUnitAsyncTest);
  203. smalltalk.addMethod(
  204. "_tearDown",
  205. smalltalk.method({
  206. selector: "tearDown",
  207. fn: function (){
  208. var self=this;
  209. smalltalk.send(self,"_assert_equals_",["ok",self["@flag"]]);
  210. return self}
  211. }),
  212. smalltalk.SUnitAsyncTest);
  213. smalltalk.addMethod(
  214. "_testAsyncErrorsAndFailures",
  215. smalltalk.method({
  216. selector: "testAsyncErrorsAndFailures",
  217. fn: function (){
  218. var self=this;
  219. var $1,$2,$4,$6,$5,$3;
  220. var suite;
  221. var runner;
  222. var result;
  223. var assertBlock;
  224. suite=smalltalk.send(["fakeError", "fakeErrorFailingInTearDown", "fakeFailure", "testPass"],"_collect_",[(function(each){
  225. return smalltalk.send(smalltalk.send(self,"_class",[]),"_selector_",[each]);
  226. })]);
  227. runner=smalltalk.send((smalltalk.TestSuiteRunner || TestSuiteRunner),"_on_",[suite]);
  228. smalltalk.send(self,"_timeout_",[(200)]);
  229. result=smalltalk.send(runner,"_result",[]);
  230. assertBlock=smalltalk.send(self,"_async_",[(function(){
  231. smalltalk.send(self,"_assert_equals_",[["fakeError"],smalltalk.send(self,"_sortedSelectors_",[smalltalk.send(result,"_errors",[])])]);
  232. smalltalk.send(self,"_assert_equals_",[["fakeErrorFailingInTearDown", "fakeFailure"],smalltalk.send(self,"_sortedSelectors_",[smalltalk.send(result,"_failures",[])])]);
  233. return smalltalk.send(self,"_finished",[]);
  234. })]);
  235. $1=smalltalk.send(runner,"_announcer",[]);
  236. $2=(smalltalk.ResultAnnouncement || ResultAnnouncement);
  237. $3=(function(ann){
  238. $4=smalltalk.send(smalltalk.send(ann,"_result",[]),"__eq_eq",[result]);
  239. $5=(function(){
  240. $6=smalltalk.send(smalltalk.send(result,"_runs",[]),"__eq",[smalltalk.send(result,"_total",[])]);
  241. return smalltalk.send($6,"_ifTrue_",[assertBlock]);
  242. });
  243. return smalltalk.send($4,"_ifTrue_",[$5]);
  244. });
  245. smalltalk.send($1,"_on_do_",[$2,$3]);
  246. smalltalk.send(runner,"_run",[]);
  247. return self}
  248. }),
  249. smalltalk.SUnitAsyncTest);
  250. smalltalk.addMethod(
  251. "_testAsyncNeedsTimeout",
  252. smalltalk.method({
  253. selector: "testAsyncNeedsTimeout",
  254. fn: function (){
  255. var self=this;
  256. smalltalk.send(self,"_should_raise_",[(function(){
  257. return smalltalk.send(self,"_async_",[(function(){
  258. })]);
  259. }),(smalltalk.Error || Error)]);
  260. smalltalk.send(self,"_timeout_",[(0)]);
  261. smalltalk.send(self,"_shouldnt_raise_",[(function(){
  262. return smalltalk.send(self,"_async_",[(function(){
  263. })]);
  264. }),(smalltalk.Error || Error)]);
  265. smalltalk.send(self,"_finished",[]);
  266. return self}
  267. }),
  268. smalltalk.SUnitAsyncTest);
  269. smalltalk.addMethod(
  270. "_testFinishedNeedsTimeout",
  271. smalltalk.method({
  272. selector: "testFinishedNeedsTimeout",
  273. fn: function (){
  274. var self=this;
  275. smalltalk.send(self,"_should_raise_",[(function(){
  276. return smalltalk.send(self,"_finished",[]);
  277. }),(smalltalk.Error || Error)]);
  278. smalltalk.send(self,"_timeout_",[(0)]);
  279. smalltalk.send(self,"_shouldnt_raise_",[(function(){
  280. return smalltalk.send(self,"_finished",[]);
  281. }),(smalltalk.Error || Error)]);
  282. return self}
  283. }),
  284. smalltalk.SUnitAsyncTest);
  285. smalltalk.addMethod(
  286. "_testIsAsyncReturnsCorrectValues",
  287. smalltalk.method({
  288. selector: "testIsAsyncReturnsCorrectValues",
  289. fn: function (){
  290. var self=this;
  291. smalltalk.send(self,"_deny_",[smalltalk.send(self,"_isAsync",[])]);
  292. smalltalk.send(self,"_timeout_",[(0)]);
  293. smalltalk.send(self,"_assert_",[smalltalk.send(self,"_isAsync",[])]);
  294. smalltalk.send(self,"_finished",[]);
  295. smalltalk.send(self,"_deny_",[smalltalk.send(self,"_isAsync",[])]);
  296. return self}
  297. }),
  298. smalltalk.SUnitAsyncTest);
  299. smalltalk.addMethod(
  300. "_testPass",
  301. smalltalk.method({
  302. selector: "testPass",
  303. fn: function (){
  304. var self=this;
  305. self["@flag"]="bad";
  306. smalltalk.send(self,"_timeout_",[(10)]);
  307. self["@flag"]=smalltalk.send(smalltalk.send(self,"_async_",[(function(){
  308. smalltalk.send(self,"_assert_",[true]);
  309. smalltalk.send(self,"_finished",[]);
  310. self["@flag"]="ok";
  311. return self["@flag"];
  312. })]),"_valueWithTimeout_",[(5)]);
  313. return self}
  314. }),
  315. smalltalk.SUnitAsyncTest);
  316. smalltalk.addMethod(
  317. "_testTimeouts",
  318. smalltalk.method({
  319. selector: "testTimeouts",
  320. fn: function (){
  321. var self=this;
  322. var $1,$2,$4,$6,$5,$3;
  323. var suite;
  324. var runner;
  325. var result;
  326. var assertBlock;
  327. suite=smalltalk.send(["fakeTimeout", "fakeMultipleTimeoutFailing", "fakeMultipleTimeoutPassing", "testPass"],"_collect_",[(function(each){
  328. return smalltalk.send(smalltalk.send(self,"_class",[]),"_selector_",[each]);
  329. })]);
  330. runner=smalltalk.send((smalltalk.TestSuiteRunner || TestSuiteRunner),"_on_",[suite]);
  331. smalltalk.send(self,"_timeout_",[(200)]);
  332. result=smalltalk.send(runner,"_result",[]);
  333. assertBlock=smalltalk.send(self,"_async_",[(function(){
  334. smalltalk.send(self,"_assert_",[smalltalk.send(smalltalk.send(result,"_errors",[]),"_isEmpty",[])]);
  335. smalltalk.send(self,"_assert_equals_",[["fakeMultipleTimeoutFailing", "fakeTimeout"],smalltalk.send(self,"_sortedSelectors_",[smalltalk.send(result,"_failures",[])])]);
  336. return smalltalk.send(self,"_finished",[]);
  337. })]);
  338. $1=smalltalk.send(runner,"_announcer",[]);
  339. $2=(smalltalk.ResultAnnouncement || ResultAnnouncement);
  340. $3=(function(ann){
  341. $4=smalltalk.send(smalltalk.send(ann,"_result",[]),"__eq_eq",[result]);
  342. $5=(function(){
  343. $6=smalltalk.send(smalltalk.send(result,"_runs",[]),"__eq",[smalltalk.send(result,"_total",[])]);
  344. return smalltalk.send($6,"_ifTrue_",[assertBlock]);
  345. });
  346. return smalltalk.send($4,"_ifTrue_",[$5]);
  347. });
  348. smalltalk.send($1,"_on_do_",[$2,$3]);
  349. smalltalk.send(runner,"_run",[]);
  350. return self}
  351. }),
  352. smalltalk.SUnitAsyncTest);
  353. smalltalk.addMethod(
  354. "_testTwoAsyncPassesWithFinishedOnlyOneIsRun",
  355. smalltalk.method({
  356. selector: "testTwoAsyncPassesWithFinishedOnlyOneIsRun",
  357. fn: function (){
  358. var self=this;
  359. var x;
  360. self["@flag"]="bad";
  361. smalltalk.send(self,"_timeout_",[(10)]);
  362. x=(0);
  363. self["@flag"]=smalltalk.send(smalltalk.send(self,"_async_",[(function(){
  364. smalltalk.send(self,"_finished",[]);
  365. self["@flag"]="ok";
  366. self["@flag"];
  367. x=smalltalk.send(x,"__plus",[(1)]);
  368. x;
  369. return smalltalk.send(self,"_assert_equals_",[(1),x]);
  370. })]),"_valueWithTimeout_",[(0)]);
  371. self["@flag"]=smalltalk.send(smalltalk.send(self,"_async_",[(function(){
  372. smalltalk.send(self,"_finished",[]);
  373. self["@flag"]="ok";
  374. self["@flag"];
  375. x=smalltalk.send(x,"__plus",[(1)]);
  376. x;
  377. return smalltalk.send(self,"_assert_equals_",[(1),x]);
  378. })]),"_valueWithTimeout_",[(0)]);
  379. return self}
  380. }),
  381. smalltalk.SUnitAsyncTest);