SUnit-Tests.js 24 KB

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