SUnit.js 30 KB

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