SUnit.js 27 KB

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