1
0

SUnit-Tests.js 23 KB

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