SUnit-Tests.js 23 KB

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