SUnit-Tests.js 24 KB

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