1
0

SUnit.js 30 KB

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