1
0

SUnit.deploy.js 15 KB

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