2
0

SUnit.js 17 KB

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