SUnit.deploy.js 13 KB

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