SUnit-Tests.js 23 KB

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