SUnit.deploy.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607
  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. "_startCase",
  176. smalltalk.method({
  177. selector: "startCase",
  178. fn: function (){
  179. var self=this;
  180. smalltalk.send(self,"_setUp",[]);
  181. smalltalk.send(self,"_performTest",[]);
  182. return self}
  183. }),
  184. smalltalk.TestCase);
  185. smalltalk.addMethod(
  186. "_tearDown",
  187. smalltalk.method({
  188. selector: "tearDown",
  189. fn: function () {
  190. var self = this;
  191. return self;
  192. }
  193. }),
  194. smalltalk.TestCase);
  195. smalltalk.addMethod(
  196. "_allTestSelectors",
  197. smalltalk.method({
  198. selector: "allTestSelectors",
  199. fn: function () {
  200. var self = this;
  201. var $1;
  202. var selectors;
  203. selectors = smalltalk.send(self, "_testSelectors", []);
  204. $1 = smalltalk.send(self, "_shouldInheritSelectors", []);
  205. if (smalltalk.assert($1)) {
  206. smalltalk.send(selectors, "_addAll_", [smalltalk.send(smalltalk.send(self, "_superclass", []), "_allTestSelectors", [])]);
  207. }
  208. return selectors;
  209. }
  210. }),
  211. smalltalk.TestCase.klass);
  212. smalltalk.addMethod(
  213. "_buildSuite",
  214. smalltalk.method({
  215. selector: "buildSuite",
  216. fn: function () {
  217. var self = this;
  218. var $1;
  219. $1 = smalltalk.send(smalltalk.send(self, "_allTestSelectors", []), "_collect_", [function (each) {return smalltalk.send(self, "_selector_", [each]);}]);
  220. return $1;
  221. }
  222. }),
  223. smalltalk.TestCase.klass);
  224. smalltalk.addMethod(
  225. "_isAbstract",
  226. smalltalk.method({
  227. selector: "isAbstract",
  228. fn: function () {
  229. var self = this;
  230. var $1;
  231. $1 = smalltalk.send(smalltalk.send(self, "_name", []), "__eq", ["TestCase"]);
  232. return $1;
  233. }
  234. }),
  235. smalltalk.TestCase.klass);
  236. smalltalk.addMethod(
  237. "_lookupHierarchyRoot",
  238. smalltalk.method({
  239. selector: "lookupHierarchyRoot",
  240. fn: function () {
  241. var self = this;
  242. return smalltalk.TestCase || TestCase;
  243. }
  244. }),
  245. smalltalk.TestCase.klass);
  246. smalltalk.addMethod(
  247. "_selector_",
  248. smalltalk.method({
  249. selector: "selector:",
  250. fn: function (aSelector) {
  251. var self = this;
  252. var $2, $3, $1;
  253. $2 = smalltalk.send(self, "_new", []);
  254. smalltalk.send($2, "_setTestSelector_", [aSelector]);
  255. $3 = smalltalk.send($2, "_yourself", []);
  256. $1 = $3;
  257. return $1;
  258. }
  259. }),
  260. smalltalk.TestCase.klass);
  261. smalltalk.addMethod(
  262. "_shouldInheritSelectors",
  263. smalltalk.method({
  264. selector: "shouldInheritSelectors",
  265. fn: function () {
  266. var self = this;
  267. var $1;
  268. $1 = smalltalk.send(self, "_~_eq", [smalltalk.send(self, "_lookupHierarchyRoot", [])]);
  269. return $1;
  270. }
  271. }),
  272. smalltalk.TestCase.klass);
  273. smalltalk.addMethod(
  274. "_testSelectors",
  275. smalltalk.method({
  276. selector: "testSelectors",
  277. fn: function () {
  278. var self = this;
  279. var $1;
  280. $1 = smalltalk.send(smalltalk.send(smalltalk.send(self, "_methodDictionary", []), "_keys", []), "_select_", [function (each) {return smalltalk.send(each, "_match_", ["^test"]);}]);
  281. return $1;
  282. }
  283. }),
  284. smalltalk.TestCase.klass);
  285. smalltalk.addClass('TestFailure', smalltalk.Error, [], 'SUnit');
  286. smalltalk.addClass('TestResult', smalltalk.Object, ['timestamp', 'runs', 'errors', 'failures', 'total'], 'SUnit');
  287. smalltalk.addMethod(
  288. "_addError_",
  289. smalltalk.method({
  290. selector: "addError:",
  291. fn: function (anError) {
  292. var self = this;
  293. smalltalk.send(smalltalk.send(self, "_errors", []), "_add_", [anError]);
  294. return self;
  295. }
  296. }),
  297. smalltalk.TestResult);
  298. smalltalk.addMethod(
  299. "_addFailure_",
  300. smalltalk.method({
  301. selector: "addFailure:",
  302. fn: function (aFailure) {
  303. var self = this;
  304. smalltalk.send(smalltalk.send(self, "_failures", []), "_add_", [aFailure]);
  305. return self;
  306. }
  307. }),
  308. smalltalk.TestResult);
  309. smalltalk.addMethod(
  310. "_errors",
  311. smalltalk.method({
  312. selector: "errors",
  313. fn: function () {
  314. var self = this;
  315. return self['@errors'];
  316. }
  317. }),
  318. smalltalk.TestResult);
  319. smalltalk.addMethod(
  320. "_failures",
  321. smalltalk.method({
  322. selector: "failures",
  323. fn: function () {
  324. var self = this;
  325. return self['@failures'];
  326. }
  327. }),
  328. smalltalk.TestResult);
  329. smalltalk.addMethod(
  330. "_increaseRuns",
  331. smalltalk.method({
  332. selector: "increaseRuns",
  333. fn: function () {
  334. var self = this;
  335. self['@runs'] = smalltalk.send(self['@runs'], "__plus", [1]);
  336. return self;
  337. }
  338. }),
  339. smalltalk.TestResult);
  340. smalltalk.addMethod(
  341. "_initialize",
  342. smalltalk.method({
  343. selector: "initialize",
  344. fn: function () {
  345. var self = this;
  346. smalltalk.send(self, "_initialize", [], smalltalk.Object);
  347. self['@timestamp'] = smalltalk.send(smalltalk.Date || Date, "_now", []);
  348. self['@runs'] = 0;
  349. self['@errors'] = smalltalk.send(smalltalk.Array || Array, "_new", []);
  350. self['@failures'] = smalltalk.send(smalltalk.Array || Array, "_new", []);
  351. self['@total'] = 0;
  352. return self;
  353. }
  354. }),
  355. smalltalk.TestResult);
  356. smalltalk.addMethod(
  357. "_nextRunDo_",
  358. smalltalk.method({
  359. selector: "nextRunDo:",
  360. fn: function (aBlock){
  361. var self=this;
  362. var $2,$1;
  363. $2=smalltalk.send(smalltalk.send(self,"_runs",[]),"__eq_eq",[smalltalk.send(self,"_total",[])]);
  364. if(! smalltalk.assert($2)){
  365. $1=smalltalk.send(aBlock,"_value_",[smalltalk.send(smalltalk.send(self,"_runs",[]),"__plus",[(1)])]);
  366. };
  367. return $1;
  368. }
  369. }),
  370. smalltalk.TestResult);
  371. smalltalk.addMethod(
  372. "_runCase_",
  373. smalltalk.method({
  374. selector: "runCase:",
  375. fn: function (aTestCase){
  376. var self=this;
  377. smalltalk.send((function(){
  378. return smalltalk.send((function(){
  379. return smalltalk.send((function(){
  380. smalltalk.send(self,"_increaseRuns",[]);
  381. return smalltalk.send(aTestCase,"_startCase",[]);
  382. }),"_ensure_",[(function(){
  383. return smalltalk.send(aTestCase,"_tearDown",[]);
  384. })]);
  385. }),"_on_do_",[(smalltalk.TestFailure || TestFailure),(function(ex){
  386. return smalltalk.send(self,"_addFailure_",[aTestCase]);
  387. })]);
  388. }),"_on_do_",[(smalltalk.Error || Error),(function(ex){
  389. return smalltalk.send(self,"_addError_",[aTestCase]);
  390. })]);
  391. return self}
  392. }),
  393. smalltalk.TestResult);
  394. smalltalk.addMethod(
  395. "_runs",
  396. smalltalk.method({
  397. selector: "runs",
  398. fn: function () {
  399. var self = this;
  400. return self['@runs'];
  401. }
  402. }),
  403. smalltalk.TestResult);
  404. smalltalk.addMethod(
  405. "_status",
  406. smalltalk.method({
  407. selector: "status",
  408. fn: function () {
  409. var self = this;
  410. var $2, $3, $1;
  411. $2 = smalltalk.send(smalltalk.send(self, "_errors", []), "_isEmpty", []);
  412. if (smalltalk.assert($2)) {
  413. $3 = smalltalk.send(smalltalk.send(self, "_failures", []), "_isEmpty", []);
  414. if (smalltalk.assert($3)) {
  415. $1 = "success";
  416. } else {
  417. $1 = "failure";
  418. }
  419. } else {
  420. $1 = "error";
  421. }
  422. return $1;
  423. }
  424. }),
  425. smalltalk.TestResult);
  426. smalltalk.addMethod(
  427. "_timestamp",
  428. smalltalk.method({
  429. selector: "timestamp",
  430. fn: function () {
  431. var self = this;
  432. return self['@timestamp'];
  433. }
  434. }),
  435. smalltalk.TestResult);
  436. smalltalk.addMethod(
  437. "_total",
  438. smalltalk.method({
  439. selector: "total",
  440. fn: function () {
  441. var self = this;
  442. return self['@total'];
  443. }
  444. }),
  445. smalltalk.TestResult);
  446. smalltalk.addMethod(
  447. "_total_",
  448. smalltalk.method({
  449. selector: "total:",
  450. fn: function (aNumber) {
  451. var self = this;
  452. self['@total'] = aNumber;
  453. return self;
  454. }
  455. }),
  456. smalltalk.TestResult);
  457. smalltalk.addClass('TestSuiteRunner', smalltalk.Object, ['suite', 'result', 'announcer', 'worker'], 'SUnit');
  458. smalltalk.addMethod(
  459. "_announcer",
  460. smalltalk.method({
  461. selector: "announcer",
  462. fn: function (){
  463. var self=this;
  464. return self["@announcer"];
  465. }
  466. }),
  467. smalltalk.TestSuiteRunner);
  468. smalltalk.addMethod(
  469. "_initialize",
  470. smalltalk.method({
  471. selector: "initialize",
  472. fn: function (){
  473. var self=this;
  474. smalltalk.send(self,"_initialize",[],smalltalk.Object);
  475. self["@announcer"]=smalltalk.send((smalltalk.Announcer || Announcer),"_new",[]);
  476. self["@result"]=smalltalk.send((smalltalk.TestResult || TestResult),"_new",[]);
  477. self["@worker"]=(function(){
  478. return smalltalk.send(self["@result"],"_nextRunDo_",[(function(index){
  479. return smalltalk.send((function(){
  480. return smalltalk.send(self["@result"],"_runCase_",[smalltalk.send(self["@suite"],"_at_",[index])]);
  481. }),"_ensure_",[(function(){
  482. return smalltalk.send(self,"_resume",[]);
  483. })]);
  484. })]);
  485. });
  486. return self}
  487. }),
  488. smalltalk.TestSuiteRunner);
  489. smalltalk.addMethod(
  490. "_result",
  491. smalltalk.method({
  492. selector: "result",
  493. fn: function (){
  494. var self=this;
  495. return self["@result"];
  496. }
  497. }),
  498. smalltalk.TestSuiteRunner);
  499. smalltalk.addMethod(
  500. "_resume",
  501. smalltalk.method({
  502. selector: "resume",
  503. fn: function (){
  504. var self=this;
  505. smalltalk.send(self["@worker"],"_fork",[]);
  506. smalltalk.send(self["@announcer"],"_announce_",[smalltalk.send(smalltalk.send((smalltalk.ResultAnnouncement || ResultAnnouncement),"_new",[]),"_result_",[self["@result"]])]);
  507. return self}
  508. }),
  509. smalltalk.TestSuiteRunner);
  510. smalltalk.addMethod(
  511. "_run",
  512. smalltalk.method({
  513. selector: "run",
  514. fn: function (){
  515. var self=this;
  516. smalltalk.send(self["@result"],"_total_",[smalltalk.send(self["@suite"],"_size",[])]);
  517. smalltalk.send(self,"_resume",[]);
  518. return self}
  519. }),
  520. smalltalk.TestSuiteRunner);
  521. smalltalk.addMethod(
  522. "_suite_",
  523. smalltalk.method({
  524. selector: "suite:",
  525. fn: function (aCollection){
  526. var self=this;
  527. self["@suite"]=aCollection;
  528. return self}
  529. }),
  530. smalltalk.TestSuiteRunner);
  531. smalltalk.addMethod(
  532. "_new",
  533. smalltalk.method({
  534. selector: "new",
  535. fn: function (){
  536. var self=this;
  537. smalltalk.send(self,"_shouldNotImplement",[]);
  538. return self}
  539. }),
  540. smalltalk.TestSuiteRunner.klass);
  541. smalltalk.addMethod(
  542. "_on_",
  543. smalltalk.method({
  544. selector: "on:",
  545. fn: function (aCollection){
  546. var self=this;
  547. var $1;
  548. $1=smalltalk.send(smalltalk.send(self,"_new",[],smalltalk.Object.klass),"_suite_",[aCollection]);
  549. return $1;
  550. }
  551. }),
  552. smalltalk.TestSuiteRunner.klass);