1
0

SUnit.js 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832
  1. smalltalk.addPackage('SUnit', {});
  2. smalltalk.addClass('ResultAnnouncement', smalltalk.Object, ['result'], 'SUnit');
  3. smalltalk.addMethod(
  4. "_result",
  5. smalltalk.method({
  6. selector: "result",
  7. category: 'accessing',
  8. fn: function (){
  9. var self=this;
  10. return self["@result"];
  11. },
  12. args: [],
  13. source: "result\x0a\x09^result",
  14. messageSends: [],
  15. referencedClasses: []
  16. }),
  17. smalltalk.ResultAnnouncement);
  18. smalltalk.addMethod(
  19. "_result_",
  20. smalltalk.method({
  21. selector: "result:",
  22. category: 'accessing',
  23. fn: function (aTestResult){
  24. var self=this;
  25. self["@result"]=aTestResult;
  26. return self},
  27. args: ["aTestResult"],
  28. source: "result: aTestResult\x0a\x09result := aTestResult",
  29. messageSends: [],
  30. referencedClasses: []
  31. }),
  32. smalltalk.ResultAnnouncement);
  33. smalltalk.addClass('TestCase', smalltalk.Object, ['testSelector'], 'SUnit');
  34. smalltalk.addMethod(
  35. "_assert_",
  36. smalltalk.method({
  37. selector: "assert:",
  38. category: 'testing',
  39. fn: function (aBoolean) {
  40. var self = this;
  41. smalltalk.send(self, "_assert_description_", [aBoolean, "Assertion failed"]);
  42. return self;
  43. },
  44. args: ["aBoolean"],
  45. source: "assert: aBoolean\x0a\x09self assert: aBoolean description: 'Assertion failed'",
  46. messageSends: ["assert:description:"],
  47. referencedClasses: []
  48. }),
  49. smalltalk.TestCase);
  50. smalltalk.addMethod(
  51. "_assert_description_",
  52. smalltalk.method({
  53. selector: "assert:description:",
  54. category: 'testing',
  55. fn: function (aBoolean, aString) {
  56. var self = this;
  57. if (!smalltalk.assert(aBoolean)) {
  58. smalltalk.send(self, "_signalFailure_", [aString]);
  59. }
  60. return self;
  61. },
  62. args: ["aBoolean", "aString"],
  63. source: "assert: aBoolean description: aString\x0a\x09aBoolean ifFalse: [self signalFailure: aString]",
  64. messageSends: ["ifFalse:", "signalFailure:"],
  65. referencedClasses: []
  66. }),
  67. smalltalk.TestCase);
  68. smalltalk.addMethod(
  69. "_assert_equals_",
  70. smalltalk.method({
  71. selector: "assert:equals:",
  72. category: 'testing',
  73. fn: function (expected, actual) {
  74. var self = this;
  75. var $1;
  76. $1 = smalltalk.send(self, "_assert_description_", [smalltalk.send(expected, "__eq", [actual]), smalltalk.send(smalltalk.send(smalltalk.send("Expected: ", "__comma", [smalltalk.send(expected, "_asString", [])]), "__comma", [" but was: "]), "__comma", [smalltalk.send(actual, "_asString", [])])]);
  77. return $1;
  78. },
  79. args: ["expected", "actual"],
  80. source: "assert: expected equals: actual\x0a\x09^ self assert: (expected = actual) description: 'Expected: ', expected asString, ' but was: ', actual asString",
  81. messageSends: ["assert:description:", "=", ",", "asString"],
  82. referencedClasses: []
  83. }),
  84. smalltalk.TestCase);
  85. smalltalk.addMethod(
  86. "_deny_",
  87. smalltalk.method({
  88. selector: "deny:",
  89. category: 'testing',
  90. fn: function (aBoolean) {
  91. var self = this;
  92. smalltalk.send(self, "_assert_", [smalltalk.send(aBoolean, "_not", [])]);
  93. return self;
  94. },
  95. args: ["aBoolean"],
  96. source: "deny: aBoolean\x0a\x09self assert: aBoolean not",
  97. messageSends: ["assert:", "not"],
  98. referencedClasses: []
  99. }),
  100. smalltalk.TestCase);
  101. smalltalk.addMethod(
  102. "_performTest",
  103. smalltalk.method({
  104. selector: "performTest",
  105. category: 'running',
  106. fn: function (){
  107. var self=this;
  108. smalltalk.send(self,"_perform_",[smalltalk.send(self,"_selector",[])]);
  109. return self},
  110. args: [],
  111. source: "performTest\x0a\x09self perform: self selector\x0a",
  112. messageSends: ["perform:", "selector"],
  113. referencedClasses: []
  114. }),
  115. smalltalk.TestCase);
  116. smalltalk.addMethod(
  117. "_runCase",
  118. smalltalk.method({
  119. selector: "runCase",
  120. category: 'running',
  121. fn: function (){
  122. var self=this;
  123. smalltalk.send((function(){
  124. smalltalk.send(self,"_setUp",[]);
  125. return smalltalk.send(self,"_performTest",[]);
  126. }),"_ensure_",[(function(){
  127. return smalltalk.send(self,"_tearDown",[]);
  128. })]);
  129. return self},
  130. args: [],
  131. source: "runCase\x0a\x09[\x09self setUp.\x0a\x09\x09self performTest ] ensure: [\x0a\x09\x09self tearDown ]\x0a",
  132. messageSends: ["ensure:", "tearDown", "setUp", "performTest"],
  133. referencedClasses: []
  134. }),
  135. smalltalk.TestCase);
  136. smalltalk.addMethod(
  137. "_selector",
  138. smalltalk.method({
  139. selector: "selector",
  140. category: 'accessing',
  141. fn: function () {
  142. var self = this;
  143. return self['@testSelector'];
  144. },
  145. args: [],
  146. source: "selector\x0a\x09^testSelector",
  147. messageSends: [],
  148. referencedClasses: []
  149. }),
  150. smalltalk.TestCase);
  151. smalltalk.addMethod(
  152. "_setTestSelector_",
  153. smalltalk.method({
  154. selector: "setTestSelector:",
  155. category: 'accessing',
  156. fn: function (aSelector) {
  157. var self = this;
  158. self['@testSelector'] = aSelector;
  159. return self;
  160. },
  161. args: ["aSelector"],
  162. source: "setTestSelector: aSelector\x0a\x09testSelector := aSelector",
  163. messageSends: [],
  164. referencedClasses: []
  165. }),
  166. smalltalk.TestCase);
  167. smalltalk.addMethod(
  168. "_setUp",
  169. smalltalk.method({
  170. selector: "setUp",
  171. category: 'running',
  172. fn: function () {
  173. var self = this;
  174. return self;
  175. },
  176. args: [],
  177. source: "setUp",
  178. messageSends: [],
  179. referencedClasses: []
  180. }),
  181. smalltalk.TestCase);
  182. smalltalk.addMethod(
  183. "_should_",
  184. smalltalk.method({
  185. selector: "should:",
  186. category: 'testing',
  187. fn: function (aBlock) {
  188. var self = this;
  189. smalltalk.send(self, "_assert_", [smalltalk.send(aBlock, "_value", [])]);
  190. return self;
  191. },
  192. args: ["aBlock"],
  193. source: "should: aBlock\x0a\x09self assert: aBlock value",
  194. messageSends: ["assert:", "value"],
  195. referencedClasses: []
  196. }),
  197. smalltalk.TestCase);
  198. smalltalk.addMethod(
  199. "_should_raise_",
  200. smalltalk.method({
  201. selector: "should:raise:",
  202. category: 'testing',
  203. fn: function (aBlock, anExceptionClass) {
  204. var self = this;
  205. smalltalk.send(self, "_assert_", [smalltalk.send(function () {smalltalk.send(aBlock, "_value", []);return false;}, "_on_do_", [anExceptionClass, function (ex) {return true;}])]);
  206. return self;
  207. },
  208. args: ["aBlock", "anExceptionClass"],
  209. source: "should: aBlock raise: anExceptionClass\x0a\x09self assert: ([aBlock value. false] \x0a\x09\x09on: anExceptionClass \x0a\x09\x09do: [:ex | true])",
  210. messageSends: ["assert:", "on:do:", "value"],
  211. referencedClasses: []
  212. }),
  213. smalltalk.TestCase);
  214. smalltalk.addMethod(
  215. "_shouldnt_raise_",
  216. smalltalk.method({
  217. selector: "shouldnt:raise:",
  218. category: 'testing',
  219. fn: function (aBlock, anExceptionClass) {
  220. var self = this;
  221. smalltalk.send(self, "_assert_", [smalltalk.send(function () {smalltalk.send(aBlock, "_value", []);return true;}, "_on_do_", [anExceptionClass, function (ex) {return false;}])]);
  222. return self;
  223. },
  224. args: ["aBlock", "anExceptionClass"],
  225. source: "shouldnt: aBlock raise: anExceptionClass\x0a\x09self assert: ([aBlock value. true] \x0a\x09\x09on: anExceptionClass \x0a\x09\x09do: [:ex | false])",
  226. messageSends: ["assert:", "on:do:", "value"],
  227. referencedClasses: []
  228. }),
  229. smalltalk.TestCase);
  230. smalltalk.addMethod(
  231. "_signalFailure_",
  232. smalltalk.method({
  233. selector: "signalFailure:",
  234. category: 'private',
  235. fn: function (aString) {
  236. var self = this;
  237. var $1, $2;
  238. $1 = smalltalk.send(smalltalk.TestFailure || TestFailure, "_new", []);
  239. smalltalk.send($1, "_messageText_", [aString]);
  240. $2 = smalltalk.send($1, "_signal", []);
  241. return self;
  242. },
  243. args: ["aString"],
  244. source: "signalFailure: aString\x0a\x09TestFailure new\x0a\x09\x09messageText: aString;\x0a\x09\x09signal",
  245. messageSends: ["messageText:", "new", "signal"],
  246. referencedClasses: ["TestFailure"]
  247. }),
  248. smalltalk.TestCase);
  249. smalltalk.addMethod(
  250. "_startCase",
  251. smalltalk.method({
  252. selector: "startCase",
  253. category: 'running',
  254. fn: function (){
  255. var self=this;
  256. smalltalk.send(self,"_setUp",[]);
  257. smalltalk.send(self,"_performTest",[]);
  258. return self},
  259. args: [],
  260. source: "startCase\x0a\x09self setUp.\x0a\x09self performTest\x0a",
  261. messageSends: ["setUp", "performTest"],
  262. referencedClasses: []
  263. }),
  264. smalltalk.TestCase);
  265. smalltalk.addMethod(
  266. "_tearDown",
  267. smalltalk.method({
  268. selector: "tearDown",
  269. category: 'running',
  270. fn: function () {
  271. var self = this;
  272. return self;
  273. },
  274. args: [],
  275. source: "tearDown",
  276. messageSends: [],
  277. referencedClasses: []
  278. }),
  279. smalltalk.TestCase);
  280. smalltalk.addMethod(
  281. "_allTestSelectors",
  282. smalltalk.method({
  283. selector: "allTestSelectors",
  284. category: 'accessing',
  285. fn: function () {
  286. var self = this;
  287. var $1;
  288. var selectors;
  289. selectors = smalltalk.send(self, "_testSelectors", []);
  290. $1 = smalltalk.send(self, "_shouldInheritSelectors", []);
  291. if (smalltalk.assert($1)) {
  292. smalltalk.send(selectors, "_addAll_", [smalltalk.send(smalltalk.send(self, "_superclass", []), "_allTestSelectors", [])]);
  293. }
  294. return selectors;
  295. },
  296. args: [],
  297. source: "allTestSelectors\x0a\x09| selectors |\x0a\x09selectors := self testSelectors.\x0a\x09self shouldInheritSelectors ifTrue: [\x0a\x09\x09selectors addAll: self superclass allTestSelectors].\x0a\x09^selectors",
  298. messageSends: ["testSelectors", "ifTrue:", "addAll:", "allTestSelectors", "superclass", "shouldInheritSelectors"],
  299. referencedClasses: []
  300. }),
  301. smalltalk.TestCase.klass);
  302. smalltalk.addMethod(
  303. "_buildSuite",
  304. smalltalk.method({
  305. selector: "buildSuite",
  306. category: 'accessing',
  307. fn: function () {
  308. var self = this;
  309. var $1;
  310. $1 = smalltalk.send(smalltalk.send(self, "_allTestSelectors", []), "_collect_", [function (each) {return smalltalk.send(self, "_selector_", [each]);}]);
  311. return $1;
  312. },
  313. args: [],
  314. source: "buildSuite\x0a\x09^self allTestSelectors collect: [:each | self selector: each]",
  315. messageSends: ["collect:", "selector:", "allTestSelectors"],
  316. referencedClasses: []
  317. }),
  318. smalltalk.TestCase.klass);
  319. smalltalk.addMethod(
  320. "_isAbstract",
  321. smalltalk.method({
  322. selector: "isAbstract",
  323. category: 'testing',
  324. fn: function () {
  325. var self = this;
  326. var $1;
  327. $1 = smalltalk.send(smalltalk.send(self, "_name", []), "__eq", ["TestCase"]);
  328. return $1;
  329. },
  330. args: [],
  331. source: "isAbstract\x0a\x09^ self name = 'TestCase'",
  332. messageSends: ["=", "name"],
  333. referencedClasses: []
  334. }),
  335. smalltalk.TestCase.klass);
  336. smalltalk.addMethod(
  337. "_lookupHierarchyRoot",
  338. smalltalk.method({
  339. selector: "lookupHierarchyRoot",
  340. category: 'accessing',
  341. fn: function () {
  342. var self = this;
  343. return smalltalk.TestCase || TestCase;
  344. },
  345. args: [],
  346. source: "lookupHierarchyRoot\x0a\x09^TestCase",
  347. messageSends: [],
  348. referencedClasses: ["TestCase"]
  349. }),
  350. smalltalk.TestCase.klass);
  351. smalltalk.addMethod(
  352. "_selector_",
  353. smalltalk.method({
  354. selector: "selector:",
  355. category: 'accessing',
  356. fn: function (aSelector) {
  357. var self = this;
  358. var $2, $3, $1;
  359. $2 = smalltalk.send(self, "_new", []);
  360. smalltalk.send($2, "_setTestSelector_", [aSelector]);
  361. $3 = smalltalk.send($2, "_yourself", []);
  362. $1 = $3;
  363. return $1;
  364. },
  365. args: ["aSelector"],
  366. source: "selector: aSelector\x0a\x09^self new\x0a\x09\x09setTestSelector: aSelector;\x0a\x09\x09yourself",
  367. messageSends: ["setTestSelector:", "new", "yourself"],
  368. referencedClasses: []
  369. }),
  370. smalltalk.TestCase.klass);
  371. smalltalk.addMethod(
  372. "_shouldInheritSelectors",
  373. smalltalk.method({
  374. selector: "shouldInheritSelectors",
  375. category: 'testing',
  376. fn: function () {
  377. var self = this;
  378. var $1;
  379. $1 = smalltalk.send(self, "_~_eq", [smalltalk.send(self, "_lookupHierarchyRoot", [])]);
  380. return $1;
  381. },
  382. args: [],
  383. source: "shouldInheritSelectors\x0a\x09^self ~= self lookupHierarchyRoot",
  384. messageSends: ["~=", "lookupHierarchyRoot"],
  385. referencedClasses: []
  386. }),
  387. smalltalk.TestCase.klass);
  388. smalltalk.addMethod(
  389. "_testSelectors",
  390. smalltalk.method({
  391. selector: "testSelectors",
  392. category: 'accessing',
  393. fn: function () {
  394. var self = this;
  395. var $1;
  396. $1 = smalltalk.send(smalltalk.send(smalltalk.send(self, "_methodDictionary", []), "_keys", []), "_select_", [function (each) {return smalltalk.send(each, "_match_", ["^test"]);}]);
  397. return $1;
  398. },
  399. args: [],
  400. source: "testSelectors\x0a\x09^self methodDictionary keys select: [:each | each match: '^test']",
  401. messageSends: ["select:", "match:", "keys", "methodDictionary"],
  402. referencedClasses: []
  403. }),
  404. smalltalk.TestCase.klass);
  405. smalltalk.addClass('TestFailure', smalltalk.Error, [], 'SUnit');
  406. smalltalk.addClass('TestResult', smalltalk.Object, ['timestamp', 'runs', 'errors', 'failures', 'total'], 'SUnit');
  407. smalltalk.addMethod(
  408. "_addError_",
  409. smalltalk.method({
  410. selector: "addError:",
  411. category: 'accessing',
  412. fn: function (anError) {
  413. var self = this;
  414. smalltalk.send(smalltalk.send(self, "_errors", []), "_add_", [anError]);
  415. return self;
  416. },
  417. args: ["anError"],
  418. source: "addError: anError\x0a\x09self errors add: anError",
  419. messageSends: ["add:", "errors"],
  420. referencedClasses: []
  421. }),
  422. smalltalk.TestResult);
  423. smalltalk.addMethod(
  424. "_addFailure_",
  425. smalltalk.method({
  426. selector: "addFailure:",
  427. category: 'accessing',
  428. fn: function (aFailure) {
  429. var self = this;
  430. smalltalk.send(smalltalk.send(self, "_failures", []), "_add_", [aFailure]);
  431. return self;
  432. },
  433. args: ["aFailure"],
  434. source: "addFailure: aFailure\x0a\x09self failures add: aFailure",
  435. messageSends: ["add:", "failures"],
  436. referencedClasses: []
  437. }),
  438. smalltalk.TestResult);
  439. smalltalk.addMethod(
  440. "_errors",
  441. smalltalk.method({
  442. selector: "errors",
  443. category: 'accessing',
  444. fn: function () {
  445. var self = this;
  446. return self['@errors'];
  447. },
  448. args: [],
  449. source: "errors\x0a\x09^errors",
  450. messageSends: [],
  451. referencedClasses: []
  452. }),
  453. smalltalk.TestResult);
  454. smalltalk.addMethod(
  455. "_failures",
  456. smalltalk.method({
  457. selector: "failures",
  458. category: 'accessing',
  459. fn: function () {
  460. var self = this;
  461. return self['@failures'];
  462. },
  463. args: [],
  464. source: "failures\x0a\x09^failures",
  465. messageSends: [],
  466. referencedClasses: []
  467. }),
  468. smalltalk.TestResult);
  469. smalltalk.addMethod(
  470. "_increaseRuns",
  471. smalltalk.method({
  472. selector: "increaseRuns",
  473. category: 'accessing',
  474. fn: function () {
  475. var self = this;
  476. self['@runs'] = smalltalk.send(self['@runs'], "__plus", [1]);
  477. return self;
  478. },
  479. args: [],
  480. source: "increaseRuns\x0a\x09runs := runs + 1",
  481. messageSends: ["+"],
  482. referencedClasses: []
  483. }),
  484. smalltalk.TestResult);
  485. smalltalk.addMethod(
  486. "_initialize",
  487. smalltalk.method({
  488. selector: "initialize",
  489. category: 'initialization',
  490. fn: function () {
  491. var self = this;
  492. smalltalk.send(self, "_initialize", [], smalltalk.Object);
  493. self['@timestamp'] = smalltalk.send(smalltalk.Date || Date, "_now", []);
  494. self['@runs'] = 0;
  495. self['@errors'] = smalltalk.send(smalltalk.Array || Array, "_new", []);
  496. self['@failures'] = smalltalk.send(smalltalk.Array || Array, "_new", []);
  497. self['@total'] = 0;
  498. return self;
  499. },
  500. args: [],
  501. source: "initialize\x0a\x09super initialize.\x0a\x09timestamp := Date now.\x0a\x09runs := 0.\x0a\x09errors := Array new.\x0a\x09failures := Array new.\x0a\x09total := 0",
  502. messageSends: ["initialize", "now", "new"],
  503. referencedClasses: ["Date", "Array"]
  504. }),
  505. smalltalk.TestResult);
  506. smalltalk.addMethod(
  507. "_nextRunDo_",
  508. smalltalk.method({
  509. selector: "nextRunDo:",
  510. category: 'running',
  511. fn: function (aBlock){
  512. var self=this;
  513. var $2,$1;
  514. $2=smalltalk.send(smalltalk.send(self,"_runs",[]),"__eq_eq",[smalltalk.send(self,"_total",[])]);
  515. if(! smalltalk.assert($2)){
  516. $1=smalltalk.send(aBlock,"_value_",[smalltalk.send(smalltalk.send(self,"_runs",[]),"__plus",[(1)])]);
  517. };
  518. return $1;
  519. },
  520. args: ["aBlock"],
  521. source: "nextRunDo: aBlock\x0a\x22Runs aBlock with index of next run\x0aor does nothing if no more runs\x22\x0a^self runs == self total\x0a\x09ifFalse: [ aBlock value: self runs + 1 ]",
  522. messageSends: ["ifFalse:", "value:", "+", "runs", "==", "total"],
  523. referencedClasses: []
  524. }),
  525. smalltalk.TestResult);
  526. smalltalk.addMethod(
  527. "_runCase_",
  528. smalltalk.method({
  529. selector: "runCase:",
  530. category: 'running',
  531. fn: function (aTestCase){
  532. var self=this;
  533. smalltalk.send((function(){
  534. return smalltalk.send((function(){
  535. return smalltalk.send((function(){
  536. smalltalk.send(self,"_increaseRuns",[]);
  537. return smalltalk.send(aTestCase,"_startCase",[]);
  538. }),"_ensure_",[(function(){
  539. return smalltalk.send(aTestCase,"_tearDown",[]);
  540. })]);
  541. }),"_on_do_",[(smalltalk.TestFailure || TestFailure),(function(ex){
  542. return smalltalk.send(self,"_addFailure_",[aTestCase]);
  543. })]);
  544. }),"_on_do_",[(smalltalk.Error || Error),(function(ex){
  545. return smalltalk.send(self,"_addError_",[aTestCase]);
  546. })]);
  547. return self},
  548. args: ["aTestCase"],
  549. source: "runCase: aTestCase\x0a\x09[[[\x09self increaseRuns.\x0a \x09aTestCase startCase ] ensure: [ aTestCase tearDown ]]\x0a\x09on: TestFailure do: [:ex | self addFailure: aTestCase]]\x0a\x09on: Error do: [:ex | self addError: aTestCase]\x0a",
  550. messageSends: ["on:do:", "addError:", "addFailure:", "ensure:", "tearDown", "increaseRuns", "startCase"],
  551. referencedClasses: ["Error", "TestFailure"]
  552. }),
  553. smalltalk.TestResult);
  554. smalltalk.addMethod(
  555. "_runs",
  556. smalltalk.method({
  557. selector: "runs",
  558. category: 'accessing',
  559. fn: function () {
  560. var self = this;
  561. return self['@runs'];
  562. },
  563. args: [],
  564. source: "runs\x0a\x09^runs",
  565. messageSends: [],
  566. referencedClasses: []
  567. }),
  568. smalltalk.TestResult);
  569. smalltalk.addMethod(
  570. "_status",
  571. smalltalk.method({
  572. selector: "status",
  573. category: 'accessing',
  574. fn: function () {
  575. var self = this;
  576. var $2, $3, $1;
  577. $2 = smalltalk.send(smalltalk.send(self, "_errors", []), "_isEmpty", []);
  578. if (smalltalk.assert($2)) {
  579. $3 = smalltalk.send(smalltalk.send(self, "_failures", []), "_isEmpty", []);
  580. if (smalltalk.assert($3)) {
  581. $1 = "success";
  582. } else {
  583. $1 = "failure";
  584. }
  585. } else {
  586. $1 = "error";
  587. }
  588. return $1;
  589. },
  590. args: [],
  591. source: "status\x0a\x09^self errors isEmpty \x0a\x09\x09ifTrue: [\x0a\x09\x09\x09self failures isEmpty \x0a\x09\x09\x09\x09ifTrue: ['success']\x0a\x09\x09\x09\x09ifFalse: ['failure']]\x0a\x09\x09ifFalse: ['error']",
  592. messageSends: ["ifTrue:ifFalse:", "isEmpty", "failures", "errors"],
  593. referencedClasses: []
  594. }),
  595. smalltalk.TestResult);
  596. smalltalk.addMethod(
  597. "_timestamp",
  598. smalltalk.method({
  599. selector: "timestamp",
  600. category: 'accessing',
  601. fn: function () {
  602. var self = this;
  603. return self['@timestamp'];
  604. },
  605. args: [],
  606. source: "timestamp\x0a\x09^timestamp",
  607. messageSends: [],
  608. referencedClasses: []
  609. }),
  610. smalltalk.TestResult);
  611. smalltalk.addMethod(
  612. "_total",
  613. smalltalk.method({
  614. selector: "total",
  615. category: 'accessing',
  616. fn: function () {
  617. var self = this;
  618. return self['@total'];
  619. },
  620. args: [],
  621. source: "total\x0a\x09^total",
  622. messageSends: [],
  623. referencedClasses: []
  624. }),
  625. smalltalk.TestResult);
  626. smalltalk.addMethod(
  627. "_total_",
  628. smalltalk.method({
  629. selector: "total:",
  630. category: 'accessing',
  631. fn: function (aNumber) {
  632. var self = this;
  633. self['@total'] = aNumber;
  634. return self;
  635. },
  636. args: ["aNumber"],
  637. source: "total: aNumber\x0a\x09total := aNumber",
  638. messageSends: [],
  639. referencedClasses: []
  640. }),
  641. smalltalk.TestResult);
  642. smalltalk.addClass('TestSuiteRunner', smalltalk.Object, ['suite', 'result', 'announcer', 'worker'], 'SUnit');
  643. smalltalk.addMethod(
  644. "_announcer",
  645. smalltalk.method({
  646. selector: "announcer",
  647. category: 'accessing',
  648. fn: function (){
  649. var self=this;
  650. return self["@announcer"];
  651. },
  652. args: [],
  653. source: "announcer\x0a\x09^announcer",
  654. messageSends: [],
  655. referencedClasses: []
  656. }),
  657. smalltalk.TestSuiteRunner);
  658. smalltalk.addMethod(
  659. "_initialize",
  660. smalltalk.method({
  661. selector: "initialize",
  662. category: 'initialization',
  663. fn: function (){
  664. var self=this;
  665. smalltalk.send(self,"_initialize",[],smalltalk.Object);
  666. self["@announcer"]=smalltalk.send((smalltalk.Announcer || Announcer),"_new",[]);
  667. self["@result"]=smalltalk.send((smalltalk.TestResult || TestResult),"_new",[]);
  668. self["@worker"]=(function(){
  669. return smalltalk.send(self["@result"],"_nextRunDo_",[(function(index){
  670. return smalltalk.send((function(){
  671. return smalltalk.send(self["@result"],"_runCase_",[smalltalk.send(self["@suite"],"_at_",[index])]);
  672. }),"_ensure_",[(function(){
  673. return smalltalk.send(self,"_resume",[]);
  674. })]);
  675. })]);
  676. });
  677. return self},
  678. args: [],
  679. source: "initialize\x0a\x09super initialize.\x0a\x09announcer := Announcer new.\x0a result := TestResult new.\x0a worker := [ result nextRunDo: [ :index |\x0a\x09\x09[ result runCase: (suite at: index) ]\x0a\x09\x09ensure: [ self resume ]]].\x0a",
  680. messageSends: ["initialize", "new", "nextRunDo:", "ensure:", "resume", "runCase:", "at:"],
  681. referencedClasses: ["Announcer", "TestResult"]
  682. }),
  683. smalltalk.TestSuiteRunner);
  684. smalltalk.addMethod(
  685. "_result",
  686. smalltalk.method({
  687. selector: "result",
  688. category: 'accessing',
  689. fn: function (){
  690. var self=this;
  691. return self["@result"];
  692. },
  693. args: [],
  694. source: "result\x0a\x09^result",
  695. messageSends: [],
  696. referencedClasses: []
  697. }),
  698. smalltalk.TestSuiteRunner);
  699. smalltalk.addMethod(
  700. "_resume",
  701. smalltalk.method({
  702. selector: "resume",
  703. category: 'actions',
  704. fn: function (){
  705. var self=this;
  706. smalltalk.send(self["@worker"],"_fork",[]);
  707. smalltalk.send(self["@announcer"],"_announce_",[smalltalk.send(smalltalk.send((smalltalk.ResultAnnouncement || ResultAnnouncement),"_new",[]),"_result_",[self["@result"]])]);
  708. return self},
  709. args: [],
  710. source: "resume\x0a\x09worker fork.\x0a announcer announce: (ResultAnnouncement new result: result)\x0a",
  711. messageSends: ["fork", "announce:", "result:", "new"],
  712. referencedClasses: ["ResultAnnouncement"]
  713. }),
  714. smalltalk.TestSuiteRunner);
  715. smalltalk.addMethod(
  716. "_run",
  717. smalltalk.method({
  718. selector: "run",
  719. category: 'actions',
  720. fn: function (){
  721. var self=this;
  722. smalltalk.send(self["@result"],"_total_",[smalltalk.send(self["@suite"],"_size",[])]);
  723. smalltalk.send(self,"_resume",[]);
  724. return self},
  725. args: [],
  726. source: "run\x0a\x09result total: suite size.\x0a\x09self resume",
  727. messageSends: ["total:", "size", "resume"],
  728. referencedClasses: []
  729. }),
  730. smalltalk.TestSuiteRunner);
  731. smalltalk.addMethod(
  732. "_suite_",
  733. smalltalk.method({
  734. selector: "suite:",
  735. category: 'accessing',
  736. fn: function (aCollection){
  737. var self=this;
  738. self["@suite"]=aCollection;
  739. return self},
  740. args: ["aCollection"],
  741. source: "suite: aCollection\x0a\x09suite := aCollection",
  742. messageSends: [],
  743. referencedClasses: []
  744. }),
  745. smalltalk.TestSuiteRunner);
  746. smalltalk.addMethod(
  747. "_new",
  748. smalltalk.method({
  749. selector: "new",
  750. category: 'instance creation',
  751. fn: function (){
  752. var self=this;
  753. smalltalk.send(self,"_shouldNotImplement",[]);
  754. return self},
  755. args: [],
  756. source: "new\x0a\x09self shouldNotImplement",
  757. messageSends: ["shouldNotImplement"],
  758. referencedClasses: []
  759. }),
  760. smalltalk.TestSuiteRunner.klass);
  761. smalltalk.addMethod(
  762. "_on_",
  763. smalltalk.method({
  764. selector: "on:",
  765. category: 'instance creation',
  766. fn: function (aCollection){
  767. var self=this;
  768. var $1;
  769. $1=smalltalk.send(smalltalk.send(self,"_new",[],smalltalk.Object.klass),"_suite_",[aCollection]);
  770. return $1;
  771. },
  772. args: ["aCollection"],
  773. source: "on: aCollection\x0a\x09^super new suite: aCollection",
  774. messageSends: ["suite:", "new"],
  775. referencedClasses: []
  776. }),
  777. smalltalk.TestSuiteRunner.klass);