SUnit.deploy.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582
  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. "_nextRunDo_",
  347. smalltalk.method({
  348. selector: "nextRunDo:",
  349. fn: function (aBlock){
  350. var self=this;
  351. var $2,$1;
  352. $2=smalltalk.send(smalltalk.send(self,"_runs",[]),"__eq_eq",[smalltalk.send(self,"_total",[])]);
  353. if(! smalltalk.assert($2)){
  354. $1=smalltalk.send(aBlock,"_value_",[smalltalk.send(smalltalk.send(self,"_runs",[]),"__plus",[(1)])]);
  355. };
  356. return $1;
  357. }
  358. }),
  359. smalltalk.TestResult);
  360. smalltalk.addMethod(
  361. "_runCase_",
  362. smalltalk.method({
  363. selector: "runCase:",
  364. fn: function (aTestCase){
  365. var self=this;
  366. smalltalk.send((function(){
  367. return smalltalk.send((function(){
  368. smalltalk.send(self,"_increaseRuns",[]);
  369. return smalltalk.send(aTestCase,"_runCase",[]);
  370. }),"_on_do_",[(smalltalk.TestFailure || TestFailure),(function(ex){
  371. return smalltalk.send(self,"_addFailure_",[aTestCase]);
  372. })]);
  373. }),"_on_do_",[(smalltalk.Error || Error),(function(ex){
  374. return smalltalk.send(self,"_addError_",[aTestCase]);
  375. })]);
  376. return self}
  377. }),
  378. smalltalk.TestResult);
  379. smalltalk.addMethod(
  380. "_runs",
  381. smalltalk.method({
  382. selector: "runs",
  383. fn: function () {
  384. var self = this;
  385. return self['@runs'];
  386. }
  387. }),
  388. smalltalk.TestResult);
  389. smalltalk.addMethod(
  390. "_status",
  391. smalltalk.method({
  392. selector: "status",
  393. fn: function () {
  394. var self = this;
  395. var $2, $3, $1;
  396. $2 = smalltalk.send(smalltalk.send(self, "_errors", []), "_isEmpty", []);
  397. if (smalltalk.assert($2)) {
  398. $3 = smalltalk.send(smalltalk.send(self, "_failures", []), "_isEmpty", []);
  399. if (smalltalk.assert($3)) {
  400. $1 = "success";
  401. } else {
  402. $1 = "failure";
  403. }
  404. } else {
  405. $1 = "error";
  406. }
  407. return $1;
  408. }
  409. }),
  410. smalltalk.TestResult);
  411. smalltalk.addMethod(
  412. "_timestamp",
  413. smalltalk.method({
  414. selector: "timestamp",
  415. fn: function () {
  416. var self = this;
  417. return self['@timestamp'];
  418. }
  419. }),
  420. smalltalk.TestResult);
  421. smalltalk.addMethod(
  422. "_total",
  423. smalltalk.method({
  424. selector: "total",
  425. fn: function () {
  426. var self = this;
  427. return self['@total'];
  428. }
  429. }),
  430. smalltalk.TestResult);
  431. smalltalk.addMethod(
  432. "_total_",
  433. smalltalk.method({
  434. selector: "total:",
  435. fn: function (aNumber) {
  436. var self = this;
  437. self['@total'] = aNumber;
  438. return self;
  439. }
  440. }),
  441. smalltalk.TestResult);
  442. smalltalk.addClass('TestSuiteRunner', smalltalk.Object, ['suite', 'result', 'announcer'], 'SUnit');
  443. smalltalk.addMethod(
  444. "_announcer",
  445. smalltalk.method({
  446. selector: "announcer",
  447. fn: function (){
  448. var self=this;
  449. return self["@announcer"];
  450. }
  451. }),
  452. smalltalk.TestSuiteRunner);
  453. smalltalk.addMethod(
  454. "_initialize",
  455. smalltalk.method({
  456. selector: "initialize",
  457. fn: function (){
  458. var self=this;
  459. smalltalk.send(self,"_initialize",[],smalltalk.Object);
  460. self["@announcer"]=smalltalk.send((smalltalk.Announcer || Announcer),"_new",[]);
  461. self["@result"]=smalltalk.send((smalltalk.TestResult || TestResult),"_new",[]);
  462. return self}
  463. }),
  464. smalltalk.TestSuiteRunner);
  465. smalltalk.addMethod(
  466. "_result",
  467. smalltalk.method({
  468. selector: "result",
  469. fn: function (){
  470. var self=this;
  471. return self["@result"];
  472. }
  473. }),
  474. smalltalk.TestSuiteRunner);
  475. smalltalk.addMethod(
  476. "_run",
  477. smalltalk.method({
  478. selector: "run",
  479. fn: function (){
  480. var self=this;
  481. var worker;
  482. smalltalk.send(self["@result"],"_total_",[smalltalk.send(self["@suite"],"_size",[])]);
  483. smalltalk.send(self["@announcer"],"_announce_",[smalltalk.send(smalltalk.send((smalltalk.ResultAnnouncement || ResultAnnouncement),"_new",[]),"_result_",[self["@result"]])]);
  484. worker=(function(){
  485. return smalltalk.send(self["@result"],"_nextRunDo_",[(function(index){
  486. return smalltalk.send((function(){
  487. return smalltalk.send(self["@result"],"_runCase_",[smalltalk.send(self["@suite"],"_at_",[index])]);
  488. }),"_ensure_",[(function(){
  489. smalltalk.send(worker,"_fork",[]);
  490. return smalltalk.send(self["@announcer"],"_announce_",[smalltalk.send(smalltalk.send((smalltalk.ResultAnnouncement || ResultAnnouncement),"_new",[]),"_result_",[self["@result"]])]);
  491. })]);
  492. })]);
  493. });
  494. smalltalk.send(worker,"_fork",[]);
  495. return self}
  496. }),
  497. smalltalk.TestSuiteRunner);
  498. smalltalk.addMethod(
  499. "_suite_",
  500. smalltalk.method({
  501. selector: "suite:",
  502. fn: function (aCollection){
  503. var self=this;
  504. self["@suite"]=aCollection;
  505. return self}
  506. }),
  507. smalltalk.TestSuiteRunner);
  508. smalltalk.addMethod(
  509. "_new",
  510. smalltalk.method({
  511. selector: "new",
  512. fn: function (){
  513. var self=this;
  514. smalltalk.send(self,"_shouldNotImplement",[]);
  515. return self}
  516. }),
  517. smalltalk.TestSuiteRunner.klass);
  518. smalltalk.addMethod(
  519. "_on_",
  520. smalltalk.method({
  521. selector: "on:",
  522. fn: function (aCollection){
  523. var self=this;
  524. var $1;
  525. $1=smalltalk.send(smalltalk.send(self,"_new",[],smalltalk.Object.klass),"_suite_",[aCollection]);
  526. return $1;
  527. }
  528. }),
  529. smalltalk.TestSuiteRunner.klass);