1
0

SUnit.js 17 KB

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