2
0

SUnit-Tests.js 23 KB

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