SUnit.js 29 KB

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