SUnit.deploy.js 15 KB

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