SUnit-Tests.js 24 KB

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