1
0

SUnit-Tests.js 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597
  1. define("amber_core/SUnit-Tests", ["amber_vm/smalltalk", "amber_vm/nil", "amber_vm/_st", "amber_vm/globals", "amber_core/SUnit"], function(smalltalk,nil,_st, globals){
  2. smalltalk.addPackage('SUnit-Tests');
  3. smalltalk.packages["SUnit-Tests"].transport = {"type":"amd","amdNamespace":"amber_core"};
  4. smalltalk.addClass('ExampleSetTest', globals.TestCase, ['empty', 'full'], 'SUnit-Tests');
  5. 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.";
  6. smalltalk.addMethod(
  7. smalltalk.method({
  8. selector: "setUp",
  9. protocol: 'running',
  10. fn: function (){
  11. var self=this;
  12. function $Set(){return globals.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",{},globals.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. globals.ExampleSetTest);
  23. smalltalk.addMethod(
  24. smalltalk.method({
  25. selector: "testAdd",
  26. protocol: '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",{},globals.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. globals.ExampleSetTest);
  39. smalltalk.addMethod(
  40. smalltalk.method({
  41. selector: "testGrow",
  42. protocol: '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",{},globals.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. globals.ExampleSetTest);
  55. smalltalk.addMethod(
  56. smalltalk.method({
  57. selector: "testIllegal",
  58. protocol: 'tests',
  59. fn: function (){
  60. var self=this;
  61. function $Error(){return globals.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",{},globals.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. globals.ExampleSetTest);
  79. smalltalk.addMethod(
  80. smalltalk.method({
  81. selector: "testIncludes",
  82. protocol: '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",{},globals.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. globals.ExampleSetTest);
  99. smalltalk.addMethod(
  100. smalltalk.method({
  101. selector: "testOccurrences",
  102. protocol: '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",{},globals.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. globals.ExampleSetTest);
  124. smalltalk.addMethod(
  125. smalltalk.method({
  126. selector: "testRemove",
  127. protocol: '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",{},globals.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. globals.ExampleSetTest);
  144. smalltalk.addClass('SUnitAsyncTest', globals.TestCase, ['flag'], 'SUnit-Tests');
  145. smalltalk.addMethod(
  146. smalltalk.method({
  147. selector: "fakeError",
  148. protocol: '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",{},globals.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. globals.SUnitAsyncTest);
  167. smalltalk.addMethod(
  168. smalltalk.method({
  169. selector: "fakeErrorFailingInTearDown",
  170. protocol: '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",{},globals.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. globals.SUnitAsyncTest);
  187. smalltalk.addMethod(
  188. smalltalk.method({
  189. selector: "fakeFailure",
  190. protocol: '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",{},globals.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. globals.SUnitAsyncTest);
  209. smalltalk.addMethod(
  210. smalltalk.method({
  211. selector: "fakeMultipleTimeoutFailing",
  212. protocol: '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",{},globals.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. globals.SUnitAsyncTest);
  237. smalltalk.addMethod(
  238. smalltalk.method({
  239. selector: "fakeMultipleTimeoutPassing",
  240. protocol: '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",{},globals.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. globals.SUnitAsyncTest);
  265. smalltalk.addMethod(
  266. smalltalk.method({
  267. selector: "fakeTimeout",
  268. protocol: '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",{},globals.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. globals.SUnitAsyncTest);
  284. smalltalk.addMethod(
  285. smalltalk.method({
  286. selector: "selectorSetOf:",
  287. protocol: '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},globals.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. globals.SUnitAsyncTest);
  304. smalltalk.addMethod(
  305. smalltalk.method({
  306. selector: "setUp",
  307. protocol: 'running',
  308. fn: function (){
  309. var self=this;
  310. self["@flag"]="ok";
  311. return self},
  312. args: [],
  313. source: "setUp\x0a\x09flag := 'ok'",
  314. messageSends: [],
  315. referencedClasses: []
  316. }),
  317. globals.SUnitAsyncTest);
  318. smalltalk.addMethod(
  319. smalltalk.method({
  320. selector: "tearDown",
  321. protocol: 'running',
  322. fn: function (){
  323. var self=this;
  324. return smalltalk.withContext(function($ctx1) {
  325. self._assert_equals_("ok",self["@flag"]);
  326. return self}, function($ctx1) {$ctx1.fill(self,"tearDown",{},globals.SUnitAsyncTest)})},
  327. args: [],
  328. source: "tearDown\x0a\x09self assert: 'ok' equals: flag",
  329. messageSends: ["assert:equals:"],
  330. referencedClasses: []
  331. }),
  332. globals.SUnitAsyncTest);
  333. smalltalk.addMethod(
  334. smalltalk.method({
  335. selector: "testAsyncErrorsAndFailures",
  336. protocol: 'tests',
  337. fn: function (){
  338. var self=this;
  339. var suite,runner,result,assertBlock;
  340. function $TestSuiteRunner(){return globals.TestSuiteRunner||(typeof TestSuiteRunner=="undefined"?nil:TestSuiteRunner)}
  341. function $ResultAnnouncement(){return globals.ResultAnnouncement||(typeof ResultAnnouncement=="undefined"?nil:ResultAnnouncement)}
  342. return smalltalk.withContext(function($ctx1) {
  343. var $1,$2,$3,$4;
  344. suite=["fakeError", "fakeErrorFailingInTearDown", "fakeFailure", "testPass"]._collect_((function(each){
  345. return smalltalk.withContext(function($ctx2) {
  346. return _st(self._class())._selector_(each);
  347. }, function($ctx2) {$ctx2.fillBlock({each:each},$ctx1,1)})}));
  348. runner=_st($TestSuiteRunner())._on_(suite);
  349. self._timeout_((200));
  350. result=_st(runner)._result();
  351. $ctx1.sendIdx["result"]=1;
  352. assertBlock=self._async_((function(){
  353. return smalltalk.withContext(function($ctx2) {
  354. $1=self._selectorSetOf_(_st(result)._errors());
  355. $ctx2.sendIdx["selectorSetOf:"]=1;
  356. $2=["fakeError"]._asSet();
  357. $ctx2.sendIdx["asSet"]=1;
  358. self._assert_equals_($1,$2);
  359. $ctx2.sendIdx["assert:equals:"]=1;
  360. self._assert_equals_(self._selectorSetOf_(_st(result)._failures()),["fakeErrorFailingInTearDown", "fakeFailure"]._asSet());
  361. return self._finished();
  362. }, function($ctx2) {$ctx2.fillBlock({},$ctx1,2)})}));
  363. _st(_st(runner)._announcer())._on_do_($ResultAnnouncement(),(function(ann){
  364. return smalltalk.withContext(function($ctx2) {
  365. $3=_st(_st(ann)._result()).__eq_eq(result);
  366. if(smalltalk.assert($3)){
  367. $4=_st(_st(result)._runs()).__eq(_st(result)._total());
  368. return _st($4)._ifTrue_(assertBlock);
  369. };
  370. }, function($ctx2) {$ctx2.fillBlock({ann:ann},$ctx1,3)})}));
  371. _st(runner)._run();
  372. return self}, function($ctx1) {$ctx1.fill(self,"testAsyncErrorsAndFailures",{suite:suite,runner:runner,result:result,assertBlock:assertBlock},globals.SUnitAsyncTest)})},
  373. args: [],
  374. 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",
  375. messageSends: ["collect:", "selector:", "class", "on:", "timeout:", "result", "async:", "assert:equals:", "selectorSetOf:", "errors", "asSet", "failures", "finished", "on:do:", "announcer", "ifTrue:", "==", "=", "runs", "total", "run"],
  376. referencedClasses: ["TestSuiteRunner", "ResultAnnouncement"]
  377. }),
  378. globals.SUnitAsyncTest);
  379. smalltalk.addMethod(
  380. smalltalk.method({
  381. selector: "testAsyncNeedsTimeout",
  382. protocol: 'tests',
  383. fn: function (){
  384. var self=this;
  385. function $Error(){return globals.Error||(typeof Error=="undefined"?nil:Error)}
  386. return smalltalk.withContext(function($ctx1) {
  387. self._should_raise_((function(){
  388. return smalltalk.withContext(function($ctx2) {
  389. return self._async_((function(){
  390. return smalltalk.withContext(function($ctx3) {
  391. }, function($ctx3) {$ctx3.fillBlock({},$ctx2,2)})}));
  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. return smalltalk.withContext(function($ctx3) {
  399. }, function($ctx3) {$ctx3.fillBlock({},$ctx2,4)})}));
  400. }, function($ctx2) {$ctx2.fillBlock({},$ctx1,3)})}),$Error());
  401. self._finished();
  402. return self}, function($ctx1) {$ctx1.fill(self,"testAsyncNeedsTimeout",{},globals.SUnitAsyncTest)})},
  403. args: [],
  404. source: "testAsyncNeedsTimeout\x0a\x09self should: [ self async: [ ] ] raise: Error.\x0a\x09self timeout: 0.\x0a\x09self shouldnt: [ self async: [ ] ] raise: Error.\x0a\x09self finished",
  405. messageSends: ["should:raise:", "async:", "timeout:", "shouldnt:raise:", "finished"],
  406. referencedClasses: ["Error"]
  407. }),
  408. globals.SUnitAsyncTest);
  409. smalltalk.addMethod(
  410. smalltalk.method({
  411. selector: "testFinishedNeedsTimeout",
  412. protocol: 'tests',
  413. fn: function (){
  414. var self=this;
  415. function $Error(){return globals.Error||(typeof Error=="undefined"?nil:Error)}
  416. return smalltalk.withContext(function($ctx1) {
  417. self._should_raise_((function(){
  418. return smalltalk.withContext(function($ctx2) {
  419. return self._finished();
  420. $ctx2.sendIdx["finished"]=1;
  421. }, function($ctx2) {$ctx2.fillBlock({},$ctx1,1)})}),$Error());
  422. self._timeout_((0));
  423. self._shouldnt_raise_((function(){
  424. return smalltalk.withContext(function($ctx2) {
  425. return self._finished();
  426. }, function($ctx2) {$ctx2.fillBlock({},$ctx1,2)})}),$Error());
  427. return self}, function($ctx1) {$ctx1.fill(self,"testFinishedNeedsTimeout",{},globals.SUnitAsyncTest)})},
  428. args: [],
  429. source: "testFinishedNeedsTimeout\x0a\x09self should: [ self finished ] raise: Error.\x0a\x09self timeout: 0.\x0a\x09self shouldnt: [ self finished ] raise: Error.",
  430. messageSends: ["should:raise:", "finished", "timeout:", "shouldnt:raise:"],
  431. referencedClasses: ["Error"]
  432. }),
  433. globals.SUnitAsyncTest);
  434. smalltalk.addMethod(
  435. smalltalk.method({
  436. selector: "testIsAsyncReturnsCorrectValues",
  437. protocol: 'tests',
  438. fn: function (){
  439. var self=this;
  440. return smalltalk.withContext(function($ctx1) {
  441. var $1,$2;
  442. $1=self._isAsync();
  443. $ctx1.sendIdx["isAsync"]=1;
  444. self._deny_($1);
  445. $ctx1.sendIdx["deny:"]=1;
  446. self._timeout_((0));
  447. $2=self._isAsync();
  448. $ctx1.sendIdx["isAsync"]=2;
  449. self._assert_($2);
  450. self._finished();
  451. self._deny_(self._isAsync());
  452. return self}, function($ctx1) {$ctx1.fill(self,"testIsAsyncReturnsCorrectValues",{},globals.SUnitAsyncTest)})},
  453. args: [],
  454. source: "testIsAsyncReturnsCorrectValues\x0a\x09self deny: self isAsync.\x0a\x09self timeout: 0.\x0a\x09self assert: self isAsync.\x0a\x09self finished.\x0a\x09self deny: self isAsync",
  455. messageSends: ["deny:", "isAsync", "timeout:", "assert:", "finished"],
  456. referencedClasses: []
  457. }),
  458. globals.SUnitAsyncTest);
  459. smalltalk.addMethod(
  460. smalltalk.method({
  461. selector: "testPass",
  462. protocol: 'tests',
  463. fn: function (){
  464. var self=this;
  465. return smalltalk.withContext(function($ctx1) {
  466. self["@flag"]="bad";
  467. self._timeout_((10));
  468. self["@flag"]=_st(self._async_((function(){
  469. return smalltalk.withContext(function($ctx2) {
  470. self._assert_(true);
  471. self._finished();
  472. self["@flag"]="ok";
  473. return self["@flag"];
  474. }, function($ctx2) {$ctx2.fillBlock({},$ctx1,1)})})))._valueWithTimeout_((5));
  475. return self}, function($ctx1) {$ctx1.fill(self,"testPass",{},globals.SUnitAsyncTest)})},
  476. args: [],
  477. source: "testPass\x0a\x09flag := 'bad'.\x0a\x09self timeout: 10.\x0a\x09flag := (self async: [ self assert: true. self finished. flag := 'ok' ]) valueWithTimeout: 5",
  478. messageSends: ["timeout:", "valueWithTimeout:", "async:", "assert:", "finished"],
  479. referencedClasses: []
  480. }),
  481. globals.SUnitAsyncTest);
  482. smalltalk.addMethod(
  483. smalltalk.method({
  484. selector: "testTimeouts",
  485. protocol: 'tests',
  486. fn: function (){
  487. var self=this;
  488. var suite,runner,result,assertBlock;
  489. function $TestSuiteRunner(){return globals.TestSuiteRunner||(typeof TestSuiteRunner=="undefined"?nil:TestSuiteRunner)}
  490. function $Set(){return globals.Set||(typeof Set=="undefined"?nil:Set)}
  491. function $ResultAnnouncement(){return globals.ResultAnnouncement||(typeof ResultAnnouncement=="undefined"?nil:ResultAnnouncement)}
  492. return smalltalk.withContext(function($ctx1) {
  493. var $1,$2,$3;
  494. suite=["fakeTimeout", "fakeMultipleTimeoutFailing", "fakeMultipleTimeoutPassing", "testPass"]._collect_((function(each){
  495. return smalltalk.withContext(function($ctx2) {
  496. return _st(self._class())._selector_(each);
  497. }, function($ctx2) {$ctx2.fillBlock({each:each},$ctx1,1)})}));
  498. runner=_st($TestSuiteRunner())._on_(suite);
  499. self._timeout_((200));
  500. result=_st(runner)._result();
  501. $ctx1.sendIdx["result"]=1;
  502. assertBlock=self._async_((function(){
  503. return smalltalk.withContext(function($ctx2) {
  504. $1=self._selectorSetOf_(_st(result)._errors());
  505. $ctx2.sendIdx["selectorSetOf:"]=1;
  506. self._assert_equals_($1,_st($Set())._new());
  507. $ctx2.sendIdx["assert:equals:"]=1;
  508. self._assert_equals_(self._selectorSetOf_(_st(result)._failures()),["fakeMultipleTimeoutFailing", "fakeTimeout"]._asSet());
  509. return self._finished();
  510. }, function($ctx2) {$ctx2.fillBlock({},$ctx1,2)})}));
  511. _st(_st(runner)._announcer())._on_do_($ResultAnnouncement(),(function(ann){
  512. return smalltalk.withContext(function($ctx2) {
  513. $2=_st(_st(ann)._result()).__eq_eq(result);
  514. if(smalltalk.assert($2)){
  515. $3=_st(_st(result)._runs()).__eq(_st(result)._total());
  516. return _st($3)._ifTrue_(assertBlock);
  517. };
  518. }, function($ctx2) {$ctx2.fillBlock({ann:ann},$ctx1,3)})}));
  519. _st(runner)._run();
  520. return self}, function($ctx1) {$ctx1.fill(self,"testTimeouts",{suite:suite,runner:runner,result:result,assertBlock:assertBlock},globals.SUnitAsyncTest)})},
  521. args: [],
  522. 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",
  523. messageSends: ["collect:", "selector:", "class", "on:", "timeout:", "result", "async:", "assert:equals:", "selectorSetOf:", "errors", "new", "failures", "asSet", "finished", "on:do:", "announcer", "ifTrue:", "==", "=", "runs", "total", "run"],
  524. referencedClasses: ["TestSuiteRunner", "Set", "ResultAnnouncement"]
  525. }),
  526. globals.SUnitAsyncTest);
  527. smalltalk.addMethod(
  528. smalltalk.method({
  529. selector: "testTwoAsyncPassesWithFinishedOnlyOneIsRun",
  530. protocol: 'tests',
  531. fn: function (){
  532. var self=this;
  533. var x;
  534. return smalltalk.withContext(function($ctx1) {
  535. var $1;
  536. self["@flag"]="bad";
  537. self._timeout_((10));
  538. x=(0);
  539. $1=self._async_((function(){
  540. return smalltalk.withContext(function($ctx2) {
  541. self._finished();
  542. $ctx2.sendIdx["finished"]=1;
  543. self["@flag"]="ok";
  544. self["@flag"];
  545. x=_st(x).__plus((1));
  546. $ctx2.sendIdx["+"]=1;
  547. x;
  548. return self._assert_equals_(x,(1));
  549. $ctx2.sendIdx["assert:equals:"]=1;
  550. }, function($ctx2) {$ctx2.fillBlock({},$ctx1,1)})}));
  551. $ctx1.sendIdx["async:"]=1;
  552. self["@flag"]=_st($1)._valueWithTimeout_((0));
  553. $ctx1.sendIdx["valueWithTimeout:"]=1;
  554. self["@flag"]=_st(self._async_((function(){
  555. return smalltalk.withContext(function($ctx2) {
  556. self._finished();
  557. self["@flag"]="ok";
  558. self["@flag"];
  559. x=_st(x).__plus((1));
  560. x;
  561. return self._assert_equals_(x,(1));
  562. }, function($ctx2) {$ctx2.fillBlock({},$ctx1,2)})})))._valueWithTimeout_((0));
  563. return self}, function($ctx1) {$ctx1.fill(self,"testTwoAsyncPassesWithFinishedOnlyOneIsRun",{x:x},globals.SUnitAsyncTest)})},
  564. args: [],
  565. 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.",
  566. messageSends: ["timeout:", "valueWithTimeout:", "async:", "finished", "+", "assert:equals:"],
  567. referencedClasses: []
  568. }),
  569. globals.SUnitAsyncTest);
  570. });