2
0

SUnit.deploy.js 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424
  1. smalltalk.addPackage('SUnit', {});
  2. smalltalk.addClass('TestCase', smalltalk.Object, ['testSelector'], 'SUnit');
  3. smalltalk.addMethod(
  4. "_assert_",
  5. smalltalk.method({
  6. selector: "assert:",
  7. fn: function (aBoolean) {
  8. var self = this;
  9. smalltalk.send(self, "_assert_description_", [aBoolean, "Assertion failed"]);
  10. return self;
  11. }
  12. }),
  13. smalltalk.TestCase);
  14. smalltalk.addMethod(
  15. "_assert_description_",
  16. smalltalk.method({
  17. selector: "assert:description:",
  18. fn: function (aBoolean, aString) {
  19. var self = this;
  20. if (!smalltalk.assert(aBoolean)) {
  21. smalltalk.send(self, "_signalFailure_", [aString]);
  22. }
  23. return self;
  24. }
  25. }),
  26. smalltalk.TestCase);
  27. smalltalk.addMethod(
  28. "_assert_equals_",
  29. smalltalk.method({
  30. selector: "assert:equals:",
  31. fn: function (expected, actual) {
  32. var self = this;
  33. var $1;
  34. $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", [])])]);
  35. return $1;
  36. }
  37. }),
  38. smalltalk.TestCase);
  39. smalltalk.addMethod(
  40. "_deny_",
  41. smalltalk.method({
  42. selector: "deny:",
  43. fn: function (aBoolean) {
  44. var self = this;
  45. smalltalk.send(self, "_assert_", [smalltalk.send(aBoolean, "_not", [])]);
  46. return self;
  47. }
  48. }),
  49. smalltalk.TestCase);
  50. smalltalk.addMethod(
  51. "_performTestFor_",
  52. smalltalk.method({
  53. selector: "performTestFor:",
  54. fn: function (aResult) {
  55. var self = this;
  56. 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]);}]);
  57. return self;
  58. }
  59. }),
  60. smalltalk.TestCase);
  61. smalltalk.addMethod(
  62. "_runCaseFor_",
  63. smalltalk.method({
  64. selector: "runCaseFor:",
  65. fn: function (aTestResult) {
  66. var self = this;
  67. smalltalk.send(self, "_setUp", []);
  68. smalltalk.send(aTestResult, "_increaseRuns", []);
  69. smalltalk.send(self, "_performTestFor_", [aTestResult]);
  70. smalltalk.send(self, "_tearDown", []);
  71. return self;
  72. }
  73. }),
  74. smalltalk.TestCase);
  75. smalltalk.addMethod(
  76. "_selector",
  77. smalltalk.method({
  78. selector: "selector",
  79. fn: function () {
  80. var self = this;
  81. return self['@testSelector'];
  82. }
  83. }),
  84. smalltalk.TestCase);
  85. smalltalk.addMethod(
  86. "_setTestSelector_",
  87. smalltalk.method({
  88. selector: "setTestSelector:",
  89. fn: function (aSelector) {
  90. var self = this;
  91. self['@testSelector'] = aSelector;
  92. return self;
  93. }
  94. }),
  95. smalltalk.TestCase);
  96. smalltalk.addMethod(
  97. "_setUp",
  98. smalltalk.method({
  99. selector: "setUp",
  100. fn: function () {
  101. var self = this;
  102. return self;
  103. }
  104. }),
  105. smalltalk.TestCase);
  106. smalltalk.addMethod(
  107. "_should_",
  108. smalltalk.method({
  109. selector: "should:",
  110. fn: function (aBlock) {
  111. var self = this;
  112. smalltalk.send(self, "_assert_", [smalltalk.send(aBlock, "_value", [])]);
  113. return self;
  114. }
  115. }),
  116. smalltalk.TestCase);
  117. smalltalk.addMethod(
  118. "_should_raise_",
  119. smalltalk.method({
  120. selector: "should:raise:",
  121. fn: function (aBlock, anExceptionClass) {
  122. var self = this;
  123. smalltalk.send(self, "_assert_", [smalltalk.send(function () {smalltalk.send(aBlock, "_value", []);return false;}, "_on_do_", [anExceptionClass, function (ex) {return true;}])]);
  124. return self;
  125. }
  126. }),
  127. smalltalk.TestCase);
  128. smalltalk.addMethod(
  129. "_shouldnt_raise_",
  130. smalltalk.method({
  131. selector: "shouldnt:raise:",
  132. fn: function (aBlock, anExceptionClass) {
  133. var self = this;
  134. smalltalk.send(self, "_assert_", [smalltalk.send(function () {smalltalk.send(aBlock, "_value", []);return true;}, "_on_do_", [anExceptionClass, function (ex) {return false;}])]);
  135. return self;
  136. }
  137. }),
  138. smalltalk.TestCase);
  139. smalltalk.addMethod(
  140. "_signalFailure_",
  141. smalltalk.method({
  142. selector: "signalFailure:",
  143. fn: function (aString) {
  144. var self = this;
  145. var $1, $2;
  146. $1 = smalltalk.send(smalltalk.TestFailure || TestFailure, "_new", []);
  147. smalltalk.send($1, "_messageText_", [aString]);
  148. $2 = smalltalk.send($1, "_signal", []);
  149. return self;
  150. }
  151. }),
  152. smalltalk.TestCase);
  153. smalltalk.addMethod(
  154. "_tearDown",
  155. smalltalk.method({
  156. selector: "tearDown",
  157. fn: function () {
  158. var self = this;
  159. return self;
  160. }
  161. }),
  162. smalltalk.TestCase);
  163. smalltalk.addMethod(
  164. "_allTestSelectors",
  165. smalltalk.method({
  166. selector: "allTestSelectors",
  167. fn: function () {
  168. var self = this;
  169. var $1;
  170. var selectors;
  171. selectors = smalltalk.send(self, "_testSelectors", []);
  172. $1 = smalltalk.send(self, "_shouldInheritSelectors", []);
  173. if (smalltalk.assert($1)) {
  174. smalltalk.send(selectors, "_addAll_", [smalltalk.send(smalltalk.send(self, "_superclass", []), "_allTestSelectors", [])]);
  175. }
  176. return selectors;
  177. }
  178. }),
  179. smalltalk.TestCase.klass);
  180. smalltalk.addMethod(
  181. "_buildSuite",
  182. smalltalk.method({
  183. selector: "buildSuite",
  184. fn: function () {
  185. var self = this;
  186. var $1;
  187. $1 = smalltalk.send(smalltalk.send(self, "_allTestSelectors", []), "_collect_", [function (each) {return smalltalk.send(self, "_selector_", [each]);}]);
  188. return $1;
  189. }
  190. }),
  191. smalltalk.TestCase.klass);
  192. smalltalk.addMethod(
  193. "_isAbstract",
  194. smalltalk.method({
  195. selector: "isAbstract",
  196. fn: function () {
  197. var self = this;
  198. var $1;
  199. $1 = smalltalk.send(smalltalk.send(self, "_name", []), "__eq", ["TestCase"]);
  200. return $1;
  201. }
  202. }),
  203. smalltalk.TestCase.klass);
  204. smalltalk.addMethod(
  205. "_lookupHierarchyRoot",
  206. smalltalk.method({
  207. selector: "lookupHierarchyRoot",
  208. fn: function () {
  209. var self = this;
  210. return smalltalk.TestCase || TestCase;
  211. }
  212. }),
  213. smalltalk.TestCase.klass);
  214. smalltalk.addMethod(
  215. "_selector_",
  216. smalltalk.method({
  217. selector: "selector:",
  218. fn: function (aSelector) {
  219. var self = this;
  220. var $2, $3, $1;
  221. $2 = smalltalk.send(self, "_new", []);
  222. smalltalk.send($2, "_setTestSelector_", [aSelector]);
  223. $3 = smalltalk.send($2, "_yourself", []);
  224. $1 = $3;
  225. return $1;
  226. }
  227. }),
  228. smalltalk.TestCase.klass);
  229. smalltalk.addMethod(
  230. "_shouldInheritSelectors",
  231. smalltalk.method({
  232. selector: "shouldInheritSelectors",
  233. fn: function () {
  234. var self = this;
  235. var $1;
  236. $1 = smalltalk.send(self, "_~_eq", [smalltalk.send(self, "_lookupHierarchyRoot", [])]);
  237. return $1;
  238. }
  239. }),
  240. smalltalk.TestCase.klass);
  241. smalltalk.addMethod(
  242. "_testSelectors",
  243. smalltalk.method({
  244. selector: "testSelectors",
  245. fn: function () {
  246. var self = this;
  247. var $1;
  248. $1 = smalltalk.send(smalltalk.send(smalltalk.send(self, "_methodDictionary", []), "_keys", []), "_select_", [function (each) {return smalltalk.send(each, "_match_", ["^test"]);}]);
  249. return $1;
  250. }
  251. }),
  252. smalltalk.TestCase.klass);
  253. smalltalk.addClass('TestFailure', smalltalk.Error, [], 'SUnit');
  254. smalltalk.addClass('TestResult', smalltalk.Object, ['timestamp', 'runs', 'errors', 'failures', 'total'], 'SUnit');
  255. smalltalk.addMethod(
  256. "_addError_",
  257. smalltalk.method({
  258. selector: "addError:",
  259. fn: function (anError) {
  260. var self = this;
  261. smalltalk.send(smalltalk.send(self, "_errors", []), "_add_", [anError]);
  262. return self;
  263. }
  264. }),
  265. smalltalk.TestResult);
  266. smalltalk.addMethod(
  267. "_addFailure_",
  268. smalltalk.method({
  269. selector: "addFailure:",
  270. fn: function (aFailure) {
  271. var self = this;
  272. smalltalk.send(smalltalk.send(self, "_failures", []), "_add_", [aFailure]);
  273. return self;
  274. }
  275. }),
  276. smalltalk.TestResult);
  277. smalltalk.addMethod(
  278. "_errors",
  279. smalltalk.method({
  280. selector: "errors",
  281. fn: function () {
  282. var self = this;
  283. return self['@errors'];
  284. }
  285. }),
  286. smalltalk.TestResult);
  287. smalltalk.addMethod(
  288. "_failures",
  289. smalltalk.method({
  290. selector: "failures",
  291. fn: function () {
  292. var self = this;
  293. return self['@failures'];
  294. }
  295. }),
  296. smalltalk.TestResult);
  297. smalltalk.addMethod(
  298. "_increaseRuns",
  299. smalltalk.method({
  300. selector: "increaseRuns",
  301. fn: function () {
  302. var self = this;
  303. self['@runs'] = smalltalk.send(self['@runs'], "__plus", [1]);
  304. return self;
  305. }
  306. }),
  307. smalltalk.TestResult);
  308. smalltalk.addMethod(
  309. "_initialize",
  310. smalltalk.method({
  311. selector: "initialize",
  312. fn: function () {
  313. var self = this;
  314. smalltalk.send(self, "_initialize", [], smalltalk.Object);
  315. self['@timestamp'] = smalltalk.send(smalltalk.Date || Date, "_now", []);
  316. self['@runs'] = 0;
  317. self['@errors'] = smalltalk.send(smalltalk.Array || Array, "_new", []);
  318. self['@failures'] = smalltalk.send(smalltalk.Array || Array, "_new", []);
  319. self['@total'] = 0;
  320. return self;
  321. }
  322. }),
  323. smalltalk.TestResult);
  324. smalltalk.addMethod(
  325. "_runs",
  326. smalltalk.method({
  327. selector: "runs",
  328. fn: function () {
  329. var self = this;
  330. return self['@runs'];
  331. }
  332. }),
  333. smalltalk.TestResult);
  334. smalltalk.addMethod(
  335. "_status",
  336. smalltalk.method({
  337. selector: "status",
  338. fn: function () {
  339. var self = this;
  340. var $2, $3, $1;
  341. $2 = smalltalk.send(smalltalk.send(self, "_errors", []), "_isEmpty", []);
  342. if (smalltalk.assert($2)) {
  343. $3 = smalltalk.send(smalltalk.send(self, "_failures", []), "_isEmpty", []);
  344. if (smalltalk.assert($3)) {
  345. $1 = "success";
  346. } else {
  347. $1 = "failure";
  348. }
  349. } else {
  350. $1 = "error";
  351. }
  352. return $1;
  353. }
  354. }),
  355. smalltalk.TestResult);
  356. smalltalk.addMethod(
  357. "_timestamp",
  358. smalltalk.method({
  359. selector: "timestamp",
  360. fn: function () {
  361. var self = this;
  362. return self['@timestamp'];
  363. }
  364. }),
  365. smalltalk.TestResult);
  366. smalltalk.addMethod(
  367. "_total",
  368. smalltalk.method({
  369. selector: "total",
  370. fn: function () {
  371. var self = this;
  372. return self['@total'];
  373. }
  374. }),
  375. smalltalk.TestResult);
  376. smalltalk.addMethod(
  377. "_total_",
  378. smalltalk.method({
  379. selector: "total:",
  380. fn: function (aNumber) {
  381. var self = this;
  382. self['@total'] = aNumber;
  383. return self;
  384. }
  385. }),
  386. smalltalk.TestResult);