2
0

SUnit.js 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533
  1. smalltalk.addPackage('SUnit', {});
  2. smalltalk.addClass('TestCase', smalltalk.Object, ['testSelector'], 'SUnit');
  3. smalltalk.addMethod(
  4. "_assert_",
  5. smalltalk.method({
  6. selector: "assert:",
  7. category: 'testing',
  8. fn: function (aBoolean) {
  9. var self=this;
  10. smalltalk.send(self, "_assert_description_", [aBoolean, "Assertion failed"]);
  11. return self;},
  12. args: ["aBoolean"],
  13. source: "assert: aBoolean\x0a\x09self assert: aBoolean description: 'Assertion failed'",
  14. messageSends: ["assert:description:"],
  15. referencedClasses: []
  16. }),
  17. smalltalk.TestCase);
  18. smalltalk.addMethod(
  19. "_assert_description_",
  20. smalltalk.method({
  21. selector: "assert:description:",
  22. category: 'testing',
  23. fn: function (aBoolean, aString) {
  24. var self=this;
  25. ((($receiver = aBoolean).klass === smalltalk.Boolean) ? (! $receiver ? (function(){return smalltalk.send(self, "_signalFailure_", [aString]);})() : nil) : smalltalk.send($receiver, "_ifFalse_", [(function(){return smalltalk.send(self, "_signalFailure_", [aString]);})]));
  26. return self;},
  27. args: ["aBoolean", "aString"],
  28. source: "assert: aBoolean description: aString\x0a\x09aBoolean ifFalse: [self signalFailure: aString]",
  29. messageSends: ["ifFalse:", "signalFailure:"],
  30. referencedClasses: []
  31. }),
  32. smalltalk.TestCase);
  33. smalltalk.addMethod(
  34. "_assert_equals_",
  35. smalltalk.method({
  36. selector: "assert:equals:",
  37. category: 'testing',
  38. fn: function (expected, actual) {
  39. var self=this;
  40. return 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", [])])]);
  41. return self;},
  42. args: ["expected", "actual"],
  43. source: "assert: expected equals: actual\x0a\x09^ self assert: (expected = actual) description: 'Expected: ', expected asString, ' but was: ', actual asString",
  44. messageSends: ["assert:description:", "=", ",", "asString"],
  45. referencedClasses: []
  46. }),
  47. smalltalk.TestCase);
  48. smalltalk.addMethod(
  49. "_deny_",
  50. smalltalk.method({
  51. selector: "deny:",
  52. category: 'testing',
  53. fn: function (aBoolean) {
  54. var self=this;
  55. smalltalk.send(self, "_assert_", [smalltalk.send(aBoolean, "_not", [])]);
  56. return self;},
  57. args: ["aBoolean"],
  58. source: "deny: aBoolean\x0a\x09self assert: aBoolean not",
  59. messageSends: ["assert:", "not"],
  60. referencedClasses: []
  61. }),
  62. smalltalk.TestCase);
  63. smalltalk.addMethod(
  64. "_performTestFor_",
  65. smalltalk.method({
  66. selector: "performTestFor:",
  67. category: 'running',
  68. fn: function (aResult) {
  69. var self=this;
  70. smalltalk.send((function(){return smalltalk.send((function(){return smalltalk.send(self, "_perform_", [smalltalk.send(self, "_selector", [])]);}), "_on_do_", [(smalltalk.TestFailure || TestFailure), (function(ex){return smalltalk.send(aResult, "_addFailure_", [self]);})]);}), "_on_do_", [(smalltalk.Error || Error), (function(ex){return smalltalk.send(aResult, "_addError_", [self]);})]);
  71. return self;},
  72. args: ["aResult"],
  73. source: "performTestFor: aResult\x0a\x09[[self perform: self selector]\x0a\x09\x09on: TestFailure do: [:ex | aResult addFailure: self]]\x0a\x09\x09on: Error do: [:ex | aResult addError: self]",
  74. messageSends: ["on:do:", "perform:", "selector", "addFailure:", "addError:"],
  75. referencedClasses: ["TestFailure", "Error"]
  76. }),
  77. smalltalk.TestCase);
  78. smalltalk.addMethod(
  79. "_runCaseFor_",
  80. smalltalk.method({
  81. selector: "runCaseFor:",
  82. category: 'running',
  83. fn: function (aTestResult) {
  84. var self=this;
  85. smalltalk.send(self, "_setUp", []);
  86. smalltalk.send(aTestResult, "_increaseRuns", []);
  87. smalltalk.send(self, "_performTestFor_", [aTestResult]);
  88. smalltalk.send(self, "_tearDown", []);
  89. return self;},
  90. args: ["aTestResult"],
  91. source: "runCaseFor: aTestResult\x0a\x09self setUp.\x0a\x09aTestResult increaseRuns.\x0a\x09self performTestFor: aTestResult.\x0a\x09self tearDown",
  92. messageSends: ["setUp", "increaseRuns", "performTestFor:", "tearDown"],
  93. referencedClasses: []
  94. }),
  95. smalltalk.TestCase);
  96. smalltalk.addMethod(
  97. "_selector",
  98. smalltalk.method({
  99. selector: "selector",
  100. category: 'accessing',
  101. fn: function () {
  102. var self=this;
  103. return self['@testSelector'];
  104. return self;},
  105. args: [],
  106. source: "selector\x0a\x09^testSelector",
  107. messageSends: [],
  108. referencedClasses: []
  109. }),
  110. smalltalk.TestCase);
  111. smalltalk.addMethod(
  112. "_setTestSelector_",
  113. smalltalk.method({
  114. selector: "setTestSelector:",
  115. category: 'accessing',
  116. fn: function (aSelector) {
  117. var self=this;
  118. (self['@testSelector']=aSelector);
  119. return self;},
  120. args: ["aSelector"],
  121. source: "setTestSelector: aSelector\x0a\x09testSelector := aSelector",
  122. messageSends: [],
  123. referencedClasses: []
  124. }),
  125. smalltalk.TestCase);
  126. smalltalk.addMethod(
  127. "_setUp",
  128. smalltalk.method({
  129. selector: "setUp",
  130. category: 'running',
  131. fn: function () {
  132. var self=this;
  133. return self;},
  134. args: [],
  135. source: "setUp",
  136. messageSends: [],
  137. referencedClasses: []
  138. }),
  139. smalltalk.TestCase);
  140. smalltalk.addMethod(
  141. "_should_",
  142. smalltalk.method({
  143. selector: "should:",
  144. category: 'testing',
  145. fn: function (aBlock) {
  146. var self=this;
  147. smalltalk.send(self, "_assert_", [smalltalk.send(aBlock, "_value", [])]);
  148. return self;},
  149. args: ["aBlock"],
  150. source: "should: aBlock\x0a\x09self assert: aBlock value",
  151. messageSends: ["assert:", "value"],
  152. referencedClasses: []
  153. }),
  154. smalltalk.TestCase);
  155. smalltalk.addMethod(
  156. "_should_raise_",
  157. smalltalk.method({
  158. selector: "should:raise:",
  159. category: 'testing',
  160. fn: function (aBlock, anExceptionClass) {
  161. var self=this;
  162. smalltalk.send(self, "_assert_", [smalltalk.send((function(){smalltalk.send(aBlock, "_value", []);return false;}), "_on_do_", [anExceptionClass, (function(ex){return true;})])]);
  163. return self;},
  164. args: ["aBlock", "anExceptionClass"],
  165. source: "should: aBlock raise: anExceptionClass\x0a\x09self assert: ([aBlock value. false] \x0a\x09\x09on: anExceptionClass \x0a\x09\x09do: [:ex | true])",
  166. messageSends: ["assert:", "on:do:", "value"],
  167. referencedClasses: []
  168. }),
  169. smalltalk.TestCase);
  170. smalltalk.addMethod(
  171. "_shouldnt_raise_",
  172. smalltalk.method({
  173. selector: "shouldnt:raise:",
  174. category: 'testing',
  175. fn: function (aBlock, anExceptionClass) {
  176. var self=this;
  177. smalltalk.send(self, "_assert_", [smalltalk.send((function(){smalltalk.send(aBlock, "_value", []);return true;}), "_on_do_", [anExceptionClass, (function(ex){return false;})])]);
  178. return self;},
  179. args: ["aBlock", "anExceptionClass"],
  180. source: "shouldnt: aBlock raise: anExceptionClass\x0a\x09self assert: ([aBlock value. true] \x0a\x09\x09on: anExceptionClass \x0a\x09\x09do: [:ex | false])",
  181. messageSends: ["assert:", "on:do:", "value"],
  182. referencedClasses: []
  183. }),
  184. smalltalk.TestCase);
  185. smalltalk.addMethod(
  186. "_signalFailure_",
  187. smalltalk.method({
  188. selector: "signalFailure:",
  189. category: 'private',
  190. fn: function (aString) {
  191. var self=this;
  192. (function($rec){smalltalk.send($rec, "_messageText_", [aString]);return smalltalk.send($rec, "_signal", []);})(smalltalk.send((smalltalk.TestFailure || TestFailure), "_new", []));
  193. return self;},
  194. args: ["aString"],
  195. source: "signalFailure: aString\x0a\x09TestFailure new\x0a\x09\x09messageText: aString;\x0a\x09\x09signal",
  196. messageSends: ["messageText:", "signal", "new"],
  197. referencedClasses: ["TestFailure"]
  198. }),
  199. smalltalk.TestCase);
  200. smalltalk.addMethod(
  201. "_tearDown",
  202. smalltalk.method({
  203. selector: "tearDown",
  204. category: 'running',
  205. fn: function () {
  206. var self=this;
  207. return self;},
  208. args: [],
  209. source: "tearDown",
  210. messageSends: [],
  211. referencedClasses: []
  212. }),
  213. smalltalk.TestCase);
  214. smalltalk.addMethod(
  215. "_allTestSelectors",
  216. smalltalk.method({
  217. selector: "allTestSelectors",
  218. category: 'accessing',
  219. fn: function () {
  220. var self=this;
  221. var selectors=nil;
  222. (selectors=smalltalk.send(self, "_testSelectors", []));
  223. ((($receiver = smalltalk.send(self, "_shouldInheritSelectors", [])).klass === smalltalk.Boolean) ? ($receiver ? (function(){return smalltalk.send(selectors, "_addAll_", [smalltalk.send(smalltalk.send(self, "_superclass", []), "_allTestSelectors", [])]);})() : nil) : smalltalk.send($receiver, "_ifTrue_", [(function(){return smalltalk.send(selectors, "_addAll_", [smalltalk.send(smalltalk.send(self, "_superclass", []), "_allTestSelectors", [])]);})]));
  224. return selectors;
  225. return self;},
  226. args: [],
  227. source: "allTestSelectors\x0a\x09| selectors |\x0a\x09selectors := self testSelectors.\x0a\x09self shouldInheritSelectors ifTrue: [\x0a\x09\x09selectors addAll: self superclass allTestSelectors].\x0a\x09^selectors",
  228. messageSends: ["testSelectors", "ifTrue:", "shouldInheritSelectors", "addAll:", "allTestSelectors", "superclass"],
  229. referencedClasses: []
  230. }),
  231. smalltalk.TestCase.klass);
  232. smalltalk.addMethod(
  233. "_buildSuite",
  234. smalltalk.method({
  235. selector: "buildSuite",
  236. category: 'accessing',
  237. fn: function () {
  238. var self=this;
  239. return smalltalk.send(smalltalk.send(self, "_allTestSelectors", []), "_collect_", [(function(each){return smalltalk.send(self, "_selector_", [each]);})]);
  240. return self;},
  241. args: [],
  242. source: "buildSuite\x0a\x09^self allTestSelectors collect: [:each | self selector: each]",
  243. messageSends: ["collect:", "allTestSelectors", "selector:"],
  244. referencedClasses: []
  245. }),
  246. smalltalk.TestCase.klass);
  247. smalltalk.addMethod(
  248. "_isAbstract",
  249. smalltalk.method({
  250. selector: "isAbstract",
  251. category: 'testing',
  252. fn: function () {
  253. var self=this;
  254. return smalltalk.send(smalltalk.send(self, "_name", []), "__eq", ["TestCase"]);
  255. return self;},
  256. args: [],
  257. source: "isAbstract\x0a\x09^ self name = 'TestCase'",
  258. messageSends: ["=", "name"],
  259. referencedClasses: []
  260. }),
  261. smalltalk.TestCase.klass);
  262. smalltalk.addMethod(
  263. "_lookupHierarchyRoot",
  264. smalltalk.method({
  265. selector: "lookupHierarchyRoot",
  266. category: 'accessing',
  267. fn: function () {
  268. var self=this;
  269. return (smalltalk.TestCase || TestCase);
  270. return self;},
  271. args: [],
  272. source: "lookupHierarchyRoot\x0a\x09^TestCase",
  273. messageSends: [],
  274. referencedClasses: ["TestCase"]
  275. }),
  276. smalltalk.TestCase.klass);
  277. smalltalk.addMethod(
  278. "_selector_",
  279. smalltalk.method({
  280. selector: "selector:",
  281. category: 'accessing',
  282. fn: function (aSelector) {
  283. var self=this;
  284. return (function($rec){smalltalk.send($rec, "_setTestSelector_", [aSelector]);return smalltalk.send($rec, "_yourself", []);})(smalltalk.send(self, "_new", []));
  285. return self;},
  286. args: ["aSelector"],
  287. source: "selector: aSelector\x0a\x09^self new\x0a\x09\x09setTestSelector: aSelector;\x0a\x09\x09yourself",
  288. messageSends: ["setTestSelector:", "yourself", "new"],
  289. referencedClasses: []
  290. }),
  291. smalltalk.TestCase.klass);
  292. smalltalk.addMethod(
  293. "_shouldInheritSelectors",
  294. smalltalk.method({
  295. selector: "shouldInheritSelectors",
  296. category: 'testing',
  297. fn: function () {
  298. var self=this;
  299. return smalltalk.send(self, "_~_eq", [smalltalk.send(self, "_lookupHierarchyRoot", [])]);
  300. return self;},
  301. args: [],
  302. source: "shouldInheritSelectors\x0a\x09^self ~= self lookupHierarchyRoot",
  303. messageSends: ["~=", "lookupHierarchyRoot"],
  304. referencedClasses: []
  305. }),
  306. smalltalk.TestCase.klass);
  307. smalltalk.addMethod(
  308. "_testSelectors",
  309. smalltalk.method({
  310. selector: "testSelectors",
  311. category: 'accessing',
  312. fn: function () {
  313. var self=this;
  314. return smalltalk.send(smalltalk.send(smalltalk.send(self, "_methodDictionary", []), "_keys", []), "_select_", [(function(each){return smalltalk.send(each, "_match_", ["^test"]);})]);
  315. return self;},
  316. args: [],
  317. source: "testSelectors\x0a\x09^self methodDictionary keys select: [:each | each match: '^test']",
  318. messageSends: ["select:", "keys", "methodDictionary", "match:"],
  319. referencedClasses: []
  320. }),
  321. smalltalk.TestCase.klass);
  322. smalltalk.addClass('TestFailure', smalltalk.Error, [], 'SUnit');
  323. smalltalk.addClass('TestResult', smalltalk.Object, ['timestamp', 'runs', 'errors', 'failures', 'total'], 'SUnit');
  324. smalltalk.addMethod(
  325. "_addError_",
  326. smalltalk.method({
  327. selector: "addError:",
  328. category: 'accessing',
  329. fn: function (anError) {
  330. var self=this;
  331. smalltalk.send(smalltalk.send(self, "_errors", []), "_add_", [anError]);
  332. return self;},
  333. args: ["anError"],
  334. source: "addError: anError\x0a\x09self errors add: anError",
  335. messageSends: ["add:", "errors"],
  336. referencedClasses: []
  337. }),
  338. smalltalk.TestResult);
  339. smalltalk.addMethod(
  340. "_addFailure_",
  341. smalltalk.method({
  342. selector: "addFailure:",
  343. category: 'accessing',
  344. fn: function (aFailure) {
  345. var self=this;
  346. smalltalk.send(smalltalk.send(self, "_failures", []), "_add_", [aFailure]);
  347. return self;},
  348. args: ["aFailure"],
  349. source: "addFailure: aFailure\x0a\x09self failures add: aFailure",
  350. messageSends: ["add:", "failures"],
  351. referencedClasses: []
  352. }),
  353. smalltalk.TestResult);
  354. smalltalk.addMethod(
  355. "_errors",
  356. smalltalk.method({
  357. selector: "errors",
  358. category: 'accessing',
  359. fn: function () {
  360. var self=this;
  361. return self['@errors'];
  362. return self;},
  363. args: [],
  364. source: "errors\x0a\x09^errors",
  365. messageSends: [],
  366. referencedClasses: []
  367. }),
  368. smalltalk.TestResult);
  369. smalltalk.addMethod(
  370. "_failures",
  371. smalltalk.method({
  372. selector: "failures",
  373. category: 'accessing',
  374. fn: function () {
  375. var self=this;
  376. return self['@failures'];
  377. return self;},
  378. args: [],
  379. source: "failures\x0a\x09^failures",
  380. messageSends: [],
  381. referencedClasses: []
  382. }),
  383. smalltalk.TestResult);
  384. smalltalk.addMethod(
  385. "_increaseRuns",
  386. smalltalk.method({
  387. selector: "increaseRuns",
  388. category: 'accessing',
  389. fn: function () {
  390. var self=this;
  391. (self['@runs']=((($receiver = self['@runs']).klass === smalltalk.Number) ? $receiver +(1) : smalltalk.send($receiver, "__plus", [(1)])));
  392. return self;},
  393. args: [],
  394. source: "increaseRuns\x0a\x09runs := runs + 1",
  395. messageSends: ["+"],
  396. referencedClasses: []
  397. }),
  398. smalltalk.TestResult);
  399. smalltalk.addMethod(
  400. "_initialize",
  401. smalltalk.method({
  402. selector: "initialize",
  403. category: 'initialization',
  404. fn: function () {
  405. var self=this;
  406. smalltalk.send(self, "_initialize", [], smalltalk.TestResult.superclass || nil);
  407. (self['@timestamp']=smalltalk.send((smalltalk.Date || Date), "_now", []));
  408. (self['@runs']=(0));
  409. (self['@errors']=smalltalk.send((smalltalk.Array || Array), "_new", []));
  410. (self['@failures']=smalltalk.send((smalltalk.Array || Array), "_new", []));
  411. (self['@total']=(0));
  412. return self;},
  413. args: [],
  414. source: "initialize\x0a\x09super initialize.\x0a\x09timestamp := Date now.\x0a\x09runs := 0.\x0a\x09errors := Array new.\x0a\x09failures := Array new.\x0a\x09total := 0",
  415. messageSends: ["initialize", "now", "new"],
  416. referencedClasses: ["Date", "Array"]
  417. }),
  418. smalltalk.TestResult);
  419. smalltalk.addMethod(
  420. "_runs",
  421. smalltalk.method({
  422. selector: "runs",
  423. category: 'accessing',
  424. fn: function () {
  425. var self=this;
  426. return self['@runs'];
  427. return self;},
  428. args: [],
  429. source: "runs\x0a\x09^runs",
  430. messageSends: [],
  431. referencedClasses: []
  432. }),
  433. smalltalk.TestResult);
  434. smalltalk.addMethod(
  435. "_status",
  436. smalltalk.method({
  437. selector: "status",
  438. category: 'accessing',
  439. fn: function () {
  440. var self=this;
  441. return ((($receiver = smalltalk.send(smalltalk.send(self, "_errors", []), "_isEmpty", [])).klass === smalltalk.Boolean) ? ($receiver ? (function(){return ((($receiver = smalltalk.send(smalltalk.send(self, "_failures", []), "_isEmpty", [])).klass === smalltalk.Boolean) ? ($receiver ? (function(){return "success";})() : (function(){return "failure";})()) : smalltalk.send($receiver, "_ifTrue_ifFalse_", [(function(){return "success";}), (function(){return "failure";})]));})() : (function(){return "error";})()) : smalltalk.send($receiver, "_ifTrue_ifFalse_", [(function(){return ((($receiver = smalltalk.send(smalltalk.send(self, "_failures", []), "_isEmpty", [])).klass === smalltalk.Boolean) ? ($receiver ? (function(){return "success";})() : (function(){return "failure";})()) : smalltalk.send($receiver, "_ifTrue_ifFalse_", [(function(){return "success";}), (function(){return "failure";})]));}), (function(){return "error";})]));
  442. return self;},
  443. args: [],
  444. 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']",
  445. messageSends: ["ifTrue:ifFalse:", "isEmpty", "errors", "failures"],
  446. referencedClasses: []
  447. }),
  448. smalltalk.TestResult);
  449. smalltalk.addMethod(
  450. "_timestamp",
  451. smalltalk.method({
  452. selector: "timestamp",
  453. category: 'accessing',
  454. fn: function () {
  455. var self=this;
  456. return self['@timestamp'];
  457. return self;},
  458. args: [],
  459. source: "timestamp\x0a\x09^timestamp",
  460. messageSends: [],
  461. referencedClasses: []
  462. }),
  463. smalltalk.TestResult);
  464. smalltalk.addMethod(
  465. "_total",
  466. smalltalk.method({
  467. selector: "total",
  468. category: 'accessing',
  469. fn: function () {
  470. var self=this;
  471. return self['@total'];
  472. return self;},
  473. args: [],
  474. source: "total\x0a\x09^total",
  475. messageSends: [],
  476. referencedClasses: []
  477. }),
  478. smalltalk.TestResult);
  479. smalltalk.addMethod(
  480. "_total_",
  481. smalltalk.method({
  482. selector: "total:",
  483. category: 'accessing',
  484. fn: function (aNumber) {
  485. var self=this;
  486. (self['@total']=aNumber);
  487. return self;},
  488. args: ["aNumber"],
  489. source: "total: aNumber\x0a\x09total := aNumber",
  490. messageSends: [],
  491. referencedClasses: []
  492. }),
  493. smalltalk.TestResult);