SUnit-Tests.js 24 KB

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