1
0

SUnit-Tests.js 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608
  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;
  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. return _st(_st(_st(result)._runs()).__eq(_st(result)._total()))._ifTrue_(assertBlock);
  377. };
  378. }, function($ctx2) {$ctx2.fillBlock({ann:ann},$ctx1,3)})}));
  379. _st(runner)._run();
  380. return self}, function($ctx1) {$ctx1.fill(self,"testAsyncErrorsAndFailures",{suite:suite,runner:runner,result:result,assertBlock:assertBlock},smalltalk.SUnitAsyncTest)})},
  381. args: [],
  382. 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",
  383. messageSends: ["collect:", "selector:", "class", "on:", "timeout:", "result", "async:", "assert:equals:", "selectorSetOf:", "errors", "asSet", "failures", "finished", "on:do:", "announcer", "ifTrue:", "==", "=", "runs", "total", "run"],
  384. referencedClasses: ["TestSuiteRunner", "ResultAnnouncement"]
  385. }),
  386. smalltalk.SUnitAsyncTest);
  387. smalltalk.addMethod(
  388. smalltalk.method({
  389. selector: "testAsyncNeedsTimeout",
  390. category: 'tests',
  391. fn: function (){
  392. var self=this;
  393. function $Error(){return smalltalk.Error||(typeof Error=="undefined"?nil:Error)}
  394. return smalltalk.withContext(function($ctx1) {
  395. self._should_raise_((function(){
  396. return smalltalk.withContext(function($ctx2) {
  397. return self._async_((function(){
  398. return smalltalk.withContext(function($ctx3) {
  399. }, function($ctx3) {$ctx3.fillBlock({},$ctx2,2)})}));
  400. $ctx2.sendIdx["async:"]=1;
  401. }, function($ctx2) {$ctx2.fillBlock({},$ctx1,1)})}),$Error());
  402. self._timeout_((0));
  403. self._shouldnt_raise_((function(){
  404. return smalltalk.withContext(function($ctx2) {
  405. return self._async_((function(){
  406. return smalltalk.withContext(function($ctx3) {
  407. }, function($ctx3) {$ctx3.fillBlock({},$ctx2,4)})}));
  408. }, function($ctx2) {$ctx2.fillBlock({},$ctx1,3)})}),$Error());
  409. self._finished();
  410. return self}, function($ctx1) {$ctx1.fill(self,"testAsyncNeedsTimeout",{},smalltalk.SUnitAsyncTest)})},
  411. args: [],
  412. source: "testAsyncNeedsTimeout\x0a\x09self should: [ self async: [ ] ] raise: Error.\x0a\x09self timeout: 0.\x0a\x09self shouldnt: [ self async: [ ] ] raise: Error.\x0a\x09self finished",
  413. messageSends: ["should:raise:", "async:", "timeout:", "shouldnt:raise:", "finished"],
  414. referencedClasses: ["Error"]
  415. }),
  416. smalltalk.SUnitAsyncTest);
  417. smalltalk.addMethod(
  418. smalltalk.method({
  419. selector: "testFinishedNeedsTimeout",
  420. category: 'tests',
  421. fn: function (){
  422. var self=this;
  423. function $Error(){return smalltalk.Error||(typeof Error=="undefined"?nil:Error)}
  424. return smalltalk.withContext(function($ctx1) {
  425. self._should_raise_((function(){
  426. return smalltalk.withContext(function($ctx2) {
  427. return self._finished();
  428. $ctx2.sendIdx["finished"]=1;
  429. }, function($ctx2) {$ctx2.fillBlock({},$ctx1,1)})}),$Error());
  430. self._timeout_((0));
  431. self._shouldnt_raise_((function(){
  432. return smalltalk.withContext(function($ctx2) {
  433. return self._finished();
  434. }, function($ctx2) {$ctx2.fillBlock({},$ctx1,2)})}),$Error());
  435. return self}, function($ctx1) {$ctx1.fill(self,"testFinishedNeedsTimeout",{},smalltalk.SUnitAsyncTest)})},
  436. args: [],
  437. source: "testFinishedNeedsTimeout\x0a\x09self should: [ self finished ] raise: Error.\x0a\x09self timeout: 0.\x0a\x09self shouldnt: [ self finished ] raise: Error.",
  438. messageSends: ["should:raise:", "finished", "timeout:", "shouldnt:raise:"],
  439. referencedClasses: ["Error"]
  440. }),
  441. smalltalk.SUnitAsyncTest);
  442. smalltalk.addMethod(
  443. smalltalk.method({
  444. selector: "testIsAsyncReturnsCorrectValues",
  445. category: 'tests',
  446. fn: function (){
  447. var self=this;
  448. return smalltalk.withContext(function($ctx1) {
  449. var $1,$2,$3;
  450. $1=self._isAsync();
  451. $ctx1.sendIdx["isAsync"]=1;
  452. self._deny_($1);
  453. $ctx1.sendIdx["deny:"]=1;
  454. self._timeout_((0));
  455. $2=self._isAsync();
  456. $ctx1.sendIdx["isAsync"]=2;
  457. self._assert_($2);
  458. self._finished();
  459. $3=self._isAsync();
  460. self._deny_($3);
  461. return self}, function($ctx1) {$ctx1.fill(self,"testIsAsyncReturnsCorrectValues",{},smalltalk.SUnitAsyncTest)})},
  462. args: [],
  463. source: "testIsAsyncReturnsCorrectValues\x0a\x09self deny: self isAsync.\x0a\x09self timeout: 0.\x0a\x09self assert: self isAsync.\x0a\x09self finished.\x0a\x09self deny: self isAsync",
  464. messageSends: ["deny:", "isAsync", "timeout:", "assert:", "finished"],
  465. referencedClasses: []
  466. }),
  467. smalltalk.SUnitAsyncTest);
  468. smalltalk.addMethod(
  469. smalltalk.method({
  470. selector: "testPass",
  471. category: 'tests',
  472. fn: function (){
  473. var self=this;
  474. return smalltalk.withContext(function($ctx1) {
  475. self["@flag"]="bad";
  476. self._timeout_((10));
  477. self["@flag"]=_st(self._async_((function(){
  478. return smalltalk.withContext(function($ctx2) {
  479. self._assert_(true);
  480. self._finished();
  481. self["@flag"]="ok";
  482. return self["@flag"];
  483. }, function($ctx2) {$ctx2.fillBlock({},$ctx1,1)})})))._valueWithTimeout_((5));
  484. return self}, function($ctx1) {$ctx1.fill(self,"testPass",{},smalltalk.SUnitAsyncTest)})},
  485. args: [],
  486. source: "testPass\x0a\x09flag := 'bad'.\x0a\x09self timeout: 10.\x0a\x09flag := (self async: [ self assert: true. self finished. flag := 'ok' ]) valueWithTimeout: 5",
  487. messageSends: ["timeout:", "valueWithTimeout:", "async:", "assert:", "finished"],
  488. referencedClasses: []
  489. }),
  490. smalltalk.SUnitAsyncTest);
  491. smalltalk.addMethod(
  492. smalltalk.method({
  493. selector: "testTimeouts",
  494. category: 'tests',
  495. fn: function (){
  496. var self=this;
  497. var suite,runner,result,assertBlock;
  498. function $TestSuiteRunner(){return smalltalk.TestSuiteRunner||(typeof TestSuiteRunner=="undefined"?nil:TestSuiteRunner)}
  499. function $Set(){return smalltalk.Set||(typeof Set=="undefined"?nil:Set)}
  500. function $ResultAnnouncement(){return smalltalk.ResultAnnouncement||(typeof ResultAnnouncement=="undefined"?nil:ResultAnnouncement)}
  501. return smalltalk.withContext(function($ctx1) {
  502. var $1,$2,$4,$3;
  503. suite=["fakeTimeout", "fakeMultipleTimeoutFailing", "fakeMultipleTimeoutPassing", "testPass"]._collect_((function(each){
  504. return smalltalk.withContext(function($ctx2) {
  505. return _st(self._class())._selector_(each);
  506. }, function($ctx2) {$ctx2.fillBlock({each:each},$ctx1,1)})}));
  507. runner=_st($TestSuiteRunner())._on_(suite);
  508. self._timeout_((200));
  509. result=_st(runner)._result();
  510. $ctx1.sendIdx["result"]=1;
  511. assertBlock=self._async_((function(){
  512. return smalltalk.withContext(function($ctx2) {
  513. $1=self._selectorSetOf_(_st(result)._errors());
  514. $ctx2.sendIdx["selectorSetOf:"]=1;
  515. self._assert_equals_($1,_st($Set())._new());
  516. $ctx2.sendIdx["assert:equals:"]=1;
  517. $2=self._selectorSetOf_(_st(result)._failures());
  518. self._assert_equals_($2,["fakeMultipleTimeoutFailing", "fakeTimeout"]._asSet());
  519. return self._finished();
  520. }, function($ctx2) {$ctx2.fillBlock({},$ctx1,2)})}));
  521. _st(_st(runner)._announcer())._on_do_($ResultAnnouncement(),(function(ann){
  522. return smalltalk.withContext(function($ctx2) {
  523. $4=_st(ann)._result();
  524. $3=_st($4).__eq_eq(result);
  525. if(smalltalk.assert($3)){
  526. return _st(_st(_st(result)._runs()).__eq(_st(result)._total()))._ifTrue_(assertBlock);
  527. };
  528. }, function($ctx2) {$ctx2.fillBlock({ann:ann},$ctx1,3)})}));
  529. _st(runner)._run();
  530. return self}, function($ctx1) {$ctx1.fill(self,"testTimeouts",{suite:suite,runner:runner,result:result,assertBlock:assertBlock},smalltalk.SUnitAsyncTest)})},
  531. args: [],
  532. 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",
  533. messageSends: ["collect:", "selector:", "class", "on:", "timeout:", "result", "async:", "assert:equals:", "selectorSetOf:", "errors", "new", "failures", "asSet", "finished", "on:do:", "announcer", "ifTrue:", "==", "=", "runs", "total", "run"],
  534. referencedClasses: ["TestSuiteRunner", "Set", "ResultAnnouncement"]
  535. }),
  536. smalltalk.SUnitAsyncTest);
  537. smalltalk.addMethod(
  538. smalltalk.method({
  539. selector: "testTwoAsyncPassesWithFinishedOnlyOneIsRun",
  540. category: 'tests',
  541. fn: function (){
  542. var self=this;
  543. var x;
  544. return smalltalk.withContext(function($ctx1) {
  545. var $1,$2;
  546. self["@flag"]="bad";
  547. self._timeout_((10));
  548. x=(0);
  549. $1=self._async_((function(){
  550. return smalltalk.withContext(function($ctx2) {
  551. self._finished();
  552. $ctx2.sendIdx["finished"]=1;
  553. self["@flag"]="ok";
  554. self["@flag"];
  555. x=_st(x).__plus((1));
  556. $ctx2.sendIdx["+"]=1;
  557. x;
  558. return self._assert_equals_(x,(1));
  559. $ctx2.sendIdx["assert:equals:"]=1;
  560. }, function($ctx2) {$ctx2.fillBlock({},$ctx1,1)})}));
  561. $ctx1.sendIdx["async:"]=1;
  562. self["@flag"]=_st($1)._valueWithTimeout_((0));
  563. $ctx1.sendIdx["valueWithTimeout:"]=1;
  564. $2=self._async_((function(){
  565. return smalltalk.withContext(function($ctx2) {
  566. self._finished();
  567. self["@flag"]="ok";
  568. self["@flag"];
  569. x=_st(x).__plus((1));
  570. x;
  571. return self._assert_equals_(x,(1));
  572. }, function($ctx2) {$ctx2.fillBlock({},$ctx1,2)})}));
  573. self["@flag"]=_st($2)._valueWithTimeout_((0));
  574. return self}, function($ctx1) {$ctx1.fill(self,"testTwoAsyncPassesWithFinishedOnlyOneIsRun",{x:x},smalltalk.SUnitAsyncTest)})},
  575. args: [],
  576. 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.",
  577. messageSends: ["timeout:", "valueWithTimeout:", "async:", "finished", "+", "assert:equals:"],
  578. referencedClasses: []
  579. }),
  580. smalltalk.SUnitAsyncTest);
  581. });