1
0

SUnit-Tests.js 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524
  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. self["@empty"]=smalltalk.send((smalltalk.Set || Set),"_new",[]);
  12. self["@full"]=smalltalk.send((smalltalk.Set || Set),"_with_with_",[(5),smalltalk.symbolFor("abc")]);
  13. return self},
  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. smalltalk.send(self["@empty"],"_add_",[(5)]);
  28. smalltalk.send(self,"_assert_",[smalltalk.send(self["@empty"],"_includes_",[(5)])]);
  29. return self},
  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. smalltalk.send(self["@empty"],"_addAll_",[smalltalk.send((1),"_to_",[(100)])]);
  44. smalltalk.send(self,"_assert_",[smalltalk.send(smalltalk.send(self["@empty"],"_size",[]),"__eq",[(100)])]);
  45. return self},
  46. args: [],
  47. source: "testGrow\x0a\x09empty addAll: (1 to: 100).\x0a\x09self assert: empty size = 100",
  48. messageSends: ["addAll:", "to:", "assert:", "=", "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. smalltalk.send(self,"_should_raise_",[(function(){
  60. return smalltalk.send(self["@empty"],"_at_",[(5)]);
  61. }),(smalltalk.Error || Error)]);
  62. smalltalk.send(self,"_should_raise_",[(function(){
  63. return smalltalk.send(self["@empty"],"_at_put_",[(5),smalltalk.symbolFor("abc")]);
  64. }),(smalltalk.Error || Error)]);
  65. return self},
  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. smalltalk.send(self,"_assert_",[smalltalk.send(self["@full"],"_includes_",[(5)])]);
  80. smalltalk.send(self,"_assert_",[smalltalk.send(self["@full"],"_includes_",[smalltalk.symbolFor("abc")])]);
  81. return self},
  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. smalltalk.send(self,"_assert_",[smalltalk.send(smalltalk.send(self["@empty"],"_occurrencesOf_",[(0)]),"__eq",[(0)])]);
  96. smalltalk.send(self,"_assert_",[smalltalk.send(smalltalk.send(self["@full"],"_occurrencesOf_",[(5)]),"__eq",[(1)])]);
  97. smalltalk.send(self["@full"],"_add_",[(5)]);
  98. smalltalk.send(self,"_assert_",[smalltalk.send(smalltalk.send(self["@full"],"_occurrencesOf_",[(5)]),"__eq",[(1)])]);
  99. return self},
  100. args: [],
  101. source: "testOccurrences\x0a\x09self assert: (empty occurrencesOf: 0) = 0.\x0a\x09self assert: (full occurrencesOf: 5) = 1.\x0a\x09full add: 5.\x0a\x09self assert: (full occurrencesOf: 5) = 1",
  102. messageSends: ["assert:", "=", "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. smalltalk.send(self["@full"],"_remove_",[(5)]);
  114. smalltalk.send(self,"_assert_",[smalltalk.send(self["@full"],"_includes_",[smalltalk.symbolFor("abc")])]);
  115. smalltalk.send(self,"_deny_",[smalltalk.send(self["@full"],"_includes_",[(5)])]);
  116. return self},
  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. self["@flag"]="bad";
  132. smalltalk.send(self,"_timeout_",[(10)]);
  133. self["@flag"]=smalltalk.send(smalltalk.send(self,"_async_",[(function(){
  134. self["@flag"]="ok";
  135. self["@flag"];
  136. return smalltalk.send(self,"_error_",["Intentional"]);
  137. })]),"_valueWithTimeout_",[(5)]);
  138. return self},
  139. args: [],
  140. source: "fakeError\x0a\x09flag := 'bad'.\x0a\x09self timeout: 10.\x0a flag := (self async: [ flag := 'ok'. self error: 'Intentional' ]) valueWithTimeout: 5\x0a",
  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. self["@flag"]="bad";
  153. smalltalk.send(self,"_timeout_",[(10)]);
  154. self["@flag"]=smalltalk.send(smalltalk.send(self,"_async_",[(function(){
  155. return smalltalk.send(self,"_error_",["Intentional"]);
  156. })]),"_valueWithTimeout_",[(5)]);
  157. return self},
  158. args: [],
  159. source: "fakeErrorFailingInTearDown\x0a\x09flag := 'bad'.\x0a\x09self timeout: 10.\x0a flag := (self async: [ self error: 'Intentional' ]) valueWithTimeout: 5\x0a",
  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. self["@flag"]="bad";
  172. smalltalk.send(self,"_timeout_",[(10)]);
  173. self["@flag"]=smalltalk.send(smalltalk.send(self,"_async_",[(function(){
  174. self["@flag"]="ok";
  175. self["@flag"];
  176. return smalltalk.send(self,"_assert_",[false]);
  177. })]),"_valueWithTimeout_",[(5)]);
  178. return self},
  179. args: [],
  180. source: "fakeFailure\x0a\x09flag := 'bad'.\x0a\x09self timeout: 10.\x0a flag := (self async: [ flag := 'ok'. self assert: false ]) valueWithTimeout: 5\x0a",
  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. smalltalk.send(self,"_timeout_",[(100)]);
  193. smalltalk.send(smalltalk.send(self,"_async_",[(function(){
  194. smalltalk.send(self,"_timeout_",[(5)]);
  195. return smalltalk.send(smalltalk.send(self,"_async_",[(function(){
  196. return smalltalk.send(self,"_finished",[]);
  197. })]),"_valueWithTimeout_",[(10)]);
  198. })]),"_valueWithTimeout_",[(5)]);
  199. return self},
  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\x0a",
  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. smalltalk.send(self,"_timeout_",[(10)]);
  214. smalltalk.send(smalltalk.send(self,"_async_",[(function(){
  215. smalltalk.send(self,"_timeout_",[(20)]);
  216. return smalltalk.send(smalltalk.send(self,"_async_",[(function(){
  217. return smalltalk.send(self,"_finished",[]);
  218. })]),"_valueWithTimeout_",[(10)]);
  219. })]),"_valueWithTimeout_",[(5)]);
  220. return self},
  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\x0a",
  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. smalltalk.send(self,"_timeout_",[(4)]);
  235. smalltalk.send(smalltalk.send(self,"_async_",[(function(){
  236. return smalltalk.send(self,"_finished",[]);
  237. })]),"_valueWithTimeout_",[(5)]);
  238. return self},
  239. args: [],
  240. source: "fakeTimeout\x0a\x09self timeout: 4.\x0a (self async: [ self finished ]) valueWithTimeout: 5\x0a",
  241. messageSends: ["timeout:", "valueWithTimeout:", "async:", "finished"],
  242. referencedClasses: []
  243. }),
  244. smalltalk.SUnitAsyncTest);
  245. smalltalk.addMethod(
  246. "_setUp",
  247. smalltalk.method({
  248. selector: "setUp",
  249. category: 'running',
  250. fn: function (){
  251. var self=this;
  252. self["@flag"]="ok";
  253. return self},
  254. args: [],
  255. source: "setUp\x0a\x09flag := 'ok'\x0a",
  256. messageSends: [],
  257. referencedClasses: []
  258. }),
  259. smalltalk.SUnitAsyncTest);
  260. smalltalk.addMethod(
  261. "_sortedSelectors_",
  262. smalltalk.method({
  263. selector: "sortedSelectors:",
  264. category: 'private',
  265. fn: function (aCollection){
  266. var self=this;
  267. var $1;
  268. $1=smalltalk.send(smalltalk.send(aCollection,"_collect_",[(function(each){
  269. return smalltalk.send(each,"_selector",[]);
  270. })]),"_sorted",[]);
  271. return $1;
  272. },
  273. args: ["aCollection"],
  274. source: "sortedSelectors: aCollection\x0a\x09^(aCollection collect: [:each | each selector]) sorted",
  275. messageSends: ["sorted", "collect:", "selector"],
  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. smalltalk.send(self,"_assert_equals_",["ok",self["@flag"]]);
  287. return self},
  288. args: [],
  289. source: "tearDown\x0a\x09self assert: 'ok' equals: flag\x0a",
  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 $1,$2,$4,$6,$5,$3;
  302. var suite;
  303. var runner;
  304. var result;
  305. var assertBlock;
  306. suite=smalltalk.send(["fakeError", "fakeErrorFailingInTearDown", "fakeFailure", "testPass"],"_collect_",[(function(each){
  307. return smalltalk.send(smalltalk.send(self,"_class",[]),"_selector_",[each]);
  308. })]);
  309. runner=smalltalk.send((smalltalk.TestSuiteRunner || TestSuiteRunner),"_on_",[suite]);
  310. smalltalk.send(self,"_timeout_",[(200)]);
  311. result=smalltalk.send(runner,"_result",[]);
  312. assertBlock=smalltalk.send(self,"_async_",[(function(){
  313. smalltalk.send(self,"_assert_equals_",[["fakeError"],smalltalk.send(self,"_sortedSelectors_",[smalltalk.send(result,"_errors",[])])]);
  314. smalltalk.send(self,"_assert_equals_",[["fakeErrorFailingInTearDown", "fakeFailure"],smalltalk.send(self,"_sortedSelectors_",[smalltalk.send(result,"_failures",[])])]);
  315. return smalltalk.send(self,"_finished",[]);
  316. })]);
  317. $1=smalltalk.send(runner,"_announcer",[]);
  318. $2=(smalltalk.ResultAnnouncement || ResultAnnouncement);
  319. $3=(function(ann){
  320. $4=smalltalk.send(smalltalk.send(ann,"_result",[]),"__eq_eq",[result]);
  321. $5=(function(){
  322. $6=smalltalk.send(smalltalk.send(result,"_runs",[]),"__eq",[smalltalk.send(result,"_total",[])]);
  323. return smalltalk.send($6,"_ifTrue_",[assertBlock]);
  324. });
  325. return smalltalk.send($4,"_ifTrue_",[$5]);
  326. });
  327. smalltalk.send($1,"_on_do_",[$2,$3]);
  328. smalltalk.send(runner,"_run",[]);
  329. return self},
  330. args: [],
  331. 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: #('fakeError') equals: (self sortedSelectors: result errors).\x0a\x09\x09self assert: #('fakeErrorFailingInTearDown' 'fakeFailure') equals: (self sortedSelectors: result failures).\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",
  332. messageSends: ["collect:", "selector:", "class", "on:", "timeout:", "result", "async:", "assert:equals:", "sortedSelectors:", "errors", "failures", "finished", "on:do:", "ifTrue:", "=", "total", "runs", "==", "announcer", "run"],
  333. referencedClasses: ["TestSuiteRunner", "ResultAnnouncement"]
  334. }),
  335. smalltalk.SUnitAsyncTest);
  336. smalltalk.addMethod(
  337. "_testAsyncNeedsTimeout",
  338. smalltalk.method({
  339. selector: "testAsyncNeedsTimeout",
  340. category: 'tests',
  341. fn: function (){
  342. var self=this;
  343. smalltalk.send(self,"_should_raise_",[(function(){
  344. return smalltalk.send(self,"_async_",[(function(){
  345. })]);
  346. }),(smalltalk.Error || Error)]);
  347. smalltalk.send(self,"_timeout_",[(0)]);
  348. smalltalk.send(self,"_shouldnt_raise_",[(function(){
  349. return smalltalk.send(self,"_async_",[(function(){
  350. })]);
  351. }),(smalltalk.Error || Error)]);
  352. smalltalk.send(self,"_finished",[]);
  353. return self},
  354. args: [],
  355. source: "testAsyncNeedsTimeout\x0a self should: [ self async: [ ] ] raise: Error.\x0a self timeout: 0.\x0a self shouldnt: [ self async: [ ] ] raise: Error.\x0a self finished\x0a",
  356. messageSends: ["should:raise:", "async:", "timeout:", "shouldnt:raise:", "finished"],
  357. referencedClasses: ["Error"]
  358. }),
  359. smalltalk.SUnitAsyncTest);
  360. smalltalk.addMethod(
  361. "_testFinishedNeedsTimeout",
  362. smalltalk.method({
  363. selector: "testFinishedNeedsTimeout",
  364. category: 'tests',
  365. fn: function (){
  366. var self=this;
  367. smalltalk.send(self,"_should_raise_",[(function(){
  368. return smalltalk.send(self,"_finished",[]);
  369. }),(smalltalk.Error || Error)]);
  370. smalltalk.send(self,"_timeout_",[(0)]);
  371. smalltalk.send(self,"_shouldnt_raise_",[(function(){
  372. return smalltalk.send(self,"_finished",[]);
  373. }),(smalltalk.Error || Error)]);
  374. return self},
  375. args: [],
  376. source: "testFinishedNeedsTimeout\x0a self should: [ self finished ] raise: Error.\x0a self timeout: 0.\x0a self shouldnt: [ self finished ] raise: Error.\x0a",
  377. messageSends: ["should:raise:", "finished", "timeout:", "shouldnt:raise:"],
  378. referencedClasses: ["Error"]
  379. }),
  380. smalltalk.SUnitAsyncTest);
  381. smalltalk.addMethod(
  382. "_testIsAsyncReturnsCorrectValues",
  383. smalltalk.method({
  384. selector: "testIsAsyncReturnsCorrectValues",
  385. category: 'tests',
  386. fn: function (){
  387. var self=this;
  388. smalltalk.send(self,"_deny_",[smalltalk.send(self,"_isAsync",[])]);
  389. smalltalk.send(self,"_timeout_",[(0)]);
  390. smalltalk.send(self,"_assert_",[smalltalk.send(self,"_isAsync",[])]);
  391. smalltalk.send(self,"_finished",[]);
  392. smalltalk.send(self,"_deny_",[smalltalk.send(self,"_isAsync",[])]);
  393. return self},
  394. args: [],
  395. source: "testIsAsyncReturnsCorrectValues\x0a self deny: self isAsync.\x0a self timeout: 0.\x0a self assert: self isAsync.\x0a self finished.\x0a self deny: self isAsync\x0a",
  396. messageSends: ["deny:", "isAsync", "timeout:", "assert:", "finished"],
  397. referencedClasses: []
  398. }),
  399. smalltalk.SUnitAsyncTest);
  400. smalltalk.addMethod(
  401. "_testPass",
  402. smalltalk.method({
  403. selector: "testPass",
  404. category: 'tests',
  405. fn: function (){
  406. var self=this;
  407. self["@flag"]="bad";
  408. smalltalk.send(self,"_timeout_",[(10)]);
  409. self["@flag"]=smalltalk.send(smalltalk.send(self,"_async_",[(function(){
  410. smalltalk.send(self,"_assert_",[true]);
  411. smalltalk.send(self,"_finished",[]);
  412. self["@flag"]="ok";
  413. return self["@flag"];
  414. })]),"_valueWithTimeout_",[(5)]);
  415. return self},
  416. args: [],
  417. source: "testPass\x0a\x09flag := 'bad'.\x0a\x09self timeout: 10.\x0a flag := (self async: [ self assert: true. self finished. flag := 'ok' ]) valueWithTimeout: 5\x0a",
  418. messageSends: ["timeout:", "valueWithTimeout:", "async:", "assert:", "finished"],
  419. referencedClasses: []
  420. }),
  421. smalltalk.SUnitAsyncTest);
  422. smalltalk.addMethod(
  423. "_testTimeouts",
  424. smalltalk.method({
  425. selector: "testTimeouts",
  426. category: 'tests',
  427. fn: function (){
  428. var self=this;
  429. var $1,$2,$4,$6,$5,$3;
  430. var suite;
  431. var runner;
  432. var result;
  433. var assertBlock;
  434. suite=smalltalk.send(["fakeTimeout", "fakeMultipleTimeoutFailing", "fakeMultipleTimeoutPassing", "testPass"],"_collect_",[(function(each){
  435. return smalltalk.send(smalltalk.send(self,"_class",[]),"_selector_",[each]);
  436. })]);
  437. runner=smalltalk.send((smalltalk.TestSuiteRunner || TestSuiteRunner),"_on_",[suite]);
  438. smalltalk.send(self,"_timeout_",[(200)]);
  439. result=smalltalk.send(runner,"_result",[]);
  440. assertBlock=smalltalk.send(self,"_async_",[(function(){
  441. smalltalk.send(self,"_assert_",[smalltalk.send(smalltalk.send(result,"_errors",[]),"_isEmpty",[])]);
  442. smalltalk.send(self,"_assert_equals_",[["fakeMultipleTimeoutFailing", "fakeTimeout"],smalltalk.send(self,"_sortedSelectors_",[smalltalk.send(result,"_failures",[])])]);
  443. return smalltalk.send(self,"_finished",[]);
  444. })]);
  445. $1=smalltalk.send(runner,"_announcer",[]);
  446. $2=(smalltalk.ResultAnnouncement || ResultAnnouncement);
  447. $3=(function(ann){
  448. $4=smalltalk.send(smalltalk.send(ann,"_result",[]),"__eq_eq",[result]);
  449. $5=(function(){
  450. $6=smalltalk.send(smalltalk.send(result,"_runs",[]),"__eq",[smalltalk.send(result,"_total",[])]);
  451. return smalltalk.send($6,"_ifTrue_",[assertBlock]);
  452. });
  453. return smalltalk.send($4,"_ifTrue_",[$5]);
  454. });
  455. smalltalk.send($1,"_on_do_",[$2,$3]);
  456. smalltalk.send(runner,"_run",[]);
  457. return self},
  458. args: [],
  459. 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: result errors isEmpty.\x0a\x09\x09self assert: #('fakeMultipleTimeoutFailing' 'fakeTimeout') equals: (self sortedSelectors: result failures).\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",
  460. messageSends: ["collect:", "selector:", "class", "on:", "timeout:", "result", "async:", "assert:", "isEmpty", "errors", "assert:equals:", "sortedSelectors:", "failures", "finished", "on:do:", "ifTrue:", "=", "total", "runs", "==", "announcer", "run"],
  461. referencedClasses: ["TestSuiteRunner", "ResultAnnouncement"]
  462. }),
  463. smalltalk.SUnitAsyncTest);
  464. smalltalk.addMethod(
  465. "_testTwoAsyncPassesWithFinishedOnlyOneIsRun",
  466. smalltalk.method({
  467. selector: "testTwoAsyncPassesWithFinishedOnlyOneIsRun",
  468. category: 'tests',
  469. fn: function (){
  470. var self=this;
  471. var x;
  472. self["@flag"]="bad";
  473. smalltalk.send(self,"_timeout_",[(10)]);
  474. x=(0);
  475. self["@flag"]=smalltalk.send(smalltalk.send(self,"_async_",[(function(){
  476. smalltalk.send(self,"_finished",[]);
  477. self["@flag"]="ok";
  478. self["@flag"];
  479. x=smalltalk.send(x,"__plus",[(1)]);
  480. x;
  481. return smalltalk.send(self,"_assert_equals_",[(1),x]);
  482. })]),"_valueWithTimeout_",[(0)]);
  483. self["@flag"]=smalltalk.send(smalltalk.send(self,"_async_",[(function(){
  484. smalltalk.send(self,"_finished",[]);
  485. self["@flag"]="ok";
  486. self["@flag"];
  487. x=smalltalk.send(x,"__plus",[(1)]);
  488. x;
  489. return smalltalk.send(self,"_assert_equals_",[(1),x]);
  490. })]),"_valueWithTimeout_",[(0)]);
  491. return self},
  492. args: [],
  493. 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: 1 equals: x ]) valueWithTimeout: 0.\x0a flag := (self async: [ self finished. flag := 'ok'. x := x+1. self assert: 1 equals: x ]) valueWithTimeout: 0.\x0a",
  494. messageSends: ["timeout:", "valueWithTimeout:", "async:", "finished", "+", "assert:equals:"],
  495. referencedClasses: []
  496. }),
  497. smalltalk.SUnitAsyncTest);