SUnit-Tests.js 24 KB

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