SUnit-Tests.js 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645
  1. define("amber_core/SUnit-Tests", ["amber/boot", "amber_core/SUnit"], function($boot){
  2. var smalltalk=$boot.vm,nil=$boot.nil,_st=$boot.asReceiver,globals=$boot.globals;
  3. smalltalk.addPackage('SUnit-Tests');
  4. smalltalk.packages["SUnit-Tests"].transport = {"type":"amd","amdNamespace":"amber_core"};
  5. smalltalk.addClass('ExampleSetTest', globals.TestCase, ['empty', 'full'], 'SUnit-Tests');
  6. globals.ExampleSetTest.comment="ExampleSetTest is taken from Pharo 1.4.\x0a\x0aTHe purpose of this class is to demonstrate a simple use case of the test framework.";
  7. smalltalk.addMethod(
  8. smalltalk.method({
  9. selector: "setUp",
  10. protocol: 'running',
  11. fn: function (){
  12. var self=this;
  13. function $Set(){return globals.Set||(typeof Set=="undefined"?nil:Set)}
  14. return smalltalk.withContext(function($ctx1) {
  15. self["@empty"]=_st($Set())._new();
  16. self["@full"]=_st($Set())._with_with_((5),"abc");
  17. return self}, function($ctx1) {$ctx1.fill(self,"setUp",{},globals.ExampleSetTest)});
  18. },
  19. args: [],
  20. source: "setUp\x0a\x09empty := Set new.\x0a\x09full := Set with: 5 with: #abc",
  21. messageSends: ["new", "with:with:"],
  22. referencedClasses: ["Set"]
  23. }),
  24. globals.ExampleSetTest);
  25. smalltalk.addMethod(
  26. smalltalk.method({
  27. selector: "testAdd",
  28. protocol: 'tests',
  29. fn: function (){
  30. var self=this;
  31. return smalltalk.withContext(function($ctx1) {
  32. _st(self["@empty"])._add_((5));
  33. self._assert_(_st(self["@empty"])._includes_((5)));
  34. return self}, function($ctx1) {$ctx1.fill(self,"testAdd",{},globals.ExampleSetTest)});
  35. },
  36. args: [],
  37. source: "testAdd\x0a\x09empty add: 5.\x0a\x09self assert: (empty includes: 5)",
  38. messageSends: ["add:", "assert:", "includes:"],
  39. referencedClasses: []
  40. }),
  41. globals.ExampleSetTest);
  42. smalltalk.addMethod(
  43. smalltalk.method({
  44. selector: "testGrow",
  45. protocol: 'tests',
  46. fn: function (){
  47. var self=this;
  48. return smalltalk.withContext(function($ctx1) {
  49. _st(self["@empty"])._addAll_((1)._to_((100)));
  50. self._assert_equals_(_st(self["@empty"])._size(),(100));
  51. return self}, function($ctx1) {$ctx1.fill(self,"testGrow",{},globals.ExampleSetTest)});
  52. },
  53. args: [],
  54. source: "testGrow\x0a\x09empty addAll: (1 to: 100).\x0a\x09self assert: empty size equals: 100",
  55. messageSends: ["addAll:", "to:", "assert:equals:", "size"],
  56. referencedClasses: []
  57. }),
  58. globals.ExampleSetTest);
  59. smalltalk.addMethod(
  60. smalltalk.method({
  61. selector: "testIllegal",
  62. protocol: 'tests',
  63. fn: function (){
  64. var self=this;
  65. function $Error(){return globals.Error||(typeof Error=="undefined"?nil:Error)}
  66. return smalltalk.withContext(function($ctx1) {
  67. self._should_raise_((function(){
  68. return smalltalk.withContext(function($ctx2) {
  69. return _st(self["@empty"])._at_((5));
  70. }, function($ctx2) {$ctx2.fillBlock({},$ctx1,1)});
  71. }),$Error());
  72. $ctx1.sendIdx["should:raise:"]=1;
  73. self._should_raise_((function(){
  74. return smalltalk.withContext(function($ctx2) {
  75. return _st(self["@empty"])._at_put_((5),"abc");
  76. }, function($ctx2) {$ctx2.fillBlock({},$ctx1,2)});
  77. }),$Error());
  78. return self}, function($ctx1) {$ctx1.fill(self,"testIllegal",{},globals.ExampleSetTest)});
  79. },
  80. args: [],
  81. source: "testIllegal\x0a\x09self\x0a\x09\x09should: [ empty at: 5 ]\x0a\x09\x09raise: Error.\x0a\x09self\x0a\x09\x09should: [ empty at: 5 put: #abc ]\x0a\x09\x09raise: Error",
  82. messageSends: ["should:raise:", "at:", "at:put:"],
  83. referencedClasses: ["Error"]
  84. }),
  85. globals.ExampleSetTest);
  86. smalltalk.addMethod(
  87. smalltalk.method({
  88. selector: "testIncludes",
  89. protocol: 'tests',
  90. fn: function (){
  91. var self=this;
  92. return smalltalk.withContext(function($ctx1) {
  93. var $1;
  94. $1=_st(self["@full"])._includes_((5));
  95. $ctx1.sendIdx["includes:"]=1;
  96. self._assert_($1);
  97. $ctx1.sendIdx["assert:"]=1;
  98. self._assert_(_st(self["@full"])._includes_("abc"));
  99. return self}, function($ctx1) {$ctx1.fill(self,"testIncludes",{},globals.ExampleSetTest)});
  100. },
  101. args: [],
  102. source: "testIncludes\x0a\x09self assert: (full includes: 5).\x0a\x09self assert: (full includes: #abc)",
  103. messageSends: ["assert:", "includes:"],
  104. referencedClasses: []
  105. }),
  106. globals.ExampleSetTest);
  107. smalltalk.addMethod(
  108. smalltalk.method({
  109. selector: "testOccurrences",
  110. protocol: 'tests',
  111. fn: function (){
  112. var self=this;
  113. return smalltalk.withContext(function($ctx1) {
  114. var $1,$2;
  115. $1=_st(self["@empty"])._occurrencesOf_((0));
  116. $ctx1.sendIdx["occurrencesOf:"]=1;
  117. self._assert_equals_($1,(0));
  118. $ctx1.sendIdx["assert:equals:"]=1;
  119. $2=_st(self["@full"])._occurrencesOf_((5));
  120. $ctx1.sendIdx["occurrencesOf:"]=2;
  121. self._assert_equals_($2,(1));
  122. $ctx1.sendIdx["assert:equals:"]=2;
  123. _st(self["@full"])._add_((5));
  124. self._assert_equals_(_st(self["@full"])._occurrencesOf_((5)),(1));
  125. return self}, function($ctx1) {$ctx1.fill(self,"testOccurrences",{},globals.ExampleSetTest)});
  126. },
  127. args: [],
  128. source: "testOccurrences\x0a\x09self assert: (empty occurrencesOf: 0) equals: 0.\x0a\x09self assert: (full occurrencesOf: 5) equals: 1.\x0a\x09full add: 5.\x0a\x09self assert: (full occurrencesOf: 5) equals: 1",
  129. messageSends: ["assert:equals:", "occurrencesOf:", "add:"],
  130. referencedClasses: []
  131. }),
  132. globals.ExampleSetTest);
  133. smalltalk.addMethod(
  134. smalltalk.method({
  135. selector: "testRemove",
  136. protocol: 'tests',
  137. fn: function (){
  138. var self=this;
  139. return smalltalk.withContext(function($ctx1) {
  140. var $1;
  141. _st(self["@full"])._remove_((5));
  142. $1=_st(self["@full"])._includes_("abc");
  143. $ctx1.sendIdx["includes:"]=1;
  144. self._assert_($1);
  145. self._deny_(_st(self["@full"])._includes_((5)));
  146. return self}, function($ctx1) {$ctx1.fill(self,"testRemove",{},globals.ExampleSetTest)});
  147. },
  148. args: [],
  149. source: "testRemove\x0a\x09full remove: 5.\x0a\x09self assert: (full includes: #abc).\x0a\x09self deny: (full includes: 5)",
  150. messageSends: ["remove:", "assert:", "includes:", "deny:"],
  151. referencedClasses: []
  152. }),
  153. globals.ExampleSetTest);
  154. smalltalk.addClass('SUnitAsyncTest', globals.TestCase, ['flag'], 'SUnit-Tests');
  155. smalltalk.addMethod(
  156. smalltalk.method({
  157. selector: "fakeError",
  158. protocol: 'helpers',
  159. fn: function (){
  160. var self=this;
  161. return smalltalk.withContext(function($ctx1) {
  162. self["@flag"]="bad";
  163. self._timeout_((30));
  164. self["@flag"]=_st(self._async_((function(){
  165. return smalltalk.withContext(function($ctx2) {
  166. self["@flag"]="ok";
  167. self["@flag"];
  168. return self._error_("Intentional");
  169. }, function($ctx2) {$ctx2.fillBlock({},$ctx1,1)});
  170. })))._valueWithTimeout_((20));
  171. return self}, function($ctx1) {$ctx1.fill(self,"fakeError",{},globals.SUnitAsyncTest)});
  172. },
  173. args: [],
  174. source: "fakeError\x0a\x09flag := 'bad'.\x0a\x09self timeout: 30.\x0a\x09flag := (self async: [ flag := 'ok'. self error: 'Intentional' ]) valueWithTimeout: 20",
  175. messageSends: ["timeout:", "valueWithTimeout:", "async:", "error:"],
  176. referencedClasses: []
  177. }),
  178. globals.SUnitAsyncTest);
  179. smalltalk.addMethod(
  180. smalltalk.method({
  181. selector: "fakeErrorFailingInTearDown",
  182. protocol: 'helpers',
  183. fn: function (){
  184. var self=this;
  185. return smalltalk.withContext(function($ctx1) {
  186. self["@flag"]="bad";
  187. self._timeout_((30));
  188. self["@flag"]=_st(self._async_((function(){
  189. return smalltalk.withContext(function($ctx2) {
  190. return self._error_("Intentional");
  191. }, function($ctx2) {$ctx2.fillBlock({},$ctx1,1)});
  192. })))._valueWithTimeout_((20));
  193. return self}, function($ctx1) {$ctx1.fill(self,"fakeErrorFailingInTearDown",{},globals.SUnitAsyncTest)});
  194. },
  195. args: [],
  196. source: "fakeErrorFailingInTearDown\x0a\x09flag := 'bad'.\x0a\x09self timeout: 30.\x0a\x09flag := (self async: [ self error: 'Intentional' ]) valueWithTimeout: 20",
  197. messageSends: ["timeout:", "valueWithTimeout:", "async:", "error:"],
  198. referencedClasses: []
  199. }),
  200. globals.SUnitAsyncTest);
  201. smalltalk.addMethod(
  202. smalltalk.method({
  203. selector: "fakeFailure",
  204. protocol: 'helpers',
  205. fn: function (){
  206. var self=this;
  207. return smalltalk.withContext(function($ctx1) {
  208. self["@flag"]="bad";
  209. self._timeout_((30));
  210. self["@flag"]=_st(self._async_((function(){
  211. return smalltalk.withContext(function($ctx2) {
  212. self["@flag"]="ok";
  213. self["@flag"];
  214. return self._assert_(false);
  215. }, function($ctx2) {$ctx2.fillBlock({},$ctx1,1)});
  216. })))._valueWithTimeout_((20));
  217. return self}, function($ctx1) {$ctx1.fill(self,"fakeFailure",{},globals.SUnitAsyncTest)});
  218. },
  219. args: [],
  220. source: "fakeFailure\x0a\x09flag := 'bad'.\x0a\x09self timeout: 30.\x0a\x09flag := (self async: [ flag := 'ok'. self assert: false ]) valueWithTimeout: 20",
  221. messageSends: ["timeout:", "valueWithTimeout:", "async:", "assert:"],
  222. referencedClasses: []
  223. }),
  224. globals.SUnitAsyncTest);
  225. smalltalk.addMethod(
  226. smalltalk.method({
  227. selector: "fakeMultipleTimeoutFailing",
  228. protocol: 'helpers',
  229. fn: function (){
  230. var self=this;
  231. return smalltalk.withContext(function($ctx1) {
  232. var $1;
  233. self._timeout_((100));
  234. $ctx1.sendIdx["timeout:"]=1;
  235. $1=self._async_((function(){
  236. return smalltalk.withContext(function($ctx2) {
  237. self._timeout_((20));
  238. return _st(self._async_((function(){
  239. return smalltalk.withContext(function($ctx3) {
  240. return self._finished();
  241. }, function($ctx3) {$ctx3.fillBlock({},$ctx2,2)});
  242. })))._valueWithTimeout_((30));
  243. }, function($ctx2) {$ctx2.fillBlock({},$ctx1,1)});
  244. }));
  245. $ctx1.sendIdx["async:"]=1;
  246. _st($1)._valueWithTimeout_((20));
  247. $ctx1.sendIdx["valueWithTimeout:"]=1;
  248. return self}, function($ctx1) {$ctx1.fill(self,"fakeMultipleTimeoutFailing",{},globals.SUnitAsyncTest)});
  249. },
  250. args: [],
  251. source: "fakeMultipleTimeoutFailing\x0a\x09self timeout: 100.\x0a\x09(self async: [ \x0a\x09\x09self timeout: 20.\x0a\x09\x09(self async: [ self finished ]) valueWithTimeout: 30\x0a\x09]) valueWithTimeout: 20",
  252. messageSends: ["timeout:", "valueWithTimeout:", "async:", "finished"],
  253. referencedClasses: []
  254. }),
  255. globals.SUnitAsyncTest);
  256. smalltalk.addMethod(
  257. smalltalk.method({
  258. selector: "fakeMultipleTimeoutPassing",
  259. protocol: 'helpers',
  260. fn: function (){
  261. var self=this;
  262. return smalltalk.withContext(function($ctx1) {
  263. var $1;
  264. self._timeout_((20));
  265. $ctx1.sendIdx["timeout:"]=1;
  266. $1=self._async_((function(){
  267. return smalltalk.withContext(function($ctx2) {
  268. self._timeout_((40));
  269. return _st(self._async_((function(){
  270. return smalltalk.withContext(function($ctx3) {
  271. return self._finished();
  272. }, function($ctx3) {$ctx3.fillBlock({},$ctx2,2)});
  273. })))._valueWithTimeout_((20));
  274. }, function($ctx2) {$ctx2.fillBlock({},$ctx1,1)});
  275. }));
  276. $ctx1.sendIdx["async:"]=1;
  277. _st($1)._valueWithTimeout_((10));
  278. $ctx1.sendIdx["valueWithTimeout:"]=1;
  279. return self}, function($ctx1) {$ctx1.fill(self,"fakeMultipleTimeoutPassing",{},globals.SUnitAsyncTest)});
  280. },
  281. args: [],
  282. source: "fakeMultipleTimeoutPassing\x0a\x09self timeout: 20.\x0a\x09(self async: [\x0a\x09\x09self timeout: 40.\x0a\x09\x09(self async: [ self finished ]) valueWithTimeout: 20\x0a\x09]) valueWithTimeout: 10",
  283. messageSends: ["timeout:", "valueWithTimeout:", "async:", "finished"],
  284. referencedClasses: []
  285. }),
  286. globals.SUnitAsyncTest);
  287. smalltalk.addMethod(
  288. smalltalk.method({
  289. selector: "fakeTimeout",
  290. protocol: 'helpers',
  291. fn: function (){
  292. var self=this;
  293. return smalltalk.withContext(function($ctx1) {
  294. self._timeout_((10));
  295. _st(self._async_((function(){
  296. return smalltalk.withContext(function($ctx2) {
  297. return self._finished();
  298. }, function($ctx2) {$ctx2.fillBlock({},$ctx1,1)});
  299. })))._valueWithTimeout_((20));
  300. return self}, function($ctx1) {$ctx1.fill(self,"fakeTimeout",{},globals.SUnitAsyncTest)});
  301. },
  302. args: [],
  303. source: "fakeTimeout\x0a\x09self timeout: 10.\x0a\x09(self async: [ self finished ]) valueWithTimeout: 20",
  304. messageSends: ["timeout:", "valueWithTimeout:", "async:", "finished"],
  305. referencedClasses: []
  306. }),
  307. globals.SUnitAsyncTest);
  308. smalltalk.addMethod(
  309. smalltalk.method({
  310. selector: "selectorSetOf:",
  311. protocol: 'private',
  312. fn: function (aCollection){
  313. var self=this;
  314. return smalltalk.withContext(function($ctx1) {
  315. var $1;
  316. $1=_st(_st(aCollection)._collect_((function(each){
  317. return smalltalk.withContext(function($ctx2) {
  318. return _st(each)._selector();
  319. }, function($ctx2) {$ctx2.fillBlock({each:each},$ctx1,1)});
  320. })))._asSet();
  321. return $1;
  322. }, function($ctx1) {$ctx1.fill(self,"selectorSetOf:",{aCollection:aCollection},globals.SUnitAsyncTest)});
  323. },
  324. args: ["aCollection"],
  325. source: "selectorSetOf: aCollection\x0a\x09^ (aCollection collect: [ :each | each selector ]) asSet",
  326. messageSends: ["asSet", "collect:", "selector"],
  327. referencedClasses: []
  328. }),
  329. globals.SUnitAsyncTest);
  330. smalltalk.addMethod(
  331. smalltalk.method({
  332. selector: "setUp",
  333. protocol: 'running',
  334. fn: function (){
  335. var self=this;
  336. self["@flag"]="ok";
  337. return self
  338. },
  339. args: [],
  340. source: "setUp\x0a\x09flag := 'ok'",
  341. messageSends: [],
  342. referencedClasses: []
  343. }),
  344. globals.SUnitAsyncTest);
  345. smalltalk.addMethod(
  346. smalltalk.method({
  347. selector: "tearDown",
  348. protocol: 'running',
  349. fn: function (){
  350. var self=this;
  351. return smalltalk.withContext(function($ctx1) {
  352. self._assert_equals_("ok",self["@flag"]);
  353. return self}, function($ctx1) {$ctx1.fill(self,"tearDown",{},globals.SUnitAsyncTest)});
  354. },
  355. args: [],
  356. source: "tearDown\x0a\x09self assert: 'ok' equals: flag",
  357. messageSends: ["assert:equals:"],
  358. referencedClasses: []
  359. }),
  360. globals.SUnitAsyncTest);
  361. smalltalk.addMethod(
  362. smalltalk.method({
  363. selector: "testAsyncErrorsAndFailures",
  364. protocol: 'tests',
  365. fn: function (){
  366. var self=this;
  367. var suite,runner,result,assertBlock;
  368. function $TestSuiteRunner(){return globals.TestSuiteRunner||(typeof TestSuiteRunner=="undefined"?nil:TestSuiteRunner)}
  369. function $ResultAnnouncement(){return globals.ResultAnnouncement||(typeof ResultAnnouncement=="undefined"?nil:ResultAnnouncement)}
  370. return smalltalk.withContext(function($ctx1) {
  371. var $1,$2,$3,$4;
  372. suite=["fakeError", "fakeErrorFailingInTearDown", "fakeFailure", "testPass"]._collect_((function(each){
  373. return smalltalk.withContext(function($ctx2) {
  374. return _st(self._class())._selector_(each);
  375. }, function($ctx2) {$ctx2.fillBlock({each:each},$ctx1,1)});
  376. }));
  377. runner=_st($TestSuiteRunner())._on_(suite);
  378. self._timeout_((200));
  379. result=_st(runner)._result();
  380. $ctx1.sendIdx["result"]=1;
  381. assertBlock=self._async_((function(){
  382. return smalltalk.withContext(function($ctx2) {
  383. $1=self._selectorSetOf_(_st(result)._errors());
  384. $ctx2.sendIdx["selectorSetOf:"]=1;
  385. $2=["fakeError"]._asSet();
  386. $ctx2.sendIdx["asSet"]=1;
  387. self._assert_equals_($1,$2);
  388. $ctx2.sendIdx["assert:equals:"]=1;
  389. self._assert_equals_(self._selectorSetOf_(_st(result)._failures()),["fakeErrorFailingInTearDown", "fakeFailure"]._asSet());
  390. return self._finished();
  391. }, function($ctx2) {$ctx2.fillBlock({},$ctx1,2)});
  392. }));
  393. _st(_st(runner)._announcer())._on_do_($ResultAnnouncement(),(function(ann){
  394. return smalltalk.withContext(function($ctx2) {
  395. $3=_st(_st(ann)._result()).__eq_eq(result);
  396. if(smalltalk.assert($3)){
  397. $4=_st(_st(result)._runs()).__eq(_st(result)._total());
  398. return _st($4)._ifTrue_(assertBlock);
  399. };
  400. }, function($ctx2) {$ctx2.fillBlock({ann:ann},$ctx1,3)});
  401. }));
  402. _st(runner)._run();
  403. return self}, function($ctx1) {$ctx1.fill(self,"testAsyncErrorsAndFailures",{suite:suite,runner:runner,result:result,assertBlock:assertBlock},globals.SUnitAsyncTest)});
  404. },
  405. args: [],
  406. source: "testAsyncErrorsAndFailures\x0a\x09| suite runner result assertBlock |\x0a\x09suite := #('fakeError' 'fakeErrorFailingInTearDown' 'fakeFailure' 'testPass') collect: [ :each | self class selector: each ].\x0a\x09runner := TestSuiteRunner on: suite.\x0a\x09self timeout: 200.\x0a\x09result := runner result.\x0a\x09assertBlock := self async: [\x0a\x09\x09self assert: (self selectorSetOf: result errors) equals: #('fakeError') asSet.\x0a\x09\x09self assert: (self selectorSetOf: result failures) equals: #('fakeErrorFailingInTearDown' 'fakeFailure') asSet.\x0a\x09\x09self finished\x0a\x09].\x0a\x09runner announcer on: ResultAnnouncement do: [ :ann |\x0a\x09\x09ann result == result ifTrue: [ result runs = result total ifTrue: assertBlock ] ].\x0a\x09runner run",
  407. messageSends: ["collect:", "selector:", "class", "on:", "timeout:", "result", "async:", "assert:equals:", "selectorSetOf:", "errors", "asSet", "failures", "finished", "on:do:", "announcer", "ifTrue:", "==", "=", "runs", "total", "run"],
  408. referencedClasses: ["TestSuiteRunner", "ResultAnnouncement"]
  409. }),
  410. globals.SUnitAsyncTest);
  411. smalltalk.addMethod(
  412. smalltalk.method({
  413. selector: "testAsyncNeedsTimeout",
  414. protocol: 'tests',
  415. fn: function (){
  416. var self=this;
  417. function $Error(){return globals.Error||(typeof Error=="undefined"?nil:Error)}
  418. return smalltalk.withContext(function($ctx1) {
  419. self._should_raise_((function(){
  420. return smalltalk.withContext(function($ctx2) {
  421. return self._async_((function(){
  422. }));
  423. $ctx2.sendIdx["async:"]=1;
  424. }, function($ctx2) {$ctx2.fillBlock({},$ctx1,1)});
  425. }),$Error());
  426. self._timeout_((0));
  427. self._shouldnt_raise_((function(){
  428. return smalltalk.withContext(function($ctx2) {
  429. return self._async_((function(){
  430. }));
  431. }, function($ctx2) {$ctx2.fillBlock({},$ctx1,3)});
  432. }),$Error());
  433. self._finished();
  434. return self}, function($ctx1) {$ctx1.fill(self,"testAsyncNeedsTimeout",{},globals.SUnitAsyncTest)});
  435. },
  436. args: [],
  437. source: "testAsyncNeedsTimeout\x0a\x09self should: [ self async: [ ] ] raise: Error.\x0a\x09self timeout: 0.\x0a\x09self shouldnt: [ self async: [ ] ] raise: Error.\x0a\x09self finished",
  438. messageSends: ["should:raise:", "async:", "timeout:", "shouldnt:raise:", "finished"],
  439. referencedClasses: ["Error"]
  440. }),
  441. globals.SUnitAsyncTest);
  442. smalltalk.addMethod(
  443. smalltalk.method({
  444. selector: "testFinishedNeedsTimeout",
  445. protocol: 'tests',
  446. fn: function (){
  447. var self=this;
  448. function $Error(){return globals.Error||(typeof Error=="undefined"?nil:Error)}
  449. return smalltalk.withContext(function($ctx1) {
  450. self._should_raise_((function(){
  451. return smalltalk.withContext(function($ctx2) {
  452. return self._finished();
  453. $ctx2.sendIdx["finished"]=1;
  454. }, function($ctx2) {$ctx2.fillBlock({},$ctx1,1)});
  455. }),$Error());
  456. self._timeout_((0));
  457. self._shouldnt_raise_((function(){
  458. return smalltalk.withContext(function($ctx2) {
  459. return self._finished();
  460. }, function($ctx2) {$ctx2.fillBlock({},$ctx1,2)});
  461. }),$Error());
  462. return self}, function($ctx1) {$ctx1.fill(self,"testFinishedNeedsTimeout",{},globals.SUnitAsyncTest)});
  463. },
  464. args: [],
  465. source: "testFinishedNeedsTimeout\x0a\x09self should: [ self finished ] raise: Error.\x0a\x09self timeout: 0.\x0a\x09self shouldnt: [ self finished ] raise: Error.",
  466. messageSends: ["should:raise:", "finished", "timeout:", "shouldnt:raise:"],
  467. referencedClasses: ["Error"]
  468. }),
  469. globals.SUnitAsyncTest);
  470. smalltalk.addMethod(
  471. smalltalk.method({
  472. selector: "testIsAsyncReturnsCorrectValues",
  473. protocol: 'tests',
  474. fn: function (){
  475. var self=this;
  476. return smalltalk.withContext(function($ctx1) {
  477. var $1,$2;
  478. $1=self._isAsync();
  479. $ctx1.sendIdx["isAsync"]=1;
  480. self._deny_($1);
  481. $ctx1.sendIdx["deny:"]=1;
  482. self._timeout_((0));
  483. $2=self._isAsync();
  484. $ctx1.sendIdx["isAsync"]=2;
  485. self._assert_($2);
  486. self._finished();
  487. self._deny_(self._isAsync());
  488. return self}, function($ctx1) {$ctx1.fill(self,"testIsAsyncReturnsCorrectValues",{},globals.SUnitAsyncTest)});
  489. },
  490. args: [],
  491. source: "testIsAsyncReturnsCorrectValues\x0a\x09self deny: self isAsync.\x0a\x09self timeout: 0.\x0a\x09self assert: self isAsync.\x0a\x09self finished.\x0a\x09self deny: self isAsync",
  492. messageSends: ["deny:", "isAsync", "timeout:", "assert:", "finished"],
  493. referencedClasses: []
  494. }),
  495. globals.SUnitAsyncTest);
  496. smalltalk.addMethod(
  497. smalltalk.method({
  498. selector: "testPass",
  499. protocol: 'tests',
  500. fn: function (){
  501. var self=this;
  502. return smalltalk.withContext(function($ctx1) {
  503. self["@flag"]="bad";
  504. self._timeout_((10));
  505. self["@flag"]=_st(self._async_((function(){
  506. return smalltalk.withContext(function($ctx2) {
  507. self._assert_(true);
  508. self._finished();
  509. self["@flag"]="ok";
  510. return self["@flag"];
  511. }, function($ctx2) {$ctx2.fillBlock({},$ctx1,1)});
  512. })))._valueWithTimeout_((5));
  513. return self}, function($ctx1) {$ctx1.fill(self,"testPass",{},globals.SUnitAsyncTest)});
  514. },
  515. args: [],
  516. source: "testPass\x0a\x09flag := 'bad'.\x0a\x09self timeout: 10.\x0a\x09flag := (self async: [ self assert: true. self finished. flag := 'ok' ]) valueWithTimeout: 5",
  517. messageSends: ["timeout:", "valueWithTimeout:", "async:", "assert:", "finished"],
  518. referencedClasses: []
  519. }),
  520. globals.SUnitAsyncTest);
  521. smalltalk.addMethod(
  522. smalltalk.method({
  523. selector: "testTimeouts",
  524. protocol: 'tests',
  525. fn: function (){
  526. var self=this;
  527. var suite,runner,result,assertBlock;
  528. function $TestSuiteRunner(){return globals.TestSuiteRunner||(typeof TestSuiteRunner=="undefined"?nil:TestSuiteRunner)}
  529. function $Set(){return globals.Set||(typeof Set=="undefined"?nil:Set)}
  530. function $ResultAnnouncement(){return globals.ResultAnnouncement||(typeof ResultAnnouncement=="undefined"?nil:ResultAnnouncement)}
  531. return smalltalk.withContext(function($ctx1) {
  532. var $1,$2,$3;
  533. suite=["fakeTimeout", "fakeMultipleTimeoutFailing", "fakeMultipleTimeoutPassing", "testPass"]._collect_((function(each){
  534. return smalltalk.withContext(function($ctx2) {
  535. return _st(self._class())._selector_(each);
  536. }, function($ctx2) {$ctx2.fillBlock({each:each},$ctx1,1)});
  537. }));
  538. runner=_st($TestSuiteRunner())._on_(suite);
  539. self._timeout_((200));
  540. result=_st(runner)._result();
  541. $ctx1.sendIdx["result"]=1;
  542. assertBlock=self._async_((function(){
  543. return smalltalk.withContext(function($ctx2) {
  544. $1=self._selectorSetOf_(_st(result)._errors());
  545. $ctx2.sendIdx["selectorSetOf:"]=1;
  546. self._assert_equals_($1,_st($Set())._new());
  547. $ctx2.sendIdx["assert:equals:"]=1;
  548. self._assert_equals_(self._selectorSetOf_(_st(result)._failures()),["fakeMultipleTimeoutFailing", "fakeTimeout"]._asSet());
  549. return self._finished();
  550. }, function($ctx2) {$ctx2.fillBlock({},$ctx1,2)});
  551. }));
  552. _st(_st(runner)._announcer())._on_do_($ResultAnnouncement(),(function(ann){
  553. return smalltalk.withContext(function($ctx2) {
  554. $2=_st(_st(ann)._result()).__eq_eq(result);
  555. if(smalltalk.assert($2)){
  556. $3=_st(_st(result)._runs()).__eq(_st(result)._total());
  557. return _st($3)._ifTrue_(assertBlock);
  558. };
  559. }, function($ctx2) {$ctx2.fillBlock({ann:ann},$ctx1,3)});
  560. }));
  561. _st(runner)._run();
  562. return self}, function($ctx1) {$ctx1.fill(self,"testTimeouts",{suite:suite,runner:runner,result:result,assertBlock:assertBlock},globals.SUnitAsyncTest)});
  563. },
  564. args: [],
  565. source: "testTimeouts\x0a\x09| suite runner result assertBlock |\x0a\x09suite := #('fakeTimeout' 'fakeMultipleTimeoutFailing' 'fakeMultipleTimeoutPassing' 'testPass') collect: [ :each | self class selector: each ].\x0a\x09runner := TestSuiteRunner on: suite.\x0a\x09self timeout: 200.\x0a\x09result := runner result.\x0a\x09assertBlock := self async: [\x0a\x09\x09self assert: (self selectorSetOf: result errors) equals: Set new.\x0a\x09\x09self assert: (self selectorSetOf: result failures) equals: #('fakeMultipleTimeoutFailing' 'fakeTimeout') asSet.\x0a\x09\x09self finished\x0a\x09].\x0a\x09runner announcer on: ResultAnnouncement do: [ :ann |\x0a\x09\x09ann result == result ifTrue: [ result runs = result total ifTrue: assertBlock ] ].\x0a\x09runner run",
  566. messageSends: ["collect:", "selector:", "class", "on:", "timeout:", "result", "async:", "assert:equals:", "selectorSetOf:", "errors", "new", "failures", "asSet", "finished", "on:do:", "announcer", "ifTrue:", "==", "=", "runs", "total", "run"],
  567. referencedClasses: ["TestSuiteRunner", "Set", "ResultAnnouncement"]
  568. }),
  569. globals.SUnitAsyncTest);
  570. smalltalk.addMethod(
  571. smalltalk.method({
  572. selector: "testTwoAsyncPassesWithFinishedOnlyOneIsRun",
  573. protocol: 'tests',
  574. fn: function (){
  575. var self=this;
  576. var x;
  577. return smalltalk.withContext(function($ctx1) {
  578. var $1;
  579. self["@flag"]="bad";
  580. self._timeout_((10));
  581. x=(0);
  582. $1=self._async_((function(){
  583. return smalltalk.withContext(function($ctx2) {
  584. self._finished();
  585. $ctx2.sendIdx["finished"]=1;
  586. self["@flag"]="ok";
  587. self["@flag"];
  588. x=_st(x).__plus((1));
  589. $ctx2.sendIdx["+"]=1;
  590. x;
  591. return self._assert_equals_(x,(1));
  592. $ctx2.sendIdx["assert:equals:"]=1;
  593. }, function($ctx2) {$ctx2.fillBlock({},$ctx1,1)});
  594. }));
  595. $ctx1.sendIdx["async:"]=1;
  596. self["@flag"]=_st($1)._valueWithTimeout_((0));
  597. $ctx1.sendIdx["valueWithTimeout:"]=1;
  598. self["@flag"]=_st(self._async_((function(){
  599. return smalltalk.withContext(function($ctx2) {
  600. self._finished();
  601. self["@flag"]="ok";
  602. self["@flag"];
  603. x=_st(x).__plus((1));
  604. x;
  605. return self._assert_equals_(x,(1));
  606. }, function($ctx2) {$ctx2.fillBlock({},$ctx1,2)});
  607. })))._valueWithTimeout_((0));
  608. return self}, function($ctx1) {$ctx1.fill(self,"testTwoAsyncPassesWithFinishedOnlyOneIsRun",{x:x},globals.SUnitAsyncTest)});
  609. },
  610. args: [],
  611. source: "testTwoAsyncPassesWithFinishedOnlyOneIsRun\x0a\x09| x |\x0a\x09flag := 'bad'.\x0a\x09self timeout: 10.\x0a\x09x := 0.\x0a\x09flag := (self async: [ self finished. flag := 'ok'. x := x+1. self assert: x equals: 1 ]) valueWithTimeout: 0.\x0a\x09flag := (self async: [ self finished. flag := 'ok'. x := x+1. self assert: x equals: 1 ]) valueWithTimeout: 0.",
  612. messageSends: ["timeout:", "valueWithTimeout:", "async:", "finished", "+", "assert:equals:"],
  613. referencedClasses: []
  614. }),
  615. globals.SUnitAsyncTest);
  616. });