1
0

SUnit.js 28 KB

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