SUnit.deploy.js 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429
  1. smalltalk.addPackage('SUnit', {});
  2. smalltalk.addClass('TestCase', smalltalk.Object, ['testSelector'], 'SUnit');
  3. smalltalk.addMethod(
  4. "_assert_",
  5. smalltalk.method({
  6. selector: "assert:",
  7. fn: function (aBoolean){
  8. var self=this;
  9. smalltalk.send(self,"_assert_description_",[aBoolean,"Assertion failed"]);
  10. return self}
  11. }),
  12. smalltalk.TestCase);
  13. smalltalk.addMethod(
  14. "_assert_description_",
  15. smalltalk.method({
  16. selector: "assert:description:",
  17. fn: function (aBoolean,aString){
  18. var self=this;
  19. if(! smalltalk.assert(aBoolean)){
  20. smalltalk.send(self,"_signalFailure_",[aString]);
  21. };
  22. return self}
  23. }),
  24. smalltalk.TestCase);
  25. smalltalk.addMethod(
  26. "_assert_equals_",
  27. smalltalk.method({
  28. selector: "assert:equals:",
  29. fn: function (expected,actual){
  30. var self=this;
  31. var $1;
  32. $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",[])])]);
  33. return $1;
  34. }
  35. }),
  36. smalltalk.TestCase);
  37. smalltalk.addMethod(
  38. "_deny_",
  39. smalltalk.method({
  40. selector: "deny:",
  41. fn: function (aBoolean){
  42. var self=this;
  43. smalltalk.send(self,"_assert_",[smalltalk.send(aBoolean,"_not",[])]);
  44. return self}
  45. }),
  46. smalltalk.TestCase);
  47. smalltalk.addMethod(
  48. "_performTestFor_",
  49. smalltalk.method({
  50. selector: "performTestFor:",
  51. fn: function (aResult){
  52. var self=this;
  53. smalltalk.send((function(){
  54. return smalltalk.send((function(){
  55. return smalltalk.send(self,"_perform_",[smalltalk.send(self,"_selector",[])]);
  56. }),"_on_do_",[(smalltalk.TestFailure || TestFailure),(function(ex){
  57. return smalltalk.send(aResult,"_addFailure_",[self]);
  58. })]);
  59. }),"_on_do_",[(smalltalk.Error || Error),(function(ex){
  60. return smalltalk.send(aResult,"_addError_",[self]);
  61. })]);
  62. return self}
  63. }),
  64. smalltalk.TestCase);
  65. smalltalk.addMethod(
  66. "_runCaseFor_",
  67. smalltalk.method({
  68. selector: "runCaseFor:",
  69. fn: function (aTestResult){
  70. var self=this;
  71. smalltalk.send(self,"_setUp",[]);
  72. smalltalk.send(aTestResult,"_increaseRuns",[]);
  73. smalltalk.send(self,"_performTestFor_",[aTestResult]);
  74. smalltalk.send(self,"_tearDown",[]);
  75. return self}
  76. }),
  77. smalltalk.TestCase);
  78. smalltalk.addMethod(
  79. "_selector",
  80. smalltalk.method({
  81. selector: "selector",
  82. fn: function (){
  83. var self=this;
  84. return self["@testSelector"];
  85. }
  86. }),
  87. smalltalk.TestCase);
  88. smalltalk.addMethod(
  89. "_setTestSelector_",
  90. smalltalk.method({
  91. selector: "setTestSelector:",
  92. fn: function (aSelector){
  93. var self=this;
  94. self["@testSelector"]=aSelector;
  95. return self}
  96. }),
  97. smalltalk.TestCase);
  98. smalltalk.addMethod(
  99. "_setUp",
  100. smalltalk.method({
  101. selector: "setUp",
  102. fn: function (){
  103. var self=this;
  104. return self}
  105. }),
  106. smalltalk.TestCase);
  107. smalltalk.addMethod(
  108. "_should_",
  109. smalltalk.method({
  110. selector: "should:",
  111. fn: function (aBlock){
  112. var self=this;
  113. smalltalk.send(self,"_assert_",[smalltalk.send(aBlock,"_value",[])]);
  114. return self}
  115. }),
  116. smalltalk.TestCase);
  117. smalltalk.addMethod(
  118. "_should_raise_",
  119. smalltalk.method({
  120. selector: "should:raise:",
  121. fn: function (aBlock,anExceptionClass){
  122. var self=this;
  123. smalltalk.send(self,"_assert_",[smalltalk.send((function(){
  124. smalltalk.send(aBlock,"_value",[]);
  125. return false;
  126. }),"_on_do_",[anExceptionClass,(function(ex){
  127. return true;
  128. })])]);
  129. return self}
  130. }),
  131. smalltalk.TestCase);
  132. smalltalk.addMethod(
  133. "_shouldnt_raise_",
  134. smalltalk.method({
  135. selector: "shouldnt:raise:",
  136. fn: function (aBlock,anExceptionClass){
  137. var self=this;
  138. smalltalk.send(self,"_assert_",[smalltalk.send((function(){
  139. smalltalk.send(aBlock,"_value",[]);
  140. return true;
  141. }),"_on_do_",[anExceptionClass,(function(ex){
  142. return false;
  143. })])]);
  144. return self}
  145. }),
  146. smalltalk.TestCase);
  147. smalltalk.addMethod(
  148. "_signalFailure_",
  149. smalltalk.method({
  150. selector: "signalFailure:",
  151. fn: function (aString){
  152. var self=this;
  153. var $1,$2;
  154. $1=smalltalk.send((smalltalk.TestFailure || TestFailure),"_new",[]);
  155. smalltalk.send($1,"_messageText_",[aString]);
  156. $2=smalltalk.send($1,"_signal",[]);
  157. return self}
  158. }),
  159. smalltalk.TestCase);
  160. smalltalk.addMethod(
  161. "_tearDown",
  162. smalltalk.method({
  163. selector: "tearDown",
  164. fn: function (){
  165. var self=this;
  166. return self}
  167. }),
  168. smalltalk.TestCase);
  169. smalltalk.addMethod(
  170. "_allTestSelectors",
  171. smalltalk.method({
  172. selector: "allTestSelectors",
  173. fn: function (){
  174. var self=this;
  175. var $1;
  176. var selectors;
  177. selectors=smalltalk.send(self,"_testSelectors",[]);
  178. $1=smalltalk.send(self,"_shouldInheritSelectors",[]);
  179. if(smalltalk.assert($1)){
  180. smalltalk.send(selectors,"_addAll_",[smalltalk.send(smalltalk.send(self,"_superclass",[]),"_allTestSelectors",[])]);
  181. };
  182. return selectors;
  183. }
  184. }),
  185. smalltalk.TestCase.klass);
  186. smalltalk.addMethod(
  187. "_buildSuite",
  188. smalltalk.method({
  189. selector: "buildSuite",
  190. fn: function (){
  191. var self=this;
  192. var $1;
  193. $1=smalltalk.send(smalltalk.send(self,"_allTestSelectors",[]),"_collect_",[(function(each){
  194. return smalltalk.send(self,"_selector_",[each]);
  195. })]);
  196. return $1;
  197. }
  198. }),
  199. smalltalk.TestCase.klass);
  200. smalltalk.addMethod(
  201. "_isAbstract",
  202. smalltalk.method({
  203. selector: "isAbstract",
  204. fn: function (){
  205. var self=this;
  206. var $1;
  207. $1=smalltalk.send(smalltalk.send(self,"_name",[]),"__eq",["TestCase"]);
  208. return $1;
  209. }
  210. }),
  211. smalltalk.TestCase.klass);
  212. smalltalk.addMethod(
  213. "_lookupHierarchyRoot",
  214. smalltalk.method({
  215. selector: "lookupHierarchyRoot",
  216. fn: function (){
  217. var self=this;
  218. return (smalltalk.TestCase || TestCase);
  219. }
  220. }),
  221. smalltalk.TestCase.klass);
  222. smalltalk.addMethod(
  223. "_selector_",
  224. smalltalk.method({
  225. selector: "selector:",
  226. fn: function (aSelector){
  227. var self=this;
  228. var $2,$3,$1;
  229. $2=smalltalk.send(self,"_new",[]);
  230. smalltalk.send($2,"_setTestSelector_",[aSelector]);
  231. $3=smalltalk.send($2,"_yourself",[]);
  232. $1=$3;
  233. return $1;
  234. }
  235. }),
  236. smalltalk.TestCase.klass);
  237. smalltalk.addMethod(
  238. "_shouldInheritSelectors",
  239. smalltalk.method({
  240. selector: "shouldInheritSelectors",
  241. fn: function (){
  242. var self=this;
  243. var $1;
  244. $1=smalltalk.send(self,"_~_eq",[smalltalk.send(self,"_lookupHierarchyRoot",[])]);
  245. return $1;
  246. }
  247. }),
  248. smalltalk.TestCase.klass);
  249. smalltalk.addMethod(
  250. "_testSelectors",
  251. smalltalk.method({
  252. selector: "testSelectors",
  253. fn: function (){
  254. var self=this;
  255. var $1;
  256. $1=smalltalk.send(smalltalk.send(smalltalk.send(self,"_methodDictionary",[]),"_keys",[]),"_select_",[(function(each){
  257. return smalltalk.send(each,"_match_",["^test"]);
  258. })]);
  259. return $1;
  260. }
  261. }),
  262. smalltalk.TestCase.klass);
  263. smalltalk.addClass('TestFailure', smalltalk.Error, [], 'SUnit');
  264. smalltalk.addClass('TestResult', smalltalk.Object, ['timestamp', 'runs', 'errors', 'failures', 'total'], 'SUnit');
  265. smalltalk.addMethod(
  266. "_addError_",
  267. smalltalk.method({
  268. selector: "addError:",
  269. fn: function (anError){
  270. var self=this;
  271. smalltalk.send(smalltalk.send(self,"_errors",[]),"_add_",[anError]);
  272. return self}
  273. }),
  274. smalltalk.TestResult);
  275. smalltalk.addMethod(
  276. "_addFailure_",
  277. smalltalk.method({
  278. selector: "addFailure:",
  279. fn: function (aFailure){
  280. var self=this;
  281. smalltalk.send(smalltalk.send(self,"_failures",[]),"_add_",[aFailure]);
  282. return self}
  283. }),
  284. smalltalk.TestResult);
  285. smalltalk.addMethod(
  286. "_errors",
  287. smalltalk.method({
  288. selector: "errors",
  289. fn: function (){
  290. var self=this;
  291. return self["@errors"];
  292. }
  293. }),
  294. smalltalk.TestResult);
  295. smalltalk.addMethod(
  296. "_failures",
  297. smalltalk.method({
  298. selector: "failures",
  299. fn: function (){
  300. var self=this;
  301. return self["@failures"];
  302. }
  303. }),
  304. smalltalk.TestResult);
  305. smalltalk.addMethod(
  306. "_increaseRuns",
  307. smalltalk.method({
  308. selector: "increaseRuns",
  309. fn: function (){
  310. var self=this;
  311. self["@runs"]=smalltalk.send(self["@runs"],"__plus",[(1)]);
  312. return self}
  313. }),
  314. smalltalk.TestResult);
  315. smalltalk.addMethod(
  316. "_initialize",
  317. smalltalk.method({
  318. selector: "initialize",
  319. fn: function (){
  320. var self=this;
  321. smalltalk.send(self,"_initialize",[],smalltalk.Object);
  322. self["@timestamp"]=smalltalk.send((smalltalk.Date || Date),"_now",[]);
  323. self["@runs"]=(0);
  324. self["@errors"]=smalltalk.send((smalltalk.Array || Array),"_new",[]);
  325. self["@failures"]=smalltalk.send((smalltalk.Array || Array),"_new",[]);
  326. self["@total"]=(0);
  327. return self}
  328. }),
  329. smalltalk.TestResult);
  330. smalltalk.addMethod(
  331. "_runs",
  332. smalltalk.method({
  333. selector: "runs",
  334. fn: function (){
  335. var self=this;
  336. return self["@runs"];
  337. }
  338. }),
  339. smalltalk.TestResult);
  340. smalltalk.addMethod(
  341. "_status",
  342. smalltalk.method({
  343. selector: "status",
  344. fn: function (){
  345. var self=this;
  346. var $2,$3,$1;
  347. $2=smalltalk.send(smalltalk.send(self,"_errors",[]),"_isEmpty",[]);
  348. if(smalltalk.assert($2)){
  349. $3=smalltalk.send(smalltalk.send(self,"_failures",[]),"_isEmpty",[]);
  350. if(smalltalk.assert($3)){
  351. $1="success";
  352. } else {
  353. $1="failure";
  354. };
  355. } else {
  356. $1="error";
  357. };
  358. return $1;
  359. }
  360. }),
  361. smalltalk.TestResult);
  362. smalltalk.addMethod(
  363. "_timestamp",
  364. smalltalk.method({
  365. selector: "timestamp",
  366. fn: function (){
  367. var self=this;
  368. return self["@timestamp"];
  369. }
  370. }),
  371. smalltalk.TestResult);
  372. smalltalk.addMethod(
  373. "_total",
  374. smalltalk.method({
  375. selector: "total",
  376. fn: function (){
  377. var self=this;
  378. return self["@total"];
  379. }
  380. }),
  381. smalltalk.TestResult);
  382. smalltalk.addMethod(
  383. "_total_",
  384. smalltalk.method({
  385. selector: "total:",
  386. fn: function (aNumber){
  387. var self=this;
  388. self["@total"]=aNumber;
  389. return self}
  390. }),
  391. smalltalk.TestResult);