2
0

SUnit-Tests.js 23 KB

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