SUnit.js 28 KB

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