2
0

SUnit-Tests.deploy.js 17 KB

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