2
0

SUnit.js 30 KB

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