SUnit.js 24 KB

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