SUnit.js 43 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251
  1. define("amber_core/SUnit", ["amber_vm/smalltalk", "amber_vm/nil", "amber_vm/_st", "amber_core/Kernel-Objects", "amber_core/Kernel-Exceptions"], function(smalltalk,nil,_st){
  2. smalltalk.addPackage('SUnit');
  3. smalltalk.packages["SUnit"].transport = {"type":"amd","amdNamespace":"amber_core"};
  4. smalltalk.addClass('ResultAnnouncement', smalltalk.Object, ['result'], 'SUnit');
  5. smalltalk.ResultAnnouncement.comment="I get signaled when a `TestCase` has been run.\x0a\x0aMy instances hold the result (instance of `TestResult`) of the test run.";
  6. smalltalk.addMethod(
  7. smalltalk.method({
  8. selector: "result",
  9. category: 'accessing',
  10. fn: function (){
  11. var self=this;
  12. return smalltalk.withContext(function($ctx1) {
  13. var $1;
  14. $1=self["@result"];
  15. return $1;
  16. }, function($ctx1) {$ctx1.fill(self,"result",{},smalltalk.ResultAnnouncement)})},
  17. args: [],
  18. source: "result\x0a\x09^ result",
  19. messageSends: [],
  20. referencedClasses: []
  21. }),
  22. smalltalk.ResultAnnouncement);
  23. smalltalk.addMethod(
  24. smalltalk.method({
  25. selector: "result:",
  26. category: 'accessing',
  27. fn: function (aTestResult){
  28. var self=this;
  29. return smalltalk.withContext(function($ctx1) {
  30. self["@result"]=aTestResult;
  31. return self}, function($ctx1) {$ctx1.fill(self,"result:",{aTestResult:aTestResult},smalltalk.ResultAnnouncement)})},
  32. args: ["aTestResult"],
  33. source: "result: aTestResult\x0a\x09result := aTestResult",
  34. messageSends: [],
  35. referencedClasses: []
  36. }),
  37. smalltalk.ResultAnnouncement);
  38. smalltalk.addClass('TestCase', smalltalk.Object, ['testSelector', 'asyncTimeout', 'context'], 'SUnit');
  39. smalltalk.TestCase.comment="I am an implementation of the command pattern to run a test.\x0a\x0a## API\x0a\x0aMy instances are created with the class method `#selector:`,\x0apassing the symbol that names the method to be executed when the test case runs.\x0a\x0aWhen you discover a new fixture, subclass `TestCase` and create a `#test...` method for the first test.\x0aAs that method develops and more `#test...` methods are added, you will find yourself refactoring temps\x0ainto instance variables for the objects in the fixture and overriding `#setUp` to initialize these variables.\x0aAs required, override `#tearDown` to nil references, release objects and deallocate.";
  40. smalltalk.addMethod(
  41. smalltalk.method({
  42. selector: "assert:",
  43. category: 'testing',
  44. fn: function (aBoolean){
  45. var self=this;
  46. return smalltalk.withContext(function($ctx1) {
  47. self._assert_description_(aBoolean,"Assertion failed");
  48. return self}, function($ctx1) {$ctx1.fill(self,"assert:",{aBoolean:aBoolean},smalltalk.TestCase)})},
  49. args: ["aBoolean"],
  50. source: "assert: aBoolean\x0a\x09self assert: aBoolean description: 'Assertion failed'",
  51. messageSends: ["assert:description:"],
  52. referencedClasses: []
  53. }),
  54. smalltalk.TestCase);
  55. smalltalk.addMethod(
  56. smalltalk.method({
  57. selector: "assert:description:",
  58. category: 'testing',
  59. fn: function (aBoolean,aString){
  60. var self=this;
  61. return smalltalk.withContext(function($ctx1) {
  62. if(! smalltalk.assert(aBoolean)){
  63. self._signalFailure_(aString);
  64. };
  65. return self}, function($ctx1) {$ctx1.fill(self,"assert:description:",{aBoolean:aBoolean,aString:aString},smalltalk.TestCase)})},
  66. args: ["aBoolean", "aString"],
  67. source: "assert: aBoolean description: aString\x0a\x09aBoolean ifFalse: [ self signalFailure: aString ]",
  68. messageSends: ["ifFalse:", "signalFailure:"],
  69. referencedClasses: []
  70. }),
  71. smalltalk.TestCase);
  72. smalltalk.addMethod(
  73. smalltalk.method({
  74. selector: "assert:equals:",
  75. category: 'testing',
  76. fn: function (actual,expected){
  77. var self=this;
  78. return smalltalk.withContext(function($ctx1) {
  79. var $2,$6,$5,$4,$3,$1;
  80. $2=_st(actual).__eq(expected);
  81. $6=_st(expected)._printString();
  82. $ctx1.sendIdx["printString"]=1;
  83. $5="Expected: ".__comma($6);
  84. $4=_st($5).__comma(" but was: ");
  85. $ctx1.sendIdx[","]=2;
  86. $3=_st($4).__comma(_st(actual)._printString());
  87. $ctx1.sendIdx[","]=1;
  88. $1=self._assert_description_($2,$3);
  89. return $1;
  90. }, function($ctx1) {$ctx1.fill(self,"assert:equals:",{actual:actual,expected:expected},smalltalk.TestCase)})},
  91. args: ["actual", "expected"],
  92. source: "assert: actual equals: expected\x0a\x09^ self assert: (actual = expected) description: 'Expected: ', expected printString, ' but was: ', actual printString",
  93. messageSends: ["assert:description:", "=", ",", "printString"],
  94. referencedClasses: []
  95. }),
  96. smalltalk.TestCase);
  97. smalltalk.addMethod(
  98. smalltalk.method({
  99. selector: "async:",
  100. category: 'async',
  101. fn: function (aBlock){
  102. var self=this;
  103. var c;
  104. return smalltalk.withContext(function($ctx1) {
  105. var $2,$1;
  106. self._errorIfNotAsync_("#async");
  107. c=self["@context"];
  108. $1=(function(){
  109. return smalltalk.withContext(function($ctx2) {
  110. $2=self._isAsync();
  111. if(smalltalk.assert($2)){
  112. return _st(c)._execute_(aBlock);
  113. };
  114. }, function($ctx2) {$ctx2.fillBlock({},$ctx1,1)})});
  115. return $1;
  116. }, function($ctx1) {$ctx1.fill(self,"async:",{aBlock:aBlock,c:c},smalltalk.TestCase)})},
  117. args: ["aBlock"],
  118. source: "async: aBlock\x0a\x09| c |\x0a\x09self errorIfNotAsync: '#async'.\x0a\x09c := context.\x0a\x09^ [ self isAsync ifTrue: [ c execute: aBlock ] ]",
  119. messageSends: ["errorIfNotAsync:", "ifTrue:", "isAsync", "execute:"],
  120. referencedClasses: []
  121. }),
  122. smalltalk.TestCase);
  123. smalltalk.addMethod(
  124. smalltalk.method({
  125. selector: "context:",
  126. category: 'accessing',
  127. fn: function (aRunningTestContext){
  128. var self=this;
  129. return smalltalk.withContext(function($ctx1) {
  130. self["@context"]=aRunningTestContext;
  131. return self}, function($ctx1) {$ctx1.fill(self,"context:",{aRunningTestContext:aRunningTestContext},smalltalk.TestCase)})},
  132. args: ["aRunningTestContext"],
  133. source: "context: aRunningTestContext\x0a\x09context := aRunningTestContext",
  134. messageSends: [],
  135. referencedClasses: []
  136. }),
  137. smalltalk.TestCase);
  138. smalltalk.addMethod(
  139. smalltalk.method({
  140. selector: "deny:",
  141. category: 'testing',
  142. fn: function (aBoolean){
  143. var self=this;
  144. return smalltalk.withContext(function($ctx1) {
  145. self._assert_(_st(aBoolean)._not());
  146. return self}, function($ctx1) {$ctx1.fill(self,"deny:",{aBoolean:aBoolean},smalltalk.TestCase)})},
  147. args: ["aBoolean"],
  148. source: "deny: aBoolean\x0a\x09self assert: aBoolean not",
  149. messageSends: ["assert:", "not"],
  150. referencedClasses: []
  151. }),
  152. smalltalk.TestCase);
  153. smalltalk.addMethod(
  154. smalltalk.method({
  155. selector: "errorIfNotAsync:",
  156. category: 'error handling',
  157. fn: function (aString){
  158. var self=this;
  159. return smalltalk.withContext(function($ctx1) {
  160. var $1;
  161. $1=self._isAsync();
  162. if(! smalltalk.assert($1)){
  163. self._error_(_st(aString).__comma(" used without prior #timeout:"));
  164. };
  165. return self}, function($ctx1) {$ctx1.fill(self,"errorIfNotAsync:",{aString:aString},smalltalk.TestCase)})},
  166. args: ["aString"],
  167. source: "errorIfNotAsync: aString\x0a\x09self isAsync ifFalse: [\x0a\x09\x09self error: aString, ' used without prior #timeout:' ]",
  168. messageSends: ["ifFalse:", "isAsync", "error:", ","],
  169. referencedClasses: []
  170. }),
  171. smalltalk.TestCase);
  172. smalltalk.addMethod(
  173. smalltalk.method({
  174. selector: "finished",
  175. category: 'async',
  176. fn: function (){
  177. var self=this;
  178. return smalltalk.withContext(function($ctx1) {
  179. self._errorIfNotAsync_("#finished");
  180. self["@asyncTimeout"]=nil;
  181. return self}, function($ctx1) {$ctx1.fill(self,"finished",{},smalltalk.TestCase)})},
  182. args: [],
  183. source: "finished\x0a\x09self errorIfNotAsync: '#finished'.\x0a\x09asyncTimeout := nil",
  184. messageSends: ["errorIfNotAsync:"],
  185. referencedClasses: []
  186. }),
  187. smalltalk.TestCase);
  188. smalltalk.addMethod(
  189. smalltalk.method({
  190. selector: "isAsync",
  191. category: 'testing',
  192. fn: function (){
  193. var self=this;
  194. return smalltalk.withContext(function($ctx1) {
  195. var $1;
  196. $1=_st(self["@asyncTimeout"])._notNil();
  197. return $1;
  198. }, function($ctx1) {$ctx1.fill(self,"isAsync",{},smalltalk.TestCase)})},
  199. args: [],
  200. source: "isAsync\x0a\x09^ asyncTimeout notNil",
  201. messageSends: ["notNil"],
  202. referencedClasses: []
  203. }),
  204. smalltalk.TestCase);
  205. smalltalk.addMethod(
  206. smalltalk.method({
  207. selector: "performTest",
  208. category: 'running',
  209. fn: function (){
  210. var self=this;
  211. return smalltalk.withContext(function($ctx1) {
  212. self["@asyncTimeout"]=nil;
  213. self._perform_(self._selector());
  214. return self}, function($ctx1) {$ctx1.fill(self,"performTest",{},smalltalk.TestCase)})},
  215. args: [],
  216. source: "performTest\x0a\x09asyncTimeout := nil.\x0a\x09self perform: self selector",
  217. messageSends: ["perform:", "selector"],
  218. referencedClasses: []
  219. }),
  220. smalltalk.TestCase);
  221. smalltalk.addMethod(
  222. smalltalk.method({
  223. selector: "runCase",
  224. category: 'running',
  225. fn: function (){
  226. var self=this;
  227. function $TestContext(){return smalltalk.TestContext||(typeof TestContext=="undefined"?nil:TestContext)}
  228. return smalltalk.withContext(function($ctx1) {
  229. _st(_st($TestContext())._testCase_(self))._start();
  230. return self}, function($ctx1) {$ctx1.fill(self,"runCase",{},smalltalk.TestCase)})},
  231. args: [],
  232. source: "runCase\x0a\x09\x22Runs a test case in isolated context, leaking all errors.\x22\x0a\x0a\x09(TestContext testCase: self) start",
  233. messageSends: ["start", "testCase:"],
  234. referencedClasses: ["TestContext"]
  235. }),
  236. smalltalk.TestCase);
  237. smalltalk.addMethod(
  238. smalltalk.method({
  239. selector: "selector",
  240. category: 'accessing',
  241. fn: function (){
  242. var self=this;
  243. return smalltalk.withContext(function($ctx1) {
  244. var $1;
  245. $1=self["@testSelector"];
  246. return $1;
  247. }, function($ctx1) {$ctx1.fill(self,"selector",{},smalltalk.TestCase)})},
  248. args: [],
  249. source: "selector\x0a\x09^ testSelector",
  250. messageSends: [],
  251. referencedClasses: []
  252. }),
  253. smalltalk.TestCase);
  254. smalltalk.addMethod(
  255. smalltalk.method({
  256. selector: "setTestSelector:",
  257. category: 'accessing',
  258. fn: function (aSelector){
  259. var self=this;
  260. return smalltalk.withContext(function($ctx1) {
  261. self["@testSelector"]=aSelector;
  262. return self}, function($ctx1) {$ctx1.fill(self,"setTestSelector:",{aSelector:aSelector},smalltalk.TestCase)})},
  263. args: ["aSelector"],
  264. source: "setTestSelector: aSelector\x0a\x09testSelector := aSelector",
  265. messageSends: [],
  266. referencedClasses: []
  267. }),
  268. smalltalk.TestCase);
  269. smalltalk.addMethod(
  270. smalltalk.method({
  271. selector: "setUp",
  272. category: 'running',
  273. fn: function (){
  274. var self=this;
  275. return smalltalk.withContext(function($ctx1) {
  276. return self}, function($ctx1) {$ctx1.fill(self,"setUp",{},smalltalk.TestCase)})},
  277. args: [],
  278. source: "setUp",
  279. messageSends: [],
  280. referencedClasses: []
  281. }),
  282. smalltalk.TestCase);
  283. smalltalk.addMethod(
  284. smalltalk.method({
  285. selector: "should:",
  286. category: 'testing',
  287. fn: function (aBlock){
  288. var self=this;
  289. return smalltalk.withContext(function($ctx1) {
  290. self._assert_(_st(aBlock)._value());
  291. return self}, function($ctx1) {$ctx1.fill(self,"should:",{aBlock:aBlock},smalltalk.TestCase)})},
  292. args: ["aBlock"],
  293. source: "should: aBlock\x0a\x09self assert: aBlock value",
  294. messageSends: ["assert:", "value"],
  295. referencedClasses: []
  296. }),
  297. smalltalk.TestCase);
  298. smalltalk.addMethod(
  299. smalltalk.method({
  300. selector: "should:raise:",
  301. category: 'testing',
  302. fn: function (aBlock,anExceptionClass){
  303. var self=this;
  304. return smalltalk.withContext(function($ctx1) {
  305. self._assert_(_st((function(){
  306. return smalltalk.withContext(function($ctx2) {
  307. _st(aBlock)._value();
  308. return false;
  309. }, function($ctx2) {$ctx2.fillBlock({},$ctx1,1)})}))._on_do_(anExceptionClass,(function(ex){
  310. return smalltalk.withContext(function($ctx2) {
  311. return true;
  312. }, function($ctx2) {$ctx2.fillBlock({ex:ex},$ctx1,2)})})));
  313. return self}, function($ctx1) {$ctx1.fill(self,"should:raise:",{aBlock:aBlock,anExceptionClass:anExceptionClass},smalltalk.TestCase)})},
  314. args: ["aBlock", "anExceptionClass"],
  315. source: "should: aBlock raise: anExceptionClass\x0a\x09self assert: ([ aBlock value. false ]\x0a\x09\x09on: anExceptionClass\x0a\x09\x09do: [ :ex | true ])",
  316. messageSends: ["assert:", "on:do:", "value"],
  317. referencedClasses: []
  318. }),
  319. smalltalk.TestCase);
  320. smalltalk.addMethod(
  321. smalltalk.method({
  322. selector: "shouldnt:raise:",
  323. category: 'testing',
  324. fn: function (aBlock,anExceptionClass){
  325. var self=this;
  326. return smalltalk.withContext(function($ctx1) {
  327. self._assert_(_st((function(){
  328. return smalltalk.withContext(function($ctx2) {
  329. _st(aBlock)._value();
  330. return true;
  331. }, function($ctx2) {$ctx2.fillBlock({},$ctx1,1)})}))._on_do_(anExceptionClass,(function(ex){
  332. return smalltalk.withContext(function($ctx2) {
  333. return false;
  334. }, function($ctx2) {$ctx2.fillBlock({ex:ex},$ctx1,2)})})));
  335. return self}, function($ctx1) {$ctx1.fill(self,"shouldnt:raise:",{aBlock:aBlock,anExceptionClass:anExceptionClass},smalltalk.TestCase)})},
  336. args: ["aBlock", "anExceptionClass"],
  337. source: "shouldnt: aBlock raise: anExceptionClass\x0a\x09self assert: ([ aBlock value. true ]\x0a\x09\x09on: anExceptionClass\x0a\x09\x09do: [ :ex | false ])",
  338. messageSends: ["assert:", "on:do:", "value"],
  339. referencedClasses: []
  340. }),
  341. smalltalk.TestCase);
  342. smalltalk.addMethod(
  343. smalltalk.method({
  344. selector: "signalFailure:",
  345. category: 'private',
  346. fn: function (aString){
  347. var self=this;
  348. function $TestFailure(){return smalltalk.TestFailure||(typeof TestFailure=="undefined"?nil:TestFailure)}
  349. return smalltalk.withContext(function($ctx1) {
  350. var $1,$2;
  351. $1=_st($TestFailure())._new();
  352. _st($1)._messageText_(aString);
  353. $2=_st($1)._signal();
  354. return self}, function($ctx1) {$ctx1.fill(self,"signalFailure:",{aString:aString},smalltalk.TestCase)})},
  355. args: ["aString"],
  356. source: "signalFailure: aString\x0a\x09TestFailure new\x0a\x09\x09messageText: aString;\x0a\x09\x09signal",
  357. messageSends: ["messageText:", "new", "signal"],
  358. referencedClasses: ["TestFailure"]
  359. }),
  360. smalltalk.TestCase);
  361. smalltalk.addMethod(
  362. smalltalk.method({
  363. selector: "tearDown",
  364. category: 'running',
  365. fn: function (){
  366. var self=this;
  367. return smalltalk.withContext(function($ctx1) {
  368. return self}, function($ctx1) {$ctx1.fill(self,"tearDown",{},smalltalk.TestCase)})},
  369. args: [],
  370. source: "tearDown",
  371. messageSends: [],
  372. referencedClasses: []
  373. }),
  374. smalltalk.TestCase);
  375. smalltalk.addMethod(
  376. smalltalk.method({
  377. selector: "timeout:",
  378. category: 'async',
  379. fn: function (aNumber){
  380. var self=this;
  381. return smalltalk.withContext(function($ctx1) {
  382. var $1;
  383. $1=self["@asyncTimeout"];
  384. if(($receiver = $1) == nil || $receiver == null){
  385. $1;
  386. } else {
  387. _st(self["@asyncTimeout"])._clearTimeout();
  388. };
  389. self["@asyncTimeout"]=(0);
  390. self["@asyncTimeout"]=_st(self._async_((function(){
  391. return smalltalk.withContext(function($ctx2) {
  392. return self._assert_description_(false,"SUnit grace time exhausted");
  393. }, function($ctx2) {$ctx2.fillBlock({},$ctx1,2)})})))._valueWithTimeout_(aNumber);
  394. return self}, function($ctx1) {$ctx1.fill(self,"timeout:",{aNumber:aNumber},smalltalk.TestCase)})},
  395. args: ["aNumber"],
  396. source: "timeout: aNumber\x0a\x09\x22Set a grace time timeout in milliseconds to run the test asynchronously\x22\x0a\x09\x0a\x09asyncTimeout ifNotNil: [ asyncTimeout clearTimeout ].\x0a\x09\x0a\x09\x22to allow #async: message send without throwing an error\x22\x0a\x09asyncTimeout := 0.\x0a\x09\x0a\x09asyncTimeout := (self async: [\x0a\x09\x09self assert: false description: 'SUnit grace time exhausted' ])\x0a\x09\x09\x09valueWithTimeout: aNumber",
  397. messageSends: ["ifNotNil:", "clearTimeout", "valueWithTimeout:", "async:", "assert:description:"],
  398. referencedClasses: []
  399. }),
  400. smalltalk.TestCase);
  401. smalltalk.addMethod(
  402. smalltalk.method({
  403. selector: "allTestSelectors",
  404. category: 'accessing',
  405. fn: function (){
  406. var self=this;
  407. var selectors;
  408. return smalltalk.withContext(function($ctx1) {
  409. var $1,$2;
  410. selectors=self._testSelectors();
  411. $1=self._shouldInheritSelectors();
  412. if(smalltalk.assert($1)){
  413. _st(selectors)._addAll_(_st(self._superclass())._allTestSelectors());
  414. };
  415. $2=selectors;
  416. return $2;
  417. }, function($ctx1) {$ctx1.fill(self,"allTestSelectors",{selectors:selectors},smalltalk.TestCase.klass)})},
  418. args: [],
  419. source: "allTestSelectors\x0a\x09| selectors |\x0a\x09selectors := self testSelectors.\x0a\x09self shouldInheritSelectors ifTrue: [\x0a\x09\x09selectors addAll: self superclass allTestSelectors ].\x0a\x09^ selectors",
  420. messageSends: ["testSelectors", "ifTrue:", "shouldInheritSelectors", "addAll:", "allTestSelectors", "superclass"],
  421. referencedClasses: []
  422. }),
  423. smalltalk.TestCase.klass);
  424. smalltalk.addMethod(
  425. smalltalk.method({
  426. selector: "buildSuite",
  427. category: 'accessing',
  428. fn: function (){
  429. var self=this;
  430. return smalltalk.withContext(function($ctx1) {
  431. var $1;
  432. $1=_st(self._allTestSelectors())._collect_((function(each){
  433. return smalltalk.withContext(function($ctx2) {
  434. return self._selector_(each);
  435. }, function($ctx2) {$ctx2.fillBlock({each:each},$ctx1,1)})}));
  436. return $1;
  437. }, function($ctx1) {$ctx1.fill(self,"buildSuite",{},smalltalk.TestCase.klass)})},
  438. args: [],
  439. source: "buildSuite\x0a\x09^ self allTestSelectors collect: [ :each | self selector: each ]",
  440. messageSends: ["collect:", "allTestSelectors", "selector:"],
  441. referencedClasses: []
  442. }),
  443. smalltalk.TestCase.klass);
  444. smalltalk.addMethod(
  445. smalltalk.method({
  446. selector: "heliosClass",
  447. category: 'helios',
  448. fn: function (){
  449. var self=this;
  450. return smalltalk.withContext(function($ctx1) {
  451. return "test";
  452. }, function($ctx1) {$ctx1.fill(self,"heliosClass",{},smalltalk.TestCase.klass)})},
  453. args: [],
  454. source: "heliosClass\x0a\x09^ 'test'",
  455. messageSends: [],
  456. referencedClasses: []
  457. }),
  458. smalltalk.TestCase.klass);
  459. smalltalk.addMethod(
  460. smalltalk.method({
  461. selector: "isAbstract",
  462. category: 'testing',
  463. fn: function (){
  464. var self=this;
  465. return smalltalk.withContext(function($ctx1) {
  466. var $1;
  467. $1=_st(self._name()).__eq("TestCase");
  468. return $1;
  469. }, function($ctx1) {$ctx1.fill(self,"isAbstract",{},smalltalk.TestCase.klass)})},
  470. args: [],
  471. source: "isAbstract\x0a\x09^ self name = 'TestCase'",
  472. messageSends: ["=", "name"],
  473. referencedClasses: []
  474. }),
  475. smalltalk.TestCase.klass);
  476. smalltalk.addMethod(
  477. smalltalk.method({
  478. selector: "lookupHierarchyRoot",
  479. category: 'accessing',
  480. fn: function (){
  481. var self=this;
  482. function $TestCase(){return smalltalk.TestCase||(typeof TestCase=="undefined"?nil:TestCase)}
  483. return smalltalk.withContext(function($ctx1) {
  484. return $TestCase();
  485. }, function($ctx1) {$ctx1.fill(self,"lookupHierarchyRoot",{},smalltalk.TestCase.klass)})},
  486. args: [],
  487. source: "lookupHierarchyRoot\x0a\x09^ TestCase",
  488. messageSends: [],
  489. referencedClasses: ["TestCase"]
  490. }),
  491. smalltalk.TestCase.klass);
  492. smalltalk.addMethod(
  493. smalltalk.method({
  494. selector: "selector:",
  495. category: 'accessing',
  496. fn: function (aSelector){
  497. var self=this;
  498. return smalltalk.withContext(function($ctx1) {
  499. var $2,$3,$1;
  500. $2=self._new();
  501. _st($2)._setTestSelector_(aSelector);
  502. $3=_st($2)._yourself();
  503. $1=$3;
  504. return $1;
  505. }, function($ctx1) {$ctx1.fill(self,"selector:",{aSelector:aSelector},smalltalk.TestCase.klass)})},
  506. args: ["aSelector"],
  507. source: "selector: aSelector\x0a\x09^ self new\x0a\x09\x09setTestSelector: aSelector;\x0a\x09\x09yourself",
  508. messageSends: ["setTestSelector:", "new", "yourself"],
  509. referencedClasses: []
  510. }),
  511. smalltalk.TestCase.klass);
  512. smalltalk.addMethod(
  513. smalltalk.method({
  514. selector: "shouldInheritSelectors",
  515. category: 'testing',
  516. fn: function (){
  517. var self=this;
  518. return smalltalk.withContext(function($ctx1) {
  519. var $1;
  520. $1=self.__tild_eq(self._lookupHierarchyRoot());
  521. return $1;
  522. }, function($ctx1) {$ctx1.fill(self,"shouldInheritSelectors",{},smalltalk.TestCase.klass)})},
  523. args: [],
  524. source: "shouldInheritSelectors\x0a\x09^ self ~= self lookupHierarchyRoot",
  525. messageSends: ["~=", "lookupHierarchyRoot"],
  526. referencedClasses: []
  527. }),
  528. smalltalk.TestCase.klass);
  529. smalltalk.addMethod(
  530. smalltalk.method({
  531. selector: "testSelectors",
  532. category: 'accessing',
  533. fn: function (){
  534. var self=this;
  535. return smalltalk.withContext(function($ctx1) {
  536. var $1;
  537. $1=_st(_st(self._methodDictionary())._keys())._select_((function(each){
  538. return smalltalk.withContext(function($ctx2) {
  539. return _st(each)._match_("^test");
  540. }, function($ctx2) {$ctx2.fillBlock({each:each},$ctx1,1)})}));
  541. return $1;
  542. }, function($ctx1) {$ctx1.fill(self,"testSelectors",{},smalltalk.TestCase.klass)})},
  543. args: [],
  544. source: "testSelectors\x0a\x09^ self methodDictionary keys select: [ :each | each match: '^test' ]",
  545. messageSends: ["select:", "keys", "methodDictionary", "match:"],
  546. referencedClasses: []
  547. }),
  548. smalltalk.TestCase.klass);
  549. smalltalk.addClass('TestContext', smalltalk.Object, ['testCase'], 'SUnit');
  550. smalltalk.TestContext.comment="I govern running a particular test case.\x0a\x0aMy main added value is `#execute:` method which runs a block as a part of test case (restores context, nilling it afterwards, cleaning/calling `#tearDown` as appropriate for sync/async scenario).";
  551. smalltalk.addMethod(
  552. smalltalk.method({
  553. selector: "execute:",
  554. category: 'running',
  555. fn: function (aBlock){
  556. var self=this;
  557. var failed;
  558. return smalltalk.withContext(function($ctx1) {
  559. var $1,$2;
  560. _st(self["@testCase"])._context_(self);
  561. $ctx1.sendIdx["context:"]=1;
  562. _st((function(){
  563. return smalltalk.withContext(function($ctx2) {
  564. failed=true;
  565. failed;
  566. _st(aBlock)._value();
  567. failed=false;
  568. return failed;
  569. }, function($ctx2) {$ctx2.fillBlock({},$ctx1,1)})}))._ensure_((function(){
  570. return smalltalk.withContext(function($ctx2) {
  571. _st(self["@testCase"])._context_(nil);
  572. $1=_st(failed)._and_((function(){
  573. return smalltalk.withContext(function($ctx3) {
  574. return _st(self["@testCase"])._isAsync();
  575. $ctx3.sendIdx["isAsync"]=1;
  576. }, function($ctx3) {$ctx3.fillBlock({},$ctx2,3)})}));
  577. if(smalltalk.assert($1)){
  578. _st(self["@testCase"])._finished();
  579. };
  580. $2=_st(self["@testCase"])._isAsync();
  581. if(! smalltalk.assert($2)){
  582. return _st(self["@testCase"])._tearDown();
  583. };
  584. }, function($ctx2) {$ctx2.fillBlock({},$ctx1,2)})}));
  585. return self}, function($ctx1) {$ctx1.fill(self,"execute:",{aBlock:aBlock,failed:failed},smalltalk.TestContext)})},
  586. args: ["aBlock"],
  587. source: "execute: aBlock\x0a\x09| failed |\x0a\x09\x0a\x09testCase context: self.\x0a\x09[\x0a\x09\x09failed := true.\x0a\x09\x09aBlock value.\x0a\x09\x09failed := false\x0a\x09]\x0a\x09\x09ensure: [\x0a\x09\x09\x09testCase context: nil.\x0a\x09\x09\x09\x0a\x09\x09\x09(failed and: [ testCase isAsync ]) ifTrue: [\x0a\x09\x09\x09\x09testCase finished ].\x0a\x09\x09\x09testCase isAsync ifFalse: [\x0a\x09\x09\x09\x09testCase tearDown ] ]",
  588. messageSends: ["context:", "ensure:", "value", "ifTrue:", "and:", "isAsync", "finished", "ifFalse:", "tearDown"],
  589. referencedClasses: []
  590. }),
  591. smalltalk.TestContext);
  592. smalltalk.addMethod(
  593. smalltalk.method({
  594. selector: "start",
  595. category: 'running',
  596. fn: function (){
  597. var self=this;
  598. return smalltalk.withContext(function($ctx1) {
  599. self._execute_((function(){
  600. return smalltalk.withContext(function($ctx2) {
  601. _st(self["@testCase"])._setUp();
  602. return _st(self["@testCase"])._performTest();
  603. }, function($ctx2) {$ctx2.fillBlock({},$ctx1,1)})}));
  604. return self}, function($ctx1) {$ctx1.fill(self,"start",{},smalltalk.TestContext)})},
  605. args: [],
  606. source: "start\x0a\x09self execute: [\x0a\x09\x09testCase setUp.\x0a\x09\x09testCase performTest ]",
  607. messageSends: ["execute:", "setUp", "performTest"],
  608. referencedClasses: []
  609. }),
  610. smalltalk.TestContext);
  611. smalltalk.addMethod(
  612. smalltalk.method({
  613. selector: "testCase:",
  614. category: 'accessing',
  615. fn: function (aTestCase){
  616. var self=this;
  617. return smalltalk.withContext(function($ctx1) {
  618. self["@testCase"]=aTestCase;
  619. return self}, function($ctx1) {$ctx1.fill(self,"testCase:",{aTestCase:aTestCase},smalltalk.TestContext)})},
  620. args: ["aTestCase"],
  621. source: "testCase: aTestCase\x0a\x09testCase := aTestCase",
  622. messageSends: [],
  623. referencedClasses: []
  624. }),
  625. smalltalk.TestContext);
  626. smalltalk.addMethod(
  627. smalltalk.method({
  628. selector: "testCase:",
  629. category: 'instance creation',
  630. fn: function (aTestCase){
  631. var self=this;
  632. return smalltalk.withContext(function($ctx1) {
  633. var $2,$3,$1;
  634. $2=self._new();
  635. _st($2)._testCase_(aTestCase);
  636. $3=_st($2)._yourself();
  637. $1=$3;
  638. return $1;
  639. }, function($ctx1) {$ctx1.fill(self,"testCase:",{aTestCase:aTestCase},smalltalk.TestContext.klass)})},
  640. args: ["aTestCase"],
  641. source: "testCase: aTestCase\x0a\x09^ self new\x0a\x09\x09testCase: aTestCase;\x0a\x09\x09yourself",
  642. messageSends: ["testCase:", "new", "yourself"],
  643. referencedClasses: []
  644. }),
  645. smalltalk.TestContext.klass);
  646. smalltalk.addClass('ReportingTestContext', smalltalk.TestContext, ['finished', 'result'], 'SUnit');
  647. smalltalk.ReportingTestContext.comment="I add `TestResult` reporting to `TestContext`.\x0a\x0aErrors are caught and save into a `TestResult`,\x0aWhen test case is finished (which can be later for async tests), a callback block is executed; this is used by a `TestSuiteRunner`.";
  648. smalltalk.addMethod(
  649. smalltalk.method({
  650. selector: "execute:",
  651. category: 'running',
  652. fn: function (aBlock){
  653. var self=this;
  654. return smalltalk.withContext(function($ctx1) {
  655. var $1;
  656. _st((function(){
  657. return smalltalk.withContext(function($ctx2) {
  658. return self._withErrorReporting_((function(){
  659. return smalltalk.withContext(function($ctx3) {
  660. return smalltalk.ReportingTestContext.superclass.fn.prototype._execute_.apply(_st(self), [aBlock]);
  661. }, function($ctx3) {$ctx3.fillBlock({},$ctx2,2)})}));
  662. }, function($ctx2) {$ctx2.fillBlock({},$ctx1,1)})}))._ensure_((function(){
  663. return smalltalk.withContext(function($ctx2) {
  664. $1=_st(self["@testCase"])._isAsync();
  665. if(! smalltalk.assert($1)){
  666. _st(self["@result"])._increaseRuns();
  667. return _st(self["@finished"])._value();
  668. };
  669. }, function($ctx2) {$ctx2.fillBlock({},$ctx1,3)})}));
  670. return self}, function($ctx1) {$ctx1.fill(self,"execute:",{aBlock:aBlock},smalltalk.ReportingTestContext)})},
  671. args: ["aBlock"],
  672. source: "execute: aBlock\x0a\x09[\x0a\x09\x09self withErrorReporting: [ super execute: aBlock ]\x0a\x09]\x0a\x09\x09ensure: [\x0a\x09\x09\x09testCase isAsync ifFalse: [\x0a\x09\x09\x09\x09result increaseRuns. finished value ] ]",
  673. messageSends: ["ensure:", "withErrorReporting:", "execute:", "ifFalse:", "isAsync", "increaseRuns", "value"],
  674. referencedClasses: []
  675. }),
  676. smalltalk.ReportingTestContext);
  677. smalltalk.addMethod(
  678. smalltalk.method({
  679. selector: "finished:",
  680. category: 'accessing',
  681. fn: function (aBlock){
  682. var self=this;
  683. return smalltalk.withContext(function($ctx1) {
  684. self["@finished"]=aBlock;
  685. return self}, function($ctx1) {$ctx1.fill(self,"finished:",{aBlock:aBlock},smalltalk.ReportingTestContext)})},
  686. args: ["aBlock"],
  687. source: "finished: aBlock\x0a\x09finished := aBlock",
  688. messageSends: [],
  689. referencedClasses: []
  690. }),
  691. smalltalk.ReportingTestContext);
  692. smalltalk.addMethod(
  693. smalltalk.method({
  694. selector: "result:",
  695. category: 'accessing',
  696. fn: function (aTestResult){
  697. var self=this;
  698. return smalltalk.withContext(function($ctx1) {
  699. self["@result"]=aTestResult;
  700. return self}, function($ctx1) {$ctx1.fill(self,"result:",{aTestResult:aTestResult},smalltalk.ReportingTestContext)})},
  701. args: ["aTestResult"],
  702. source: "result: aTestResult\x0a\x09result := aTestResult",
  703. messageSends: [],
  704. referencedClasses: []
  705. }),
  706. smalltalk.ReportingTestContext);
  707. smalltalk.addMethod(
  708. smalltalk.method({
  709. selector: "withErrorReporting:",
  710. category: 'private',
  711. fn: function (aBlock){
  712. var self=this;
  713. function $TestFailure(){return smalltalk.TestFailure||(typeof TestFailure=="undefined"?nil:TestFailure)}
  714. function $Error(){return smalltalk.Error||(typeof Error=="undefined"?nil:Error)}
  715. return smalltalk.withContext(function($ctx1) {
  716. _st((function(){
  717. return smalltalk.withContext(function($ctx2) {
  718. return _st(aBlock)._on_do_($TestFailure(),(function(ex){
  719. return smalltalk.withContext(function($ctx3) {
  720. return _st(self["@result"])._addFailure_(self["@testCase"]);
  721. }, function($ctx3) {$ctx3.fillBlock({ex:ex},$ctx2,2)})}));
  722. }, function($ctx2) {$ctx2.fillBlock({},$ctx1,1)})}))._on_do_($Error(),(function(ex){
  723. return smalltalk.withContext(function($ctx2) {
  724. return _st(self["@result"])._addError_(self["@testCase"]);
  725. }, function($ctx2) {$ctx2.fillBlock({ex:ex},$ctx1,3)})}));
  726. $ctx1.sendIdx["on:do:"]=1;
  727. return self}, function($ctx1) {$ctx1.fill(self,"withErrorReporting:",{aBlock:aBlock},smalltalk.ReportingTestContext)})},
  728. args: ["aBlock"],
  729. source: "withErrorReporting: aBlock\x0a\x09[ aBlock\x0a\x09\x09on: TestFailure\x0a\x09\x09do: [ :ex | result addFailure: testCase ]\x0a\x09]\x0a\x09\x09on: Error\x0a\x09\x09do: [ :ex | result addError: testCase ]",
  730. messageSends: ["on:do:", "addFailure:", "addError:"],
  731. referencedClasses: ["TestFailure", "Error"]
  732. }),
  733. smalltalk.ReportingTestContext);
  734. smalltalk.addMethod(
  735. smalltalk.method({
  736. selector: "testCase:result:finished:",
  737. category: 'instance creation',
  738. fn: function (aTestCase,aTestResult,aBlock){
  739. var self=this;
  740. return smalltalk.withContext(function($ctx1) {
  741. var $2,$3,$1;
  742. $2=smalltalk.ReportingTestContext.klass.superclass.fn.prototype._testCase_.apply(_st(self), [aTestCase]);
  743. _st($2)._result_(aTestResult);
  744. _st($2)._finished_(aBlock);
  745. $3=_st($2)._yourself();
  746. $1=$3;
  747. return $1;
  748. }, function($ctx1) {$ctx1.fill(self,"testCase:result:finished:",{aTestCase:aTestCase,aTestResult:aTestResult,aBlock:aBlock},smalltalk.ReportingTestContext.klass)})},
  749. args: ["aTestCase", "aTestResult", "aBlock"],
  750. source: "testCase: aTestCase result: aTestResult finished: aBlock\x0a\x09^ (super testCase: aTestCase)\x0a\x09\x09result: aTestResult;\x0a\x09\x09finished: aBlock;\x0a\x09\x09yourself",
  751. messageSends: ["result:", "testCase:", "finished:", "yourself"],
  752. referencedClasses: []
  753. }),
  754. smalltalk.ReportingTestContext.klass);
  755. smalltalk.addClass('TestFailure', smalltalk.Error, [], 'SUnit');
  756. smalltalk.TestFailure.comment="I am raised when the boolean parameter of an #`assert:` or `#deny:` call is the opposite of what the assertion claims.\x0a\x0aThe test framework distinguishes between failures and errors.\x0aA failure is an event whose possibiity is explicitly anticipated and checked for in an assertion,\x0awhereas an error is an unanticipated problem like a division by 0 or an index out of bounds.";
  757. smalltalk.addClass('TestResult', smalltalk.Object, ['timestamp', 'runs', 'errors', 'failures', 'total'], 'SUnit');
  758. smalltalk.TestResult.comment="I implement the collecting parameter pattern for running a bunch of tests.\x0a\x0aMy instances hold tests that have run, sorted into the result categories of passed, failures and errors.\x0a\x0a`TestResult` is an interesting object to subclass or substitute. `#runCase:` is the external protocol you need to reproduce";
  759. smalltalk.addMethod(
  760. smalltalk.method({
  761. selector: "addError:",
  762. category: 'accessing',
  763. fn: function (anError){
  764. var self=this;
  765. return smalltalk.withContext(function($ctx1) {
  766. _st(self._errors())._add_(anError);
  767. return self}, function($ctx1) {$ctx1.fill(self,"addError:",{anError:anError},smalltalk.TestResult)})},
  768. args: ["anError"],
  769. source: "addError: anError\x0a\x09self errors add: anError",
  770. messageSends: ["add:", "errors"],
  771. referencedClasses: []
  772. }),
  773. smalltalk.TestResult);
  774. smalltalk.addMethod(
  775. smalltalk.method({
  776. selector: "addFailure:",
  777. category: 'accessing',
  778. fn: function (aFailure){
  779. var self=this;
  780. return smalltalk.withContext(function($ctx1) {
  781. _st(self._failures())._add_(aFailure);
  782. return self}, function($ctx1) {$ctx1.fill(self,"addFailure:",{aFailure:aFailure},smalltalk.TestResult)})},
  783. args: ["aFailure"],
  784. source: "addFailure: aFailure\x0a\x09self failures add: aFailure",
  785. messageSends: ["add:", "failures"],
  786. referencedClasses: []
  787. }),
  788. smalltalk.TestResult);
  789. smalltalk.addMethod(
  790. smalltalk.method({
  791. selector: "errors",
  792. category: 'accessing',
  793. fn: function (){
  794. var self=this;
  795. return smalltalk.withContext(function($ctx1) {
  796. var $1;
  797. $1=self["@errors"];
  798. return $1;
  799. }, function($ctx1) {$ctx1.fill(self,"errors",{},smalltalk.TestResult)})},
  800. args: [],
  801. source: "errors\x0a\x09^ errors",
  802. messageSends: [],
  803. referencedClasses: []
  804. }),
  805. smalltalk.TestResult);
  806. smalltalk.addMethod(
  807. smalltalk.method({
  808. selector: "failures",
  809. category: 'accessing',
  810. fn: function (){
  811. var self=this;
  812. return smalltalk.withContext(function($ctx1) {
  813. var $1;
  814. $1=self["@failures"];
  815. return $1;
  816. }, function($ctx1) {$ctx1.fill(self,"failures",{},smalltalk.TestResult)})},
  817. args: [],
  818. source: "failures\x0a\x09^ failures",
  819. messageSends: [],
  820. referencedClasses: []
  821. }),
  822. smalltalk.TestResult);
  823. smalltalk.addMethod(
  824. smalltalk.method({
  825. selector: "increaseRuns",
  826. category: 'accessing',
  827. fn: function (){
  828. var self=this;
  829. return smalltalk.withContext(function($ctx1) {
  830. self["@runs"]=_st(self["@runs"]).__plus((1));
  831. return self}, function($ctx1) {$ctx1.fill(self,"increaseRuns",{},smalltalk.TestResult)})},
  832. args: [],
  833. source: "increaseRuns\x0a\x09runs := runs + 1",
  834. messageSends: ["+"],
  835. referencedClasses: []
  836. }),
  837. smalltalk.TestResult);
  838. smalltalk.addMethod(
  839. smalltalk.method({
  840. selector: "initialize",
  841. category: 'initialization',
  842. fn: function (){
  843. var self=this;
  844. function $Date(){return smalltalk.Date||(typeof Date=="undefined"?nil:Date)}
  845. function $Array(){return smalltalk.Array||(typeof Array=="undefined"?nil:Array)}
  846. return smalltalk.withContext(function($ctx1) {
  847. smalltalk.TestResult.superclass.fn.prototype._initialize.apply(_st(self), []);
  848. self["@timestamp"]=_st($Date())._now();
  849. self["@runs"]=(0);
  850. self["@errors"]=_st($Array())._new();
  851. $ctx1.sendIdx["new"]=1;
  852. self["@failures"]=_st($Array())._new();
  853. self["@total"]=(0);
  854. return self}, function($ctx1) {$ctx1.fill(self,"initialize",{},smalltalk.TestResult)})},
  855. args: [],
  856. source: "initialize\x0a\x09super initialize.\x0a\x09timestamp := Date now.\x0a\x09runs := 0.\x0a\x09errors := Array new.\x0a\x09failures := Array new.\x0a\x09total := 0",
  857. messageSends: ["initialize", "now", "new"],
  858. referencedClasses: ["Date", "Array"]
  859. }),
  860. smalltalk.TestResult);
  861. smalltalk.addMethod(
  862. smalltalk.method({
  863. selector: "nextRunDo:",
  864. category: 'running',
  865. fn: function (aBlock){
  866. var self=this;
  867. return smalltalk.withContext(function($ctx1) {
  868. var $3,$2,$1;
  869. $3=self._runs();
  870. $ctx1.sendIdx["runs"]=1;
  871. $2=_st($3).__eq_eq(self._total());
  872. if(! smalltalk.assert($2)){
  873. $1=_st(aBlock)._value_(_st(self._runs()).__plus((1)));
  874. };
  875. return $1;
  876. }, function($ctx1) {$ctx1.fill(self,"nextRunDo:",{aBlock:aBlock},smalltalk.TestResult)})},
  877. args: ["aBlock"],
  878. source: "nextRunDo: aBlock\x0a\x09\x22Runs aBlock with index of next run or does nothing if no more runs\x22\x0a\x09^ self runs == self total\x0a\x09\x09ifFalse: [ aBlock value: self runs + 1 ]",
  879. messageSends: ["ifFalse:", "==", "runs", "total", "value:", "+"],
  880. referencedClasses: []
  881. }),
  882. smalltalk.TestResult);
  883. smalltalk.addMethod(
  884. smalltalk.method({
  885. selector: "runCase:",
  886. category: 'running',
  887. fn: function (aTestCase){
  888. var self=this;
  889. function $TestFailure(){return smalltalk.TestFailure||(typeof TestFailure=="undefined"?nil:TestFailure)}
  890. function $Error(){return smalltalk.Error||(typeof Error=="undefined"?nil:Error)}
  891. return smalltalk.withContext(function($ctx1) {
  892. _st((function(){
  893. return smalltalk.withContext(function($ctx2) {
  894. return _st((function(){
  895. return smalltalk.withContext(function($ctx3) {
  896. self._increaseRuns();
  897. return _st(aTestCase)._runCase();
  898. }, function($ctx3) {$ctx3.fillBlock({},$ctx2,2)})}))._on_do_($TestFailure(),(function(ex){
  899. return smalltalk.withContext(function($ctx3) {
  900. return self._addFailure_(aTestCase);
  901. }, function($ctx3) {$ctx3.fillBlock({ex:ex},$ctx2,3)})}));
  902. }, function($ctx2) {$ctx2.fillBlock({},$ctx1,1)})}))._on_do_($Error(),(function(ex){
  903. return smalltalk.withContext(function($ctx2) {
  904. return self._addError_(aTestCase);
  905. }, function($ctx2) {$ctx2.fillBlock({ex:ex},$ctx1,4)})}));
  906. $ctx1.sendIdx["on:do:"]=1;
  907. return self}, function($ctx1) {$ctx1.fill(self,"runCase:",{aTestCase:aTestCase},smalltalk.TestResult)})},
  908. args: ["aTestCase"],
  909. source: "runCase: aTestCase\x0a\x09[ [ self increaseRuns.\x0a\x09\x09aTestCase runCase ]\x0a\x09on: TestFailure do: [ :ex | self addFailure: aTestCase ]]\x0a\x09on: Error do: [ :ex | self addError: aTestCase ]",
  910. messageSends: ["on:do:", "increaseRuns", "runCase", "addFailure:", "addError:"],
  911. referencedClasses: ["TestFailure", "Error"]
  912. }),
  913. smalltalk.TestResult);
  914. smalltalk.addMethod(
  915. smalltalk.method({
  916. selector: "runs",
  917. category: 'accessing',
  918. fn: function (){
  919. var self=this;
  920. return smalltalk.withContext(function($ctx1) {
  921. var $1;
  922. $1=self["@runs"];
  923. return $1;
  924. }, function($ctx1) {$ctx1.fill(self,"runs",{},smalltalk.TestResult)})},
  925. args: [],
  926. source: "runs\x0a\x09^ runs",
  927. messageSends: [],
  928. referencedClasses: []
  929. }),
  930. smalltalk.TestResult);
  931. smalltalk.addMethod(
  932. smalltalk.method({
  933. selector: "status",
  934. category: 'accessing',
  935. fn: function (){
  936. var self=this;
  937. return smalltalk.withContext(function($ctx1) {
  938. var $2,$3,$1;
  939. $2=_st(self._errors())._isEmpty();
  940. $ctx1.sendIdx["isEmpty"]=1;
  941. if(smalltalk.assert($2)){
  942. $3=_st(self._failures())._isEmpty();
  943. if(smalltalk.assert($3)){
  944. $1="success";
  945. } else {
  946. $1="failure";
  947. };
  948. } else {
  949. $1="error";
  950. };
  951. return $1;
  952. }, function($ctx1) {$ctx1.fill(self,"status",{},smalltalk.TestResult)})},
  953. args: [],
  954. source: "status\x0a\x09^ self errors isEmpty\x0a\x09\x09ifTrue: [\x0a\x09\x09\x09self failures isEmpty\x0a\x09\x09\x09\x09ifTrue: [ 'success' ]\x0a\x09\x09\x09\x09ifFalse: [ 'failure' ]]\x0a\x09\x09ifFalse: [ 'error' ]",
  955. messageSends: ["ifTrue:ifFalse:", "isEmpty", "errors", "failures"],
  956. referencedClasses: []
  957. }),
  958. smalltalk.TestResult);
  959. smalltalk.addMethod(
  960. smalltalk.method({
  961. selector: "timestamp",
  962. category: 'accessing',
  963. fn: function (){
  964. var self=this;
  965. return smalltalk.withContext(function($ctx1) {
  966. var $1;
  967. $1=self["@timestamp"];
  968. return $1;
  969. }, function($ctx1) {$ctx1.fill(self,"timestamp",{},smalltalk.TestResult)})},
  970. args: [],
  971. source: "timestamp\x0a\x09^ timestamp",
  972. messageSends: [],
  973. referencedClasses: []
  974. }),
  975. smalltalk.TestResult);
  976. smalltalk.addMethod(
  977. smalltalk.method({
  978. selector: "total",
  979. category: 'accessing',
  980. fn: function (){
  981. var self=this;
  982. return smalltalk.withContext(function($ctx1) {
  983. var $1;
  984. $1=self["@total"];
  985. return $1;
  986. }, function($ctx1) {$ctx1.fill(self,"total",{},smalltalk.TestResult)})},
  987. args: [],
  988. source: "total\x0a\x09^ total",
  989. messageSends: [],
  990. referencedClasses: []
  991. }),
  992. smalltalk.TestResult);
  993. smalltalk.addMethod(
  994. smalltalk.method({
  995. selector: "total:",
  996. category: 'accessing',
  997. fn: function (aNumber){
  998. var self=this;
  999. return smalltalk.withContext(function($ctx1) {
  1000. self["@total"]=aNumber;
  1001. return self}, function($ctx1) {$ctx1.fill(self,"total:",{aNumber:aNumber},smalltalk.TestResult)})},
  1002. args: ["aNumber"],
  1003. source: "total: aNumber\x0a\x09total := aNumber",
  1004. messageSends: [],
  1005. referencedClasses: []
  1006. }),
  1007. smalltalk.TestResult);
  1008. smalltalk.addClass('TestSuiteRunner', smalltalk.Object, ['suite', 'result', 'announcer', 'runNextTest'], 'SUnit');
  1009. smalltalk.TestSuiteRunner.comment="I am responsible for running a collection (`suite`) of tests.\x0a\x0a## API\x0a\x0aInstances should be created using the class-side `#on:` method, taking a collection of tests to run as parameter.\x0aTo run the test suite, use `#run`.";
  1010. smalltalk.addMethod(
  1011. smalltalk.method({
  1012. selector: "announcer",
  1013. category: 'accessing',
  1014. fn: function (){
  1015. var self=this;
  1016. return smalltalk.withContext(function($ctx1) {
  1017. var $1;
  1018. $1=self["@announcer"];
  1019. return $1;
  1020. }, function($ctx1) {$ctx1.fill(self,"announcer",{},smalltalk.TestSuiteRunner)})},
  1021. args: [],
  1022. source: "announcer\x0a\x09^ announcer",
  1023. messageSends: [],
  1024. referencedClasses: []
  1025. }),
  1026. smalltalk.TestSuiteRunner);
  1027. smalltalk.addMethod(
  1028. smalltalk.method({
  1029. selector: "contextOf:",
  1030. category: 'private',
  1031. fn: function (anInteger){
  1032. var self=this;
  1033. function $ReportingTestContext(){return smalltalk.ReportingTestContext||(typeof ReportingTestContext=="undefined"?nil:ReportingTestContext)}
  1034. return smalltalk.withContext(function($ctx1) {
  1035. var $1;
  1036. $1=_st($ReportingTestContext())._testCase_result_finished_(_st(self["@suite"])._at_(anInteger),self["@result"],(function(){
  1037. return smalltalk.withContext(function($ctx2) {
  1038. return self._resume();
  1039. }, function($ctx2) {$ctx2.fillBlock({},$ctx1,1)})}));
  1040. return $1;
  1041. }, function($ctx1) {$ctx1.fill(self,"contextOf:",{anInteger:anInteger},smalltalk.TestSuiteRunner)})},
  1042. args: ["anInteger"],
  1043. source: "contextOf: anInteger\x0a\x09^ ReportingTestContext testCase: (suite at: anInteger) result: result finished: [ self resume ]",
  1044. messageSends: ["testCase:result:finished:", "at:", "resume"],
  1045. referencedClasses: ["ReportingTestContext"]
  1046. }),
  1047. smalltalk.TestSuiteRunner);
  1048. smalltalk.addMethod(
  1049. smalltalk.method({
  1050. selector: "initialize",
  1051. category: 'initialization',
  1052. fn: function (){
  1053. var self=this;
  1054. function $Announcer(){return smalltalk.Announcer||(typeof Announcer=="undefined"?nil:Announcer)}
  1055. function $TestResult(){return smalltalk.TestResult||(typeof TestResult=="undefined"?nil:TestResult)}
  1056. return smalltalk.withContext(function($ctx1) {
  1057. var $1;
  1058. smalltalk.TestSuiteRunner.superclass.fn.prototype._initialize.apply(_st(self), []);
  1059. self["@announcer"]=_st($Announcer())._new();
  1060. $ctx1.sendIdx["new"]=1;
  1061. self["@result"]=_st($TestResult())._new();
  1062. self["@runNextTest"]=(function(){
  1063. var runs;
  1064. return smalltalk.withContext(function($ctx2) {
  1065. runs=_st(self["@result"])._runs();
  1066. runs;
  1067. $1=_st(runs).__lt(_st(self["@result"])._total());
  1068. if(smalltalk.assert($1)){
  1069. return _st(self._contextOf_(_st(runs).__plus((1))))._start();
  1070. };
  1071. }, function($ctx2) {$ctx2.fillBlock({runs:runs},$ctx1,1)})});
  1072. return self}, function($ctx1) {$ctx1.fill(self,"initialize",{},smalltalk.TestSuiteRunner)})},
  1073. args: [],
  1074. source: "initialize\x0a\x09super initialize.\x0a\x09announcer := Announcer new.\x0a\x09result := TestResult new.\x0a\x09runNextTest := [ | runs | runs := result runs. runs < result total ifTrue: [ (self contextOf: runs + 1) start ] ].",
  1075. messageSends: ["initialize", "new", "runs", "ifTrue:", "<", "total", "start", "contextOf:", "+"],
  1076. referencedClasses: ["Announcer", "TestResult"]
  1077. }),
  1078. smalltalk.TestSuiteRunner);
  1079. smalltalk.addMethod(
  1080. smalltalk.method({
  1081. selector: "result",
  1082. category: 'accessing',
  1083. fn: function (){
  1084. var self=this;
  1085. return smalltalk.withContext(function($ctx1) {
  1086. var $1;
  1087. $1=self["@result"];
  1088. return $1;
  1089. }, function($ctx1) {$ctx1.fill(self,"result",{},smalltalk.TestSuiteRunner)})},
  1090. args: [],
  1091. source: "result\x0a\x09^ result",
  1092. messageSends: [],
  1093. referencedClasses: []
  1094. }),
  1095. smalltalk.TestSuiteRunner);
  1096. smalltalk.addMethod(
  1097. smalltalk.method({
  1098. selector: "resume",
  1099. category: 'actions',
  1100. fn: function (){
  1101. var self=this;
  1102. function $ResultAnnouncement(){return smalltalk.ResultAnnouncement||(typeof ResultAnnouncement=="undefined"?nil:ResultAnnouncement)}
  1103. return smalltalk.withContext(function($ctx1) {
  1104. _st(self["@runNextTest"])._fork();
  1105. _st(self["@announcer"])._announce_(_st(_st($ResultAnnouncement())._new())._result_(self["@result"]));
  1106. return self}, function($ctx1) {$ctx1.fill(self,"resume",{},smalltalk.TestSuiteRunner)})},
  1107. args: [],
  1108. source: "resume\x0a\x09runNextTest fork.\x0a\x09announcer announce: (ResultAnnouncement new result: result)",
  1109. messageSends: ["fork", "announce:", "result:", "new"],
  1110. referencedClasses: ["ResultAnnouncement"]
  1111. }),
  1112. smalltalk.TestSuiteRunner);
  1113. smalltalk.addMethod(
  1114. smalltalk.method({
  1115. selector: "run",
  1116. category: 'actions',
  1117. fn: function (){
  1118. var self=this;
  1119. return smalltalk.withContext(function($ctx1) {
  1120. _st(self["@result"])._total_(_st(self["@suite"])._size());
  1121. self._resume();
  1122. return self}, function($ctx1) {$ctx1.fill(self,"run",{},smalltalk.TestSuiteRunner)})},
  1123. args: [],
  1124. source: "run\x0a\x09result total: suite size.\x0a\x09self resume",
  1125. messageSends: ["total:", "size", "resume"],
  1126. referencedClasses: []
  1127. }),
  1128. smalltalk.TestSuiteRunner);
  1129. smalltalk.addMethod(
  1130. smalltalk.method({
  1131. selector: "suite:",
  1132. category: 'accessing',
  1133. fn: function (aCollection){
  1134. var self=this;
  1135. return smalltalk.withContext(function($ctx1) {
  1136. self["@suite"]=aCollection;
  1137. return self}, function($ctx1) {$ctx1.fill(self,"suite:",{aCollection:aCollection},smalltalk.TestSuiteRunner)})},
  1138. args: ["aCollection"],
  1139. source: "suite: aCollection\x0a\x09suite := aCollection",
  1140. messageSends: [],
  1141. referencedClasses: []
  1142. }),
  1143. smalltalk.TestSuiteRunner);
  1144. smalltalk.addMethod(
  1145. smalltalk.method({
  1146. selector: "new",
  1147. category: 'instance creation',
  1148. fn: function (){
  1149. var self=this;
  1150. return smalltalk.withContext(function($ctx1) {
  1151. self._shouldNotImplement();
  1152. return self}, function($ctx1) {$ctx1.fill(self,"new",{},smalltalk.TestSuiteRunner.klass)})},
  1153. args: [],
  1154. source: "new\x0a\x09self shouldNotImplement",
  1155. messageSends: ["shouldNotImplement"],
  1156. referencedClasses: []
  1157. }),
  1158. smalltalk.TestSuiteRunner.klass);
  1159. smalltalk.addMethod(
  1160. smalltalk.method({
  1161. selector: "on:",
  1162. category: 'instance creation',
  1163. fn: function (aCollection){
  1164. var self=this;
  1165. return smalltalk.withContext(function($ctx1) {
  1166. var $1;
  1167. $1=_st(smalltalk.TestSuiteRunner.klass.superclass.fn.prototype._new.apply(_st(self), []))._suite_(aCollection);
  1168. return $1;
  1169. }, function($ctx1) {$ctx1.fill(self,"on:",{aCollection:aCollection},smalltalk.TestSuiteRunner.klass)})},
  1170. args: ["aCollection"],
  1171. source: "on: aCollection\x0a\x09^ super new suite: aCollection",
  1172. messageSends: ["suite:", "new"],
  1173. referencedClasses: []
  1174. }),
  1175. smalltalk.TestSuiteRunner.klass);
  1176. });