SUnit.js 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376
  1. smalltalk.addClass('TestCase', smalltalk.Object, ['testedClass'], 'SUnit');
  2. smalltalk.addMethod(
  3. '_testedClass',
  4. smalltalk.method({
  5. selector: 'testedClass',
  6. category: 'accessing',
  7. fn: function (){
  8. var self=this;
  9. return self['@testedClass'];
  10. return self;},
  11. source: unescape('testedClass%0A%09%5EtestedClass'),
  12. messageSends: [],
  13. referencedClasses: []
  14. }),
  15. smalltalk.TestCase);
  16. smalltalk.addMethod(
  17. '_testedClass_',
  18. smalltalk.method({
  19. selector: 'testedClass:',
  20. category: 'accessing',
  21. fn: function (aClass){
  22. var self=this;
  23. self['@testedClass']=aClass;
  24. return self;},
  25. source: unescape('testedClass%3A%20aClass%0A%09testedClass%20%3A%3D%20aClass'),
  26. messageSends: [],
  27. referencedClasses: []
  28. }),
  29. smalltalk.TestCase);
  30. smalltalk.addMethod(
  31. '_cleanUpInstanceVariables',
  32. smalltalk.method({
  33. selector: 'cleanUpInstanceVariables',
  34. category: 'private',
  35. fn: function (){
  36. var self=this;
  37. smalltalk.send(smalltalk.send(smalltalk.send(self, "_class", []), "_instanceVariableNames", []), "_do_", [(function(name){return (($receiver = smalltalk.send(name, "__eq", ["testSelector"])).klass === smalltalk.Boolean) ? (! $receiver ? (function(){return smalltalk.send(self, "_instVarAt_put_", [name, nil]);})() : nil) : smalltalk.send($receiver, "_ifFalse_", [(function(){return smalltalk.send(self, "_instVarAt_put_", [name, nil]);})]);})]);
  38. return self;},
  39. source: unescape('cleanUpInstanceVariables%0A%09self%20class%20instanceVariableNames%20do%3A%20%5B%20%3Aname%20%7C%0A%09%09name%20%3D%20%27testSelector%27%20ifFalse%3A%20%5B%0A%09%09%09self%20instVarAt%3A%20name%20put%3A%20nil%20%5D%5D'),
  40. messageSends: ["do:", "instanceVariableNames", "class", "ifFalse:", unescape("%3D"), "instVarAt:put:"],
  41. referencedClasses: []
  42. }),
  43. smalltalk.TestCase);
  44. smalltalk.addMethod(
  45. '_signalFailure_',
  46. smalltalk.method({
  47. selector: 'signalFailure:',
  48. category: 'private',
  49. fn: function (aString){
  50. var self=this;
  51. (function($rec){smalltalk.send($rec, "_messageText_", [aString]);return smalltalk.send($rec, "_signal", []);})(smalltalk.send((smalltalk.TestFailure || TestFailure), "_new", []));
  52. return self;},
  53. source: unescape('signalFailure%3A%20aString%0A%09TestFailure%20new%0A%09%09messageText%3A%20aString%3B%0A%09%09signal'),
  54. messageSends: ["messageText:", "signal", "new"],
  55. referencedClasses: []
  56. }),
  57. smalltalk.TestCase);
  58. smalltalk.addMethod(
  59. '_setUp',
  60. smalltalk.method({
  61. selector: 'setUp',
  62. category: 'running',
  63. fn: function (){
  64. var self=this;
  65. return self;},
  66. source: unescape('setUp'),
  67. messageSends: [],
  68. referencedClasses: []
  69. }),
  70. smalltalk.TestCase);
  71. smalltalk.addMethod(
  72. '_tearDown',
  73. smalltalk.method({
  74. selector: 'tearDown',
  75. category: 'running',
  76. fn: function (){
  77. var self=this;
  78. return self;},
  79. source: unescape('tearDown'),
  80. messageSends: [],
  81. referencedClasses: []
  82. }),
  83. smalltalk.TestCase);
  84. smalltalk.addMethod(
  85. '_methods',
  86. smalltalk.method({
  87. selector: 'methods',
  88. category: 'running',
  89. fn: function (){
  90. var self=this;
  91. return smalltalk.send(smalltalk.send(smalltalk.send(smalltalk.send(self, "_class", []), "_methodDictionary", []), "_keys", []), "_select_", [(function(each){return smalltalk.send(each, "_match_", [unescape("%5Etest")]);})]);
  92. return self;},
  93. source: unescape('methods%0A%09%5Eself%20class%20methodDictionary%20keys%20select%3A%20%5B%3Aeach%20%7C%20each%20match%3A%20%27%5Etest%27%5D'),
  94. messageSends: ["select:", "keys", "methodDictionary", "class", "match:"],
  95. referencedClasses: []
  96. }),
  97. smalltalk.TestCase);
  98. smalltalk.addMethod(
  99. '_runCaseFor_',
  100. smalltalk.method({
  101. selector: 'runCaseFor:',
  102. category: 'running',
  103. fn: function (aTestResult){
  104. var self=this;
  105. smalltalk.send((function(){smalltalk.send(self, "_setUp", []);return smalltalk.send(self, "_performTestFor_", [aTestResult]);}), "_on_do_", [(smalltalk.Error || Error), (function(ex){smalltalk.send(self, "_tearDown", []);smalltalk.send(self, "_cleanUpInstanceVariables", []);return smalltalk.send(ex, "_signal", []);})]);
  106. smalltalk.send(self, "_tearDown", []);
  107. smalltalk.send(self, "_cleanUpInstanceVariables", []);
  108. return self;},
  109. source: unescape('runCaseFor%3A%20aTestResult%0A%09%5Bself%20setUp.%0A%09self%20performTestFor%3A%20aTestResult%5D%0A%09%09on%3A%20Error%0A%09%09do%3A%20%5B%3Aex%20%7C%0A%09%09%09self%20tearDown.%0A%09%09%09self%20cleanUpInstanceVariables.%0A%09%09%09ex%20signal%5D.%0A%09self%20tearDown.%0A%09self%20cleanUpInstanceVariables'),
  110. messageSends: ["on:do:", "setUp", "performTestFor:", "tearDown", "cleanUpInstanceVariables", "signal"],
  111. referencedClasses: [smalltalk.Error]
  112. }),
  113. smalltalk.TestCase);
  114. smalltalk.addMethod(
  115. '_performTestFor_',
  116. smalltalk.method({
  117. selector: 'performTestFor:',
  118. category: 'running',
  119. fn: function (aResult){
  120. var self=this;
  121. smalltalk.send(smalltalk.send(self, "_methods", []), "_do_", [(function(each){smalltalk.send((function(){return smalltalk.send((function(){return smalltalk.send(self, "_perform_", [each]);}), "_on_do_", [(smalltalk.TestFailure || TestFailure), (function(ex){return smalltalk.send(aResult, "_addFailure_", [smalltalk.send(smalltalk.send(smalltalk.send(smalltalk.send(smalltalk.send(smalltalk.send(self, "_class", []), "_name", []), "__comma", [unescape("%3E%3E")]), "__comma", [each]), "__comma", [": "]), "__comma", [smalltalk.send(ex, "_messageText", [])])]);})]);}), "_on_do_", [(smalltalk.Error || Error), (function(ex){return smalltalk.send(aResult, "_addError_", [smalltalk.send(smalltalk.send(smalltalk.send(smalltalk.send(smalltalk.send(smalltalk.send(self, "_class", []), "_name", []), "__comma", [unescape("%3E%3E")]), "__comma", [each]), "__comma", [": "]), "__comma", [smalltalk.send(ex, "_messageText", [])])]);})]);return smalltalk.send(aResult, "_increaseRuns", []);})]);
  122. return self;},
  123. source: unescape('performTestFor%3A%20aResult%0A%09self%20methods%20do%3A%20%5B%3Aeach%20%7C%20%0A%09%09%5B%5Bself%20perform%3A%20each%5D%0A%09%09%09on%3A%20TestFailure%20do%3A%20%5B%3Aex%20%7C%20aResult%20addFailure%3A%20self%20class%20name%2C%20%27%3E%3E%27%2C%20each%2C%20%27%3A%20%27%2C%20ex%20messageText%5D%5D%0A%09%09%09on%3A%20Error%20do%3A%20%5B%3Aex%20%7C%20aResult%20addError%3A%20self%20class%20name%2C%20%27%3E%3E%27%2C%20each%2C%20%27%3A%20%27%2C%20ex%20messageText%5D.%0A%09%09aResult%20increaseRuns%5D'),
  124. messageSends: ["do:", "methods", "on:do:", "perform:", "addFailure:", unescape("%2C"), "name", "class", "messageText", "addError:", "increaseRuns"],
  125. referencedClasses: [smalltalk.Error]
  126. }),
  127. smalltalk.TestCase);
  128. smalltalk.addMethod(
  129. '_assert_',
  130. smalltalk.method({
  131. selector: 'assert:',
  132. category: 'testing',
  133. fn: function (aBoolean){
  134. var self=this;
  135. smalltalk.send(self, "_assert_description_", [aBoolean, "Assertion failed"]);
  136. return self;},
  137. source: unescape('assert%3A%20aBoolean%0A%09self%20assert%3A%20aBoolean%20description%3A%20%27Assertion%20failed%27'),
  138. messageSends: ["assert:description:"],
  139. referencedClasses: []
  140. }),
  141. smalltalk.TestCase);
  142. smalltalk.addMethod(
  143. '_deny_',
  144. smalltalk.method({
  145. selector: 'deny:',
  146. category: 'testing',
  147. fn: function (aBoolean){
  148. var self=this;
  149. smalltalk.send(self, "_assert_", [smalltalk.send(aBoolean, "_not", [])]);
  150. return self;},
  151. source: unescape('deny%3A%20aBoolean%0A%09self%20assert%3A%20aBoolean%20not'),
  152. messageSends: ["assert:", "not"],
  153. referencedClasses: []
  154. }),
  155. smalltalk.TestCase);
  156. smalltalk.addMethod(
  157. '_assert_equals_',
  158. smalltalk.method({
  159. selector: 'assert:equals:',
  160. category: 'testing',
  161. fn: function (expected, actual){
  162. var self=this;
  163. 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", [])])]);
  164. return self;},
  165. 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'),
  166. messageSends: ["assert:description:", unescape("%3D"), unescape("%2C"), "asString"],
  167. referencedClasses: []
  168. }),
  169. smalltalk.TestCase);
  170. smalltalk.addMethod(
  171. '_assert_description_',
  172. smalltalk.method({
  173. selector: 'assert:description:',
  174. category: 'testing',
  175. fn: function (aBoolean, aString){
  176. var self=this;
  177. (($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]);})]);
  178. return self;},
  179. source: unescape('assert%3A%20aBoolean%20description%3A%20aString%0A%09aBoolean%20ifFalse%3A%20%5Bself%20signalFailure%3A%20aString%5D'),
  180. messageSends: ["ifFalse:", "signalFailure:"],
  181. referencedClasses: []
  182. }),
  183. smalltalk.TestCase);
  184. smalltalk.addClass('TestFailure', smalltalk.Error, [], 'SUnit');
  185. smalltalk.addClass('TestResult', smalltalk.Object, ['timestamp', 'runs', 'errors', 'failures', 'total'], 'SUnit');
  186. smalltalk.addMethod(
  187. '_timestamp',
  188. smalltalk.method({
  189. selector: 'timestamp',
  190. category: 'accessing',
  191. fn: function (){
  192. var self=this;
  193. return self['@timestamp'];
  194. return self;},
  195. source: unescape('timestamp%0A%09%5Etimestamp'),
  196. messageSends: [],
  197. referencedClasses: []
  198. }),
  199. smalltalk.TestResult);
  200. smalltalk.addMethod(
  201. '_errors',
  202. smalltalk.method({
  203. selector: 'errors',
  204. category: 'accessing',
  205. fn: function (){
  206. var self=this;
  207. return self['@errors'];
  208. return self;},
  209. source: unescape('errors%0A%09%5Eerrors'),
  210. messageSends: [],
  211. referencedClasses: []
  212. }),
  213. smalltalk.TestResult);
  214. smalltalk.addMethod(
  215. '_failures',
  216. smalltalk.method({
  217. selector: 'failures',
  218. category: 'accessing',
  219. fn: function (){
  220. var self=this;
  221. return self['@failures'];
  222. return self;},
  223. source: unescape('failures%0A%09%5Efailures'),
  224. messageSends: [],
  225. referencedClasses: []
  226. }),
  227. smalltalk.TestResult);
  228. smalltalk.addMethod(
  229. '_total',
  230. smalltalk.method({
  231. selector: 'total',
  232. category: 'accessing',
  233. fn: function (){
  234. var self=this;
  235. return self['@total'];
  236. return self;},
  237. source: unescape('total%0A%09%5Etotal'),
  238. messageSends: [],
  239. referencedClasses: []
  240. }),
  241. smalltalk.TestResult);
  242. smalltalk.addMethod(
  243. '_total_',
  244. smalltalk.method({
  245. selector: 'total:',
  246. category: 'accessing',
  247. fn: function (aNumber){
  248. var self=this;
  249. self['@total']=aNumber;
  250. return self;},
  251. source: unescape('total%3A%20aNumber%0A%09total%20%3A%3D%20aNumber'),
  252. messageSends: [],
  253. referencedClasses: []
  254. }),
  255. smalltalk.TestResult);
  256. smalltalk.addMethod(
  257. '_addError_',
  258. smalltalk.method({
  259. selector: 'addError:',
  260. category: 'accessing',
  261. fn: function (anError){
  262. var self=this;
  263. smalltalk.send(smalltalk.send(self, "_errors", []), "_add_", [anError]);
  264. return self;},
  265. source: unescape('addError%3A%20anError%0A%09self%20errors%20add%3A%20anError'),
  266. messageSends: ["add:", "errors"],
  267. referencedClasses: []
  268. }),
  269. smalltalk.TestResult);
  270. smalltalk.addMethod(
  271. '_addFailure_',
  272. smalltalk.method({
  273. selector: 'addFailure:',
  274. category: 'accessing',
  275. fn: function (aFailure){
  276. var self=this;
  277. smalltalk.send(smalltalk.send(self, "_failures", []), "_add_", [aFailure]);
  278. return self;},
  279. source: unescape('addFailure%3A%20aFailure%0A%09self%20failures%20add%3A%20aFailure'),
  280. messageSends: ["add:", "failures"],
  281. referencedClasses: []
  282. }),
  283. smalltalk.TestResult);
  284. smalltalk.addMethod(
  285. '_runs',
  286. smalltalk.method({
  287. selector: 'runs',
  288. category: 'accessing',
  289. fn: function (){
  290. var self=this;
  291. return self['@runs'];
  292. return self;},
  293. source: unescape('runs%0A%09%5Eruns'),
  294. messageSends: [],
  295. referencedClasses: []
  296. }),
  297. smalltalk.TestResult);
  298. smalltalk.addMethod(
  299. '_increaseRuns',
  300. smalltalk.method({
  301. selector: 'increaseRuns',
  302. category: 'accessing',
  303. fn: function (){
  304. var self=this;
  305. self['@runs']=(($receiver = self['@runs']).klass === smalltalk.Number) ? $receiver +(1) : smalltalk.send($receiver, "__plus", [(1)]);
  306. return self;},
  307. source: unescape('increaseRuns%0A%09runs%20%3A%3D%20runs%20+%201'),
  308. messageSends: [unescape("+")],
  309. referencedClasses: []
  310. }),
  311. smalltalk.TestResult);
  312. smalltalk.addMethod(
  313. '_status',
  314. smalltalk.method({
  315. selector: 'status',
  316. category: 'accessing',
  317. fn: function (){
  318. var self=this;
  319. 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";})]);
  320. return self;},
  321. 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'),
  322. messageSends: ["ifTrue:ifFalse:", "isEmpty", "errors", "failures"],
  323. referencedClasses: []
  324. }),
  325. smalltalk.TestResult);
  326. smalltalk.addMethod(
  327. '_initialize',
  328. smalltalk.method({
  329. selector: 'initialize',
  330. category: 'initialization',
  331. fn: function (){
  332. var self=this;
  333. smalltalk.send(self, "_initialize", [], smalltalk.Object);
  334. self['@timestamp']=smalltalk.send((smalltalk.Date || Date), "_now", []);
  335. self['@runs']=(0);
  336. self['@errors']=smalltalk.send((smalltalk.Array || Array), "_new", []);
  337. self['@failures']=smalltalk.send((smalltalk.Array || Array), "_new", []);
  338. self['@total']=(0);
  339. return self;},
  340. 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'),
  341. messageSends: ["initialize", "now", "new"],
  342. referencedClasses: [smalltalk.Date,smalltalk.Array]
  343. }),
  344. smalltalk.TestResult);