1
0

SUnit.js 57 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809
  1. define(["amber/boot", "amber_core/Kernel-Classes", "amber_core/Kernel-Exceptions", "amber_core/Kernel-Infrastructure", "amber_core/Kernel-Objects"], function($boot){"use strict";
  2. if(!$boot.nilAsReceiver)$boot.nilAsReceiver=$boot.nil;
  3. var $core=$boot.api,nil=$boot.nilAsReceiver,$recv=$boot.asReceiver,$globals=$boot.globals;
  4. if(!$boot.nilAsClass)$boot.nilAsClass=$boot.dnu;
  5. $core.addPackage('SUnit');
  6. $core.packages["SUnit"].innerEval = function (expr) { return eval(expr); };
  7. $core.packages["SUnit"].transport = {"type":"amd","amdNamespace":"amber_core"};
  8. $core.addClass('ResultAnnouncement', $globals.Object, ['result'], 'SUnit');
  9. //>>excludeStart("ide", pragmas.excludeIdeData);
  10. $globals.ResultAnnouncement.comment="I get signaled when a `TestCase` has been run.\x0a\x0aMy instances hold the result (instance of `TestResult`) of the test run.";
  11. //>>excludeEnd("ide");
  12. $core.addMethod(
  13. $core.method({
  14. selector: "result",
  15. protocol: 'accessing',
  16. fn: function (){
  17. var self=this;
  18. return self["@result"];
  19. },
  20. //>>excludeStart("ide", pragmas.excludeIdeData);
  21. args: [],
  22. source: "result\x0a\x09^ result",
  23. referencedClasses: [],
  24. //>>excludeEnd("ide");
  25. messageSends: []
  26. }),
  27. $globals.ResultAnnouncement);
  28. $core.addMethod(
  29. $core.method({
  30. selector: "result:",
  31. protocol: 'accessing',
  32. fn: function (aTestResult){
  33. var self=this;
  34. self["@result"]=aTestResult;
  35. return self;
  36. },
  37. //>>excludeStart("ide", pragmas.excludeIdeData);
  38. args: ["aTestResult"],
  39. source: "result: aTestResult\x0a\x09result := aTestResult",
  40. referencedClasses: [],
  41. //>>excludeEnd("ide");
  42. messageSends: []
  43. }),
  44. $globals.ResultAnnouncement);
  45. $core.addClass('TestCase', $globals.Object, ['testSelector', 'asyncTimeout', 'context'], 'SUnit');
  46. //>>excludeStart("ide", pragmas.excludeIdeData);
  47. $globals.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.";
  48. //>>excludeEnd("ide");
  49. $core.addMethod(
  50. $core.method({
  51. selector: "assert:",
  52. protocol: 'testing',
  53. fn: function (aBoolean){
  54. var self=this;
  55. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  56. return $core.withContext(function($ctx1) {
  57. //>>excludeEnd("ctx");
  58. self._assert_description_(aBoolean,"Assertion failed");
  59. return self;
  60. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  61. }, function($ctx1) {$ctx1.fill(self,"assert:",{aBoolean:aBoolean},$globals.TestCase)});
  62. //>>excludeEnd("ctx");
  63. },
  64. //>>excludeStart("ide", pragmas.excludeIdeData);
  65. args: ["aBoolean"],
  66. source: "assert: aBoolean\x0a\x09self assert: aBoolean description: 'Assertion failed'",
  67. referencedClasses: [],
  68. //>>excludeEnd("ide");
  69. messageSends: ["assert:description:"]
  70. }),
  71. $globals.TestCase);
  72. $core.addMethod(
  73. $core.method({
  74. selector: "assert:description:",
  75. protocol: 'testing',
  76. fn: function (aBoolean,aString){
  77. var self=this;
  78. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  79. return $core.withContext(function($ctx1) {
  80. //>>excludeEnd("ctx");
  81. if(!$core.assert(aBoolean)){
  82. self._signalFailure_(aString);
  83. }
  84. return self;
  85. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  86. }, function($ctx1) {$ctx1.fill(self,"assert:description:",{aBoolean:aBoolean,aString:aString},$globals.TestCase)});
  87. //>>excludeEnd("ctx");
  88. },
  89. //>>excludeStart("ide", pragmas.excludeIdeData);
  90. args: ["aBoolean", "aString"],
  91. source: "assert: aBoolean description: aString\x0a\x09aBoolean ifFalse: [ self signalFailure: aString ]",
  92. referencedClasses: [],
  93. //>>excludeEnd("ide");
  94. messageSends: ["ifFalse:", "signalFailure:"]
  95. }),
  96. $globals.TestCase);
  97. $core.addMethod(
  98. $core.method({
  99. selector: "assert:equals:",
  100. protocol: 'testing',
  101. fn: function (actual,expected){
  102. var self=this;
  103. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  104. return $core.withContext(function($ctx1) {
  105. //>>excludeEnd("ctx");
  106. var $1,$5,$4,$3,$2;
  107. $1=$recv(actual).__eq(expected);
  108. $5=$recv(expected)._printString();
  109. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  110. $ctx1.sendIdx["printString"]=1;
  111. //>>excludeEnd("ctx");
  112. $4="Expected: ".__comma($5);
  113. $3=$recv($4).__comma(" but was: ");
  114. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  115. $ctx1.sendIdx[","]=2;
  116. //>>excludeEnd("ctx");
  117. $2=$recv($3).__comma($recv(actual)._printString());
  118. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  119. $ctx1.sendIdx[","]=1;
  120. //>>excludeEnd("ctx");
  121. return self._assert_description_($1,$2);
  122. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  123. }, function($ctx1) {$ctx1.fill(self,"assert:equals:",{actual:actual,expected:expected},$globals.TestCase)});
  124. //>>excludeEnd("ctx");
  125. },
  126. //>>excludeStart("ide", pragmas.excludeIdeData);
  127. args: ["actual", "expected"],
  128. source: "assert: actual equals: expected\x0a\x09^ self assert: (actual = expected) description: 'Expected: ', expected printString, ' but was: ', actual printString",
  129. referencedClasses: [],
  130. //>>excludeEnd("ide");
  131. messageSends: ["assert:description:", "=", ",", "printString"]
  132. }),
  133. $globals.TestCase);
  134. $core.addMethod(
  135. $core.method({
  136. selector: "async:",
  137. protocol: 'async',
  138. fn: function (aBlock){
  139. var self=this;
  140. var c;
  141. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  142. return $core.withContext(function($ctx1) {
  143. //>>excludeEnd("ctx");
  144. var $1;
  145. self._errorIfNotAsync_("#async");
  146. c=self["@context"];
  147. return (function(){
  148. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  149. return $core.withContext(function($ctx2) {
  150. //>>excludeEnd("ctx");
  151. $1=self._isAsync();
  152. if($core.assert($1)){
  153. return $recv(c)._execute_(aBlock);
  154. }
  155. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  156. }, function($ctx2) {$ctx2.fillBlock({},$ctx1,1)});
  157. //>>excludeEnd("ctx");
  158. });
  159. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  160. }, function($ctx1) {$ctx1.fill(self,"async:",{aBlock:aBlock,c:c},$globals.TestCase)});
  161. //>>excludeEnd("ctx");
  162. },
  163. //>>excludeStart("ide", pragmas.excludeIdeData);
  164. args: ["aBlock"],
  165. source: "async: aBlock\x0a\x09| c |\x0a\x09self errorIfNotAsync: '#async'.\x0a\x09c := context.\x0a\x09^ [ self isAsync ifTrue: [ c execute: aBlock ] ]",
  166. referencedClasses: [],
  167. //>>excludeEnd("ide");
  168. messageSends: ["errorIfNotAsync:", "ifTrue:", "isAsync", "execute:"]
  169. }),
  170. $globals.TestCase);
  171. $core.addMethod(
  172. $core.method({
  173. selector: "context:",
  174. protocol: 'accessing',
  175. fn: function (aRunningTestContext){
  176. var self=this;
  177. self["@context"]=aRunningTestContext;
  178. return self;
  179. },
  180. //>>excludeStart("ide", pragmas.excludeIdeData);
  181. args: ["aRunningTestContext"],
  182. source: "context: aRunningTestContext\x0a\x09context := aRunningTestContext",
  183. referencedClasses: [],
  184. //>>excludeEnd("ide");
  185. messageSends: []
  186. }),
  187. $globals.TestCase);
  188. $core.addMethod(
  189. $core.method({
  190. selector: "deny:",
  191. protocol: 'testing',
  192. fn: function (aBoolean){
  193. var self=this;
  194. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  195. return $core.withContext(function($ctx1) {
  196. //>>excludeEnd("ctx");
  197. self._assert_($recv(aBoolean)._not());
  198. return self;
  199. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  200. }, function($ctx1) {$ctx1.fill(self,"deny:",{aBoolean:aBoolean},$globals.TestCase)});
  201. //>>excludeEnd("ctx");
  202. },
  203. //>>excludeStart("ide", pragmas.excludeIdeData);
  204. args: ["aBoolean"],
  205. source: "deny: aBoolean\x0a\x09self assert: aBoolean not",
  206. referencedClasses: [],
  207. //>>excludeEnd("ide");
  208. messageSends: ["assert:", "not"]
  209. }),
  210. $globals.TestCase);
  211. $core.addMethod(
  212. $core.method({
  213. selector: "errorIfNotAsync:",
  214. protocol: 'error handling',
  215. fn: function (aString){
  216. var self=this;
  217. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  218. return $core.withContext(function($ctx1) {
  219. //>>excludeEnd("ctx");
  220. var $1;
  221. $1=self._isAsync();
  222. if(!$core.assert($1)){
  223. self._error_($recv(aString).__comma(" used without prior #timeout:"));
  224. }
  225. return self;
  226. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  227. }, function($ctx1) {$ctx1.fill(self,"errorIfNotAsync:",{aString:aString},$globals.TestCase)});
  228. //>>excludeEnd("ctx");
  229. },
  230. //>>excludeStart("ide", pragmas.excludeIdeData);
  231. args: ["aString"],
  232. source: "errorIfNotAsync: aString\x0a\x09self isAsync ifFalse: [\x0a\x09\x09self error: aString, ' used without prior #timeout:' ]",
  233. referencedClasses: [],
  234. //>>excludeEnd("ide");
  235. messageSends: ["ifFalse:", "isAsync", "error:", ","]
  236. }),
  237. $globals.TestCase);
  238. $core.addMethod(
  239. $core.method({
  240. selector: "finished",
  241. protocol: 'async',
  242. fn: function (){
  243. var self=this;
  244. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  245. return $core.withContext(function($ctx1) {
  246. //>>excludeEnd("ctx");
  247. self._errorIfNotAsync_("#finished");
  248. self["@asyncTimeout"]=nil;
  249. return self;
  250. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  251. }, function($ctx1) {$ctx1.fill(self,"finished",{},$globals.TestCase)});
  252. //>>excludeEnd("ctx");
  253. },
  254. //>>excludeStart("ide", pragmas.excludeIdeData);
  255. args: [],
  256. source: "finished\x0a\x09self errorIfNotAsync: '#finished'.\x0a\x09asyncTimeout := nil",
  257. referencedClasses: [],
  258. //>>excludeEnd("ide");
  259. messageSends: ["errorIfNotAsync:"]
  260. }),
  261. $globals.TestCase);
  262. $core.addMethod(
  263. $core.method({
  264. selector: "isAsync",
  265. protocol: 'testing',
  266. fn: function (){
  267. var self=this;
  268. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  269. return $core.withContext(function($ctx1) {
  270. //>>excludeEnd("ctx");
  271. return $recv(self["@asyncTimeout"])._notNil();
  272. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  273. }, function($ctx1) {$ctx1.fill(self,"isAsync",{},$globals.TestCase)});
  274. //>>excludeEnd("ctx");
  275. },
  276. //>>excludeStart("ide", pragmas.excludeIdeData);
  277. args: [],
  278. source: "isAsync\x0a\x09^ asyncTimeout notNil",
  279. referencedClasses: [],
  280. //>>excludeEnd("ide");
  281. messageSends: ["notNil"]
  282. }),
  283. $globals.TestCase);
  284. $core.addMethod(
  285. $core.method({
  286. selector: "performTest",
  287. protocol: 'running',
  288. fn: function (){
  289. var self=this;
  290. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  291. return $core.withContext(function($ctx1) {
  292. //>>excludeEnd("ctx");
  293. self["@asyncTimeout"]=nil;
  294. self._perform_(self._selector());
  295. return self;
  296. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  297. }, function($ctx1) {$ctx1.fill(self,"performTest",{},$globals.TestCase)});
  298. //>>excludeEnd("ctx");
  299. },
  300. //>>excludeStart("ide", pragmas.excludeIdeData);
  301. args: [],
  302. source: "performTest\x0a\x09asyncTimeout := nil.\x0a\x09self perform: self selector",
  303. referencedClasses: [],
  304. //>>excludeEnd("ide");
  305. messageSends: ["perform:", "selector"]
  306. }),
  307. $globals.TestCase);
  308. $core.addMethod(
  309. $core.method({
  310. selector: "runCase",
  311. protocol: 'running',
  312. fn: function (){
  313. var self=this;
  314. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  315. return $core.withContext(function($ctx1) {
  316. //>>excludeEnd("ctx");
  317. $recv($recv($globals.TestContext)._testCase_(self))._start();
  318. return self;
  319. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  320. }, function($ctx1) {$ctx1.fill(self,"runCase",{},$globals.TestCase)});
  321. //>>excludeEnd("ctx");
  322. },
  323. //>>excludeStart("ide", pragmas.excludeIdeData);
  324. args: [],
  325. source: "runCase\x0a\x09\x22Runs a test case in isolated context, leaking all errors.\x22\x0a\x0a\x09(TestContext testCase: self) start",
  326. referencedClasses: ["TestContext"],
  327. //>>excludeEnd("ide");
  328. messageSends: ["start", "testCase:"]
  329. }),
  330. $globals.TestCase);
  331. $core.addMethod(
  332. $core.method({
  333. selector: "selector",
  334. protocol: 'accessing',
  335. fn: function (){
  336. var self=this;
  337. return self["@testSelector"];
  338. },
  339. //>>excludeStart("ide", pragmas.excludeIdeData);
  340. args: [],
  341. source: "selector\x0a\x09^ testSelector",
  342. referencedClasses: [],
  343. //>>excludeEnd("ide");
  344. messageSends: []
  345. }),
  346. $globals.TestCase);
  347. $core.addMethod(
  348. $core.method({
  349. selector: "setTestSelector:",
  350. protocol: 'accessing',
  351. fn: function (aSelector){
  352. var self=this;
  353. self["@testSelector"]=aSelector;
  354. return self;
  355. },
  356. //>>excludeStart("ide", pragmas.excludeIdeData);
  357. args: ["aSelector"],
  358. source: "setTestSelector: aSelector\x0a\x09testSelector := aSelector",
  359. referencedClasses: [],
  360. //>>excludeEnd("ide");
  361. messageSends: []
  362. }),
  363. $globals.TestCase);
  364. $core.addMethod(
  365. $core.method({
  366. selector: "setUp",
  367. protocol: 'running',
  368. fn: function (){
  369. var self=this;
  370. return self;
  371. },
  372. //>>excludeStart("ide", pragmas.excludeIdeData);
  373. args: [],
  374. source: "setUp",
  375. referencedClasses: [],
  376. //>>excludeEnd("ide");
  377. messageSends: []
  378. }),
  379. $globals.TestCase);
  380. $core.addMethod(
  381. $core.method({
  382. selector: "should:",
  383. protocol: 'testing',
  384. fn: function (aBlock){
  385. var self=this;
  386. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  387. return $core.withContext(function($ctx1) {
  388. //>>excludeEnd("ctx");
  389. self._assert_($recv(aBlock)._value());
  390. return self;
  391. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  392. }, function($ctx1) {$ctx1.fill(self,"should:",{aBlock:aBlock},$globals.TestCase)});
  393. //>>excludeEnd("ctx");
  394. },
  395. //>>excludeStart("ide", pragmas.excludeIdeData);
  396. args: ["aBlock"],
  397. source: "should: aBlock\x0a\x09self assert: aBlock value",
  398. referencedClasses: [],
  399. //>>excludeEnd("ide");
  400. messageSends: ["assert:", "value"]
  401. }),
  402. $globals.TestCase);
  403. $core.addMethod(
  404. $core.method({
  405. selector: "should:raise:",
  406. protocol: 'testing',
  407. fn: function (aBlock,anExceptionClass){
  408. var self=this;
  409. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  410. return $core.withContext(function($ctx1) {
  411. //>>excludeEnd("ctx");
  412. self._assert_($recv((function(){
  413. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  414. return $core.withContext(function($ctx2) {
  415. //>>excludeEnd("ctx");
  416. $recv(aBlock)._value();
  417. return false;
  418. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  419. }, function($ctx2) {$ctx2.fillBlock({},$ctx1,1)});
  420. //>>excludeEnd("ctx");
  421. }))._on_do_(anExceptionClass,(function(ex){
  422. return true;
  423. })));
  424. return self;
  425. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  426. }, function($ctx1) {$ctx1.fill(self,"should:raise:",{aBlock:aBlock,anExceptionClass:anExceptionClass},$globals.TestCase)});
  427. //>>excludeEnd("ctx");
  428. },
  429. //>>excludeStart("ide", pragmas.excludeIdeData);
  430. args: ["aBlock", "anExceptionClass"],
  431. source: "should: aBlock raise: anExceptionClass\x0a\x09self assert: ([ aBlock value. false ]\x0a\x09\x09on: anExceptionClass\x0a\x09\x09do: [ :ex | true ])",
  432. referencedClasses: [],
  433. //>>excludeEnd("ide");
  434. messageSends: ["assert:", "on:do:", "value"]
  435. }),
  436. $globals.TestCase);
  437. $core.addMethod(
  438. $core.method({
  439. selector: "shouldnt:raise:",
  440. protocol: 'testing',
  441. fn: function (aBlock,anExceptionClass){
  442. var self=this;
  443. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  444. return $core.withContext(function($ctx1) {
  445. //>>excludeEnd("ctx");
  446. self._assert_($recv((function(){
  447. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  448. return $core.withContext(function($ctx2) {
  449. //>>excludeEnd("ctx");
  450. $recv(aBlock)._value();
  451. return true;
  452. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  453. }, function($ctx2) {$ctx2.fillBlock({},$ctx1,1)});
  454. //>>excludeEnd("ctx");
  455. }))._on_do_(anExceptionClass,(function(ex){
  456. return false;
  457. })));
  458. return self;
  459. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  460. }, function($ctx1) {$ctx1.fill(self,"shouldnt:raise:",{aBlock:aBlock,anExceptionClass:anExceptionClass},$globals.TestCase)});
  461. //>>excludeEnd("ctx");
  462. },
  463. //>>excludeStart("ide", pragmas.excludeIdeData);
  464. args: ["aBlock", "anExceptionClass"],
  465. source: "shouldnt: aBlock raise: anExceptionClass\x0a\x09self assert: ([ aBlock value. true ]\x0a\x09\x09on: anExceptionClass\x0a\x09\x09do: [ :ex | false ])",
  466. referencedClasses: [],
  467. //>>excludeEnd("ide");
  468. messageSends: ["assert:", "on:do:", "value"]
  469. }),
  470. $globals.TestCase);
  471. $core.addMethod(
  472. $core.method({
  473. selector: "signalFailure:",
  474. protocol: 'private',
  475. fn: function (aString){
  476. var self=this;
  477. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  478. return $core.withContext(function($ctx1) {
  479. //>>excludeEnd("ctx");
  480. var $1;
  481. $1=$recv($globals.TestFailure)._new();
  482. $recv($1)._messageText_(aString);
  483. $recv($1)._signal();
  484. return self;
  485. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  486. }, function($ctx1) {$ctx1.fill(self,"signalFailure:",{aString:aString},$globals.TestCase)});
  487. //>>excludeEnd("ctx");
  488. },
  489. //>>excludeStart("ide", pragmas.excludeIdeData);
  490. args: ["aString"],
  491. source: "signalFailure: aString\x0a\x09TestFailure new\x0a\x09\x09messageText: aString;\x0a\x09\x09signal",
  492. referencedClasses: ["TestFailure"],
  493. //>>excludeEnd("ide");
  494. messageSends: ["messageText:", "new", "signal"]
  495. }),
  496. $globals.TestCase);
  497. $core.addMethod(
  498. $core.method({
  499. selector: "tearDown",
  500. protocol: 'running',
  501. fn: function (){
  502. var self=this;
  503. return self;
  504. },
  505. //>>excludeStart("ide", pragmas.excludeIdeData);
  506. args: [],
  507. source: "tearDown",
  508. referencedClasses: [],
  509. //>>excludeEnd("ide");
  510. messageSends: []
  511. }),
  512. $globals.TestCase);
  513. $core.addMethod(
  514. $core.method({
  515. selector: "timeout:",
  516. protocol: 'async',
  517. fn: function (aNumber){
  518. var self=this;
  519. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  520. return $core.withContext(function($ctx1) {
  521. //>>excludeEnd("ctx");
  522. var $1,$receiver;
  523. $1=self["@asyncTimeout"];
  524. if(($receiver = $1) == null || $receiver.isNil){
  525. $1;
  526. } else {
  527. $recv(self["@asyncTimeout"])._clearTimeout();
  528. }
  529. self["@asyncTimeout"]=(0);
  530. self["@asyncTimeout"]=$recv(self._async_((function(){
  531. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  532. return $core.withContext(function($ctx2) {
  533. //>>excludeEnd("ctx");
  534. return self._assert_description_(false,"SUnit grace time exhausted");
  535. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  536. }, function($ctx2) {$ctx2.fillBlock({},$ctx1,2)});
  537. //>>excludeEnd("ctx");
  538. })))._valueWithTimeout_(aNumber);
  539. return self;
  540. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  541. }, function($ctx1) {$ctx1.fill(self,"timeout:",{aNumber:aNumber},$globals.TestCase)});
  542. //>>excludeEnd("ctx");
  543. },
  544. //>>excludeStart("ide", pragmas.excludeIdeData);
  545. args: ["aNumber"],
  546. 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",
  547. referencedClasses: [],
  548. //>>excludeEnd("ide");
  549. messageSends: ["ifNotNil:", "clearTimeout", "valueWithTimeout:", "async:", "assert:description:"]
  550. }),
  551. $globals.TestCase);
  552. $core.addMethod(
  553. $core.method({
  554. selector: "allTestSelectors",
  555. protocol: 'accessing',
  556. fn: function (){
  557. var self=this;
  558. var selectors;
  559. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  560. return $core.withContext(function($ctx1) {
  561. //>>excludeEnd("ctx");
  562. var $1;
  563. selectors=self._testSelectors();
  564. $1=self._shouldInheritSelectors();
  565. if($core.assert($1)){
  566. $recv(selectors)._addAll_($recv(self._superclass())._allTestSelectors());
  567. }
  568. return selectors;
  569. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  570. }, function($ctx1) {$ctx1.fill(self,"allTestSelectors",{selectors:selectors},$globals.TestCase.klass)});
  571. //>>excludeEnd("ctx");
  572. },
  573. //>>excludeStart("ide", pragmas.excludeIdeData);
  574. args: [],
  575. source: "allTestSelectors\x0a\x09| selectors |\x0a\x09selectors := self testSelectors.\x0a\x09self shouldInheritSelectors ifTrue: [\x0a\x09\x09selectors addAll: self superclass allTestSelectors ].\x0a\x09^ selectors",
  576. referencedClasses: [],
  577. //>>excludeEnd("ide");
  578. messageSends: ["testSelectors", "ifTrue:", "shouldInheritSelectors", "addAll:", "allTestSelectors", "superclass"]
  579. }),
  580. $globals.TestCase.klass);
  581. $core.addMethod(
  582. $core.method({
  583. selector: "buildSuite",
  584. protocol: 'accessing',
  585. fn: function (){
  586. var self=this;
  587. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  588. return $core.withContext(function($ctx1) {
  589. //>>excludeEnd("ctx");
  590. return $recv(self._allTestSelectors())._collect_((function(each){
  591. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  592. return $core.withContext(function($ctx2) {
  593. //>>excludeEnd("ctx");
  594. return self._selector_(each);
  595. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  596. }, function($ctx2) {$ctx2.fillBlock({each:each},$ctx1,1)});
  597. //>>excludeEnd("ctx");
  598. }));
  599. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  600. }, function($ctx1) {$ctx1.fill(self,"buildSuite",{},$globals.TestCase.klass)});
  601. //>>excludeEnd("ctx");
  602. },
  603. //>>excludeStart("ide", pragmas.excludeIdeData);
  604. args: [],
  605. source: "buildSuite\x0a\x09^ self allTestSelectors collect: [ :each | self selector: each ]",
  606. referencedClasses: [],
  607. //>>excludeEnd("ide");
  608. messageSends: ["collect:", "allTestSelectors", "selector:"]
  609. }),
  610. $globals.TestCase.klass);
  611. $core.addMethod(
  612. $core.method({
  613. selector: "classTag",
  614. protocol: 'accessing',
  615. fn: function (){
  616. var self=this;
  617. return "test";
  618. },
  619. //>>excludeStart("ide", pragmas.excludeIdeData);
  620. args: [],
  621. source: "classTag\x0a\x09\x22Returns a tag or general category for this class.\x0a\x09Typically used to help tools do some reflection.\x0a\x09Helios, for example, uses this to decide what icon the class should display.\x22\x0a\x09\x0a\x09^ 'test'",
  622. referencedClasses: [],
  623. //>>excludeEnd("ide");
  624. messageSends: []
  625. }),
  626. $globals.TestCase.klass);
  627. $core.addMethod(
  628. $core.method({
  629. selector: "isAbstract",
  630. protocol: 'testing',
  631. fn: function (){
  632. var self=this;
  633. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  634. return $core.withContext(function($ctx1) {
  635. //>>excludeEnd("ctx");
  636. return $recv(self._name()).__eq("TestCase");
  637. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  638. }, function($ctx1) {$ctx1.fill(self,"isAbstract",{},$globals.TestCase.klass)});
  639. //>>excludeEnd("ctx");
  640. },
  641. //>>excludeStart("ide", pragmas.excludeIdeData);
  642. args: [],
  643. source: "isAbstract\x0a\x09^ self name = 'TestCase'",
  644. referencedClasses: [],
  645. //>>excludeEnd("ide");
  646. messageSends: ["=", "name"]
  647. }),
  648. $globals.TestCase.klass);
  649. $core.addMethod(
  650. $core.method({
  651. selector: "lookupHierarchyRoot",
  652. protocol: 'accessing',
  653. fn: function (){
  654. var self=this;
  655. return $globals.TestCase;
  656. },
  657. //>>excludeStart("ide", pragmas.excludeIdeData);
  658. args: [],
  659. source: "lookupHierarchyRoot\x0a\x09^ TestCase",
  660. referencedClasses: ["TestCase"],
  661. //>>excludeEnd("ide");
  662. messageSends: []
  663. }),
  664. $globals.TestCase.klass);
  665. $core.addMethod(
  666. $core.method({
  667. selector: "selector:",
  668. protocol: 'accessing',
  669. fn: function (aSelector){
  670. var self=this;
  671. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  672. return $core.withContext(function($ctx1) {
  673. //>>excludeEnd("ctx");
  674. var $1;
  675. $1=self._new();
  676. $recv($1)._setTestSelector_(aSelector);
  677. return $recv($1)._yourself();
  678. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  679. }, function($ctx1) {$ctx1.fill(self,"selector:",{aSelector:aSelector},$globals.TestCase.klass)});
  680. //>>excludeEnd("ctx");
  681. },
  682. //>>excludeStart("ide", pragmas.excludeIdeData);
  683. args: ["aSelector"],
  684. source: "selector: aSelector\x0a\x09^ self new\x0a\x09\x09setTestSelector: aSelector;\x0a\x09\x09yourself",
  685. referencedClasses: [],
  686. //>>excludeEnd("ide");
  687. messageSends: ["setTestSelector:", "new", "yourself"]
  688. }),
  689. $globals.TestCase.klass);
  690. $core.addMethod(
  691. $core.method({
  692. selector: "shouldInheritSelectors",
  693. protocol: 'testing',
  694. fn: function (){
  695. var self=this;
  696. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  697. return $core.withContext(function($ctx1) {
  698. //>>excludeEnd("ctx");
  699. return self.__tild_eq(self._lookupHierarchyRoot());
  700. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  701. }, function($ctx1) {$ctx1.fill(self,"shouldInheritSelectors",{},$globals.TestCase.klass)});
  702. //>>excludeEnd("ctx");
  703. },
  704. //>>excludeStart("ide", pragmas.excludeIdeData);
  705. args: [],
  706. source: "shouldInheritSelectors\x0a\x09^ self ~= self lookupHierarchyRoot",
  707. referencedClasses: [],
  708. //>>excludeEnd("ide");
  709. messageSends: ["~=", "lookupHierarchyRoot"]
  710. }),
  711. $globals.TestCase.klass);
  712. $core.addMethod(
  713. $core.method({
  714. selector: "testSelectors",
  715. protocol: 'accessing',
  716. fn: function (){
  717. var self=this;
  718. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  719. return $core.withContext(function($ctx1) {
  720. //>>excludeEnd("ctx");
  721. return $recv($recv(self._methodDictionary())._keys())._select_((function(each){
  722. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  723. return $core.withContext(function($ctx2) {
  724. //>>excludeEnd("ctx");
  725. return $recv(each)._match_("^test");
  726. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  727. }, function($ctx2) {$ctx2.fillBlock({each:each},$ctx1,1)});
  728. //>>excludeEnd("ctx");
  729. }));
  730. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  731. }, function($ctx1) {$ctx1.fill(self,"testSelectors",{},$globals.TestCase.klass)});
  732. //>>excludeEnd("ctx");
  733. },
  734. //>>excludeStart("ide", pragmas.excludeIdeData);
  735. args: [],
  736. source: "testSelectors\x0a\x09^ self methodDictionary keys select: [ :each | each match: '^test' ]",
  737. referencedClasses: [],
  738. //>>excludeEnd("ide");
  739. messageSends: ["select:", "keys", "methodDictionary", "match:"]
  740. }),
  741. $globals.TestCase.klass);
  742. $core.addClass('TestContext', $globals.Object, ['testCase'], 'SUnit');
  743. //>>excludeStart("ide", pragmas.excludeIdeData);
  744. $globals.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).";
  745. //>>excludeEnd("ide");
  746. $core.addMethod(
  747. $core.method({
  748. selector: "execute:",
  749. protocol: 'running',
  750. fn: function (aBlock){
  751. var self=this;
  752. var failed;
  753. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  754. return $core.withContext(function($ctx1) {
  755. //>>excludeEnd("ctx");
  756. var $1,$2;
  757. $recv(self["@testCase"])._context_(self);
  758. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  759. $ctx1.sendIdx["context:"]=1;
  760. //>>excludeEnd("ctx");
  761. $recv((function(){
  762. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  763. return $core.withContext(function($ctx2) {
  764. //>>excludeEnd("ctx");
  765. failed=true;
  766. failed;
  767. $recv(aBlock)._value();
  768. failed=false;
  769. return failed;
  770. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  771. }, function($ctx2) {$ctx2.fillBlock({},$ctx1,1)});
  772. //>>excludeEnd("ctx");
  773. }))._ensure_((function(){
  774. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  775. return $core.withContext(function($ctx2) {
  776. //>>excludeEnd("ctx");
  777. $recv(self["@testCase"])._context_(nil);
  778. $1=$recv(failed)._and_((function(){
  779. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  780. return $core.withContext(function($ctx3) {
  781. //>>excludeEnd("ctx");
  782. return $recv(self["@testCase"])._isAsync();
  783. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  784. $ctx3.sendIdx["isAsync"]=1;
  785. //>>excludeEnd("ctx");
  786. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  787. }, function($ctx3) {$ctx3.fillBlock({},$ctx2,3)});
  788. //>>excludeEnd("ctx");
  789. }));
  790. if($core.assert($1)){
  791. $recv(self["@testCase"])._finished();
  792. }
  793. $2=$recv(self["@testCase"])._isAsync();
  794. if(!$core.assert($2)){
  795. return $recv(self["@testCase"])._tearDown();
  796. }
  797. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  798. }, function($ctx2) {$ctx2.fillBlock({},$ctx1,2)});
  799. //>>excludeEnd("ctx");
  800. }));
  801. return self;
  802. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  803. }, function($ctx1) {$ctx1.fill(self,"execute:",{aBlock:aBlock,failed:failed},$globals.TestContext)});
  804. //>>excludeEnd("ctx");
  805. },
  806. //>>excludeStart("ide", pragmas.excludeIdeData);
  807. args: ["aBlock"],
  808. 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 ] ]",
  809. referencedClasses: [],
  810. //>>excludeEnd("ide");
  811. messageSends: ["context:", "ensure:", "value", "ifTrue:", "and:", "isAsync", "finished", "ifFalse:", "tearDown"]
  812. }),
  813. $globals.TestContext);
  814. $core.addMethod(
  815. $core.method({
  816. selector: "start",
  817. protocol: 'running',
  818. fn: function (){
  819. var self=this;
  820. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  821. return $core.withContext(function($ctx1) {
  822. //>>excludeEnd("ctx");
  823. self._execute_((function(){
  824. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  825. return $core.withContext(function($ctx2) {
  826. //>>excludeEnd("ctx");
  827. $recv(self["@testCase"])._setUp();
  828. return $recv(self["@testCase"])._performTest();
  829. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  830. }, function($ctx2) {$ctx2.fillBlock({},$ctx1,1)});
  831. //>>excludeEnd("ctx");
  832. }));
  833. return self;
  834. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  835. }, function($ctx1) {$ctx1.fill(self,"start",{},$globals.TestContext)});
  836. //>>excludeEnd("ctx");
  837. },
  838. //>>excludeStart("ide", pragmas.excludeIdeData);
  839. args: [],
  840. source: "start\x0a\x09self execute: [\x0a\x09\x09testCase setUp.\x0a\x09\x09testCase performTest ]",
  841. referencedClasses: [],
  842. //>>excludeEnd("ide");
  843. messageSends: ["execute:", "setUp", "performTest"]
  844. }),
  845. $globals.TestContext);
  846. $core.addMethod(
  847. $core.method({
  848. selector: "testCase:",
  849. protocol: 'accessing',
  850. fn: function (aTestCase){
  851. var self=this;
  852. self["@testCase"]=aTestCase;
  853. return self;
  854. },
  855. //>>excludeStart("ide", pragmas.excludeIdeData);
  856. args: ["aTestCase"],
  857. source: "testCase: aTestCase\x0a\x09testCase := aTestCase",
  858. referencedClasses: [],
  859. //>>excludeEnd("ide");
  860. messageSends: []
  861. }),
  862. $globals.TestContext);
  863. $core.addMethod(
  864. $core.method({
  865. selector: "testCase:",
  866. protocol: 'instance creation',
  867. fn: function (aTestCase){
  868. var self=this;
  869. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  870. return $core.withContext(function($ctx1) {
  871. //>>excludeEnd("ctx");
  872. var $1;
  873. $1=self._new();
  874. $recv($1)._testCase_(aTestCase);
  875. return $recv($1)._yourself();
  876. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  877. }, function($ctx1) {$ctx1.fill(self,"testCase:",{aTestCase:aTestCase},$globals.TestContext.klass)});
  878. //>>excludeEnd("ctx");
  879. },
  880. //>>excludeStart("ide", pragmas.excludeIdeData);
  881. args: ["aTestCase"],
  882. source: "testCase: aTestCase\x0a\x09^ self new\x0a\x09\x09testCase: aTestCase;\x0a\x09\x09yourself",
  883. referencedClasses: [],
  884. //>>excludeEnd("ide");
  885. messageSends: ["testCase:", "new", "yourself"]
  886. }),
  887. $globals.TestContext.klass);
  888. $core.addClass('ReportingTestContext', $globals.TestContext, ['finished', 'result'], 'SUnit');
  889. //>>excludeStart("ide", pragmas.excludeIdeData);
  890. $globals.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`.";
  891. //>>excludeEnd("ide");
  892. $core.addMethod(
  893. $core.method({
  894. selector: "execute:",
  895. protocol: 'running',
  896. fn: function (aBlock){
  897. var self=this;
  898. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  899. return $core.withContext(function($ctx1) {
  900. //>>excludeEnd("ctx");
  901. var $1;
  902. $recv((function(){
  903. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  904. return $core.withContext(function($ctx2) {
  905. //>>excludeEnd("ctx");
  906. return self._withErrorReporting_((function(){
  907. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  908. return $core.withContext(function($ctx3) {
  909. //>>excludeEnd("ctx");
  910. return (
  911. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  912. $ctx3.supercall = true,
  913. //>>excludeEnd("ctx");
  914. ($globals.ReportingTestContext.superclass||$boot.nilAsClass).fn.prototype._execute_.apply($recv(self), [aBlock]));
  915. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  916. $ctx3.supercall = false;
  917. //>>excludeEnd("ctx");;
  918. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  919. }, function($ctx3) {$ctx3.fillBlock({},$ctx2,2)});
  920. //>>excludeEnd("ctx");
  921. }));
  922. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  923. }, function($ctx2) {$ctx2.fillBlock({},$ctx1,1)});
  924. //>>excludeEnd("ctx");
  925. }))._ensure_((function(){
  926. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  927. return $core.withContext(function($ctx2) {
  928. //>>excludeEnd("ctx");
  929. $1=$recv(self["@testCase"])._isAsync();
  930. if(!$core.assert($1)){
  931. $recv(self["@result"])._increaseRuns();
  932. return $recv(self["@finished"])._value();
  933. }
  934. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  935. }, function($ctx2) {$ctx2.fillBlock({},$ctx1,3)});
  936. //>>excludeEnd("ctx");
  937. }));
  938. return self;
  939. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  940. }, function($ctx1) {$ctx1.fill(self,"execute:",{aBlock:aBlock},$globals.ReportingTestContext)});
  941. //>>excludeEnd("ctx");
  942. },
  943. //>>excludeStart("ide", pragmas.excludeIdeData);
  944. args: ["aBlock"],
  945. 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 ] ]",
  946. referencedClasses: [],
  947. //>>excludeEnd("ide");
  948. messageSends: ["ensure:", "withErrorReporting:", "execute:", "ifFalse:", "isAsync", "increaseRuns", "value"]
  949. }),
  950. $globals.ReportingTestContext);
  951. $core.addMethod(
  952. $core.method({
  953. selector: "finished:",
  954. protocol: 'accessing',
  955. fn: function (aBlock){
  956. var self=this;
  957. self["@finished"]=aBlock;
  958. return self;
  959. },
  960. //>>excludeStart("ide", pragmas.excludeIdeData);
  961. args: ["aBlock"],
  962. source: "finished: aBlock\x0a\x09finished := aBlock",
  963. referencedClasses: [],
  964. //>>excludeEnd("ide");
  965. messageSends: []
  966. }),
  967. $globals.ReportingTestContext);
  968. $core.addMethod(
  969. $core.method({
  970. selector: "result:",
  971. protocol: 'accessing',
  972. fn: function (aTestResult){
  973. var self=this;
  974. self["@result"]=aTestResult;
  975. return self;
  976. },
  977. //>>excludeStart("ide", pragmas.excludeIdeData);
  978. args: ["aTestResult"],
  979. source: "result: aTestResult\x0a\x09result := aTestResult",
  980. referencedClasses: [],
  981. //>>excludeEnd("ide");
  982. messageSends: []
  983. }),
  984. $globals.ReportingTestContext);
  985. $core.addMethod(
  986. $core.method({
  987. selector: "withErrorReporting:",
  988. protocol: 'private',
  989. fn: function (aBlock){
  990. var self=this;
  991. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  992. return $core.withContext(function($ctx1) {
  993. //>>excludeEnd("ctx");
  994. $recv((function(){
  995. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  996. return $core.withContext(function($ctx2) {
  997. //>>excludeEnd("ctx");
  998. return $recv(aBlock)._on_do_($globals.TestFailure,(function(ex){
  999. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1000. return $core.withContext(function($ctx3) {
  1001. //>>excludeEnd("ctx");
  1002. return $recv(self["@result"])._addFailure_(self["@testCase"]);
  1003. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1004. }, function($ctx3) {$ctx3.fillBlock({ex:ex},$ctx2,2)});
  1005. //>>excludeEnd("ctx");
  1006. }));
  1007. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1008. }, function($ctx2) {$ctx2.fillBlock({},$ctx1,1)});
  1009. //>>excludeEnd("ctx");
  1010. }))._on_do_($globals.Error,(function(ex){
  1011. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1012. return $core.withContext(function($ctx2) {
  1013. //>>excludeEnd("ctx");
  1014. return $recv(self["@result"])._addError_(self["@testCase"]);
  1015. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1016. }, function($ctx2) {$ctx2.fillBlock({ex:ex},$ctx1,3)});
  1017. //>>excludeEnd("ctx");
  1018. }));
  1019. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1020. $ctx1.sendIdx["on:do:"]=1;
  1021. //>>excludeEnd("ctx");
  1022. return self;
  1023. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1024. }, function($ctx1) {$ctx1.fill(self,"withErrorReporting:",{aBlock:aBlock},$globals.ReportingTestContext)});
  1025. //>>excludeEnd("ctx");
  1026. },
  1027. //>>excludeStart("ide", pragmas.excludeIdeData);
  1028. args: ["aBlock"],
  1029. 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 ]",
  1030. referencedClasses: ["TestFailure", "Error"],
  1031. //>>excludeEnd("ide");
  1032. messageSends: ["on:do:", "addFailure:", "addError:"]
  1033. }),
  1034. $globals.ReportingTestContext);
  1035. $core.addMethod(
  1036. $core.method({
  1037. selector: "testCase:result:finished:",
  1038. protocol: 'instance creation',
  1039. fn: function (aTestCase,aTestResult,aBlock){
  1040. var self=this;
  1041. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1042. return $core.withContext(function($ctx1) {
  1043. //>>excludeEnd("ctx");
  1044. var $1;
  1045. $1=(
  1046. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1047. $ctx1.supercall = true,
  1048. //>>excludeEnd("ctx");
  1049. ($globals.ReportingTestContext.klass.superclass||$boot.nilAsClass).fn.prototype._testCase_.apply($recv(self), [aTestCase]));
  1050. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1051. $ctx1.supercall = false;
  1052. //>>excludeEnd("ctx");;
  1053. $recv($1)._result_(aTestResult);
  1054. $recv($1)._finished_(aBlock);
  1055. return $recv($1)._yourself();
  1056. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1057. }, function($ctx1) {$ctx1.fill(self,"testCase:result:finished:",{aTestCase:aTestCase,aTestResult:aTestResult,aBlock:aBlock},$globals.ReportingTestContext.klass)});
  1058. //>>excludeEnd("ctx");
  1059. },
  1060. //>>excludeStart("ide", pragmas.excludeIdeData);
  1061. args: ["aTestCase", "aTestResult", "aBlock"],
  1062. source: "testCase: aTestCase result: aTestResult finished: aBlock\x0a\x09^ (super testCase: aTestCase)\x0a\x09\x09result: aTestResult;\x0a\x09\x09finished: aBlock;\x0a\x09\x09yourself",
  1063. referencedClasses: [],
  1064. //>>excludeEnd("ide");
  1065. messageSends: ["result:", "testCase:", "finished:", "yourself"]
  1066. }),
  1067. $globals.ReportingTestContext.klass);
  1068. $core.addClass('TestFailure', $globals.Error, [], 'SUnit');
  1069. //>>excludeStart("ide", pragmas.excludeIdeData);
  1070. $globals.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.";
  1071. //>>excludeEnd("ide");
  1072. $core.addClass('TestResult', $globals.Object, ['timestamp', 'runs', 'errors', 'failures', 'total'], 'SUnit');
  1073. //>>excludeStart("ide", pragmas.excludeIdeData);
  1074. $globals.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";
  1075. //>>excludeEnd("ide");
  1076. $core.addMethod(
  1077. $core.method({
  1078. selector: "addError:",
  1079. protocol: 'accessing',
  1080. fn: function (anError){
  1081. var self=this;
  1082. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1083. return $core.withContext(function($ctx1) {
  1084. //>>excludeEnd("ctx");
  1085. $recv(self._errors())._add_(anError);
  1086. return self;
  1087. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1088. }, function($ctx1) {$ctx1.fill(self,"addError:",{anError:anError},$globals.TestResult)});
  1089. //>>excludeEnd("ctx");
  1090. },
  1091. //>>excludeStart("ide", pragmas.excludeIdeData);
  1092. args: ["anError"],
  1093. source: "addError: anError\x0a\x09self errors add: anError",
  1094. referencedClasses: [],
  1095. //>>excludeEnd("ide");
  1096. messageSends: ["add:", "errors"]
  1097. }),
  1098. $globals.TestResult);
  1099. $core.addMethod(
  1100. $core.method({
  1101. selector: "addFailure:",
  1102. protocol: 'accessing',
  1103. fn: function (aFailure){
  1104. var self=this;
  1105. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1106. return $core.withContext(function($ctx1) {
  1107. //>>excludeEnd("ctx");
  1108. $recv(self._failures())._add_(aFailure);
  1109. return self;
  1110. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1111. }, function($ctx1) {$ctx1.fill(self,"addFailure:",{aFailure:aFailure},$globals.TestResult)});
  1112. //>>excludeEnd("ctx");
  1113. },
  1114. //>>excludeStart("ide", pragmas.excludeIdeData);
  1115. args: ["aFailure"],
  1116. source: "addFailure: aFailure\x0a\x09self failures add: aFailure",
  1117. referencedClasses: [],
  1118. //>>excludeEnd("ide");
  1119. messageSends: ["add:", "failures"]
  1120. }),
  1121. $globals.TestResult);
  1122. $core.addMethod(
  1123. $core.method({
  1124. selector: "errors",
  1125. protocol: 'accessing',
  1126. fn: function (){
  1127. var self=this;
  1128. return self["@errors"];
  1129. },
  1130. //>>excludeStart("ide", pragmas.excludeIdeData);
  1131. args: [],
  1132. source: "errors\x0a\x09^ errors",
  1133. referencedClasses: [],
  1134. //>>excludeEnd("ide");
  1135. messageSends: []
  1136. }),
  1137. $globals.TestResult);
  1138. $core.addMethod(
  1139. $core.method({
  1140. selector: "failures",
  1141. protocol: 'accessing',
  1142. fn: function (){
  1143. var self=this;
  1144. return self["@failures"];
  1145. },
  1146. //>>excludeStart("ide", pragmas.excludeIdeData);
  1147. args: [],
  1148. source: "failures\x0a\x09^ failures",
  1149. referencedClasses: [],
  1150. //>>excludeEnd("ide");
  1151. messageSends: []
  1152. }),
  1153. $globals.TestResult);
  1154. $core.addMethod(
  1155. $core.method({
  1156. selector: "increaseRuns",
  1157. protocol: 'accessing',
  1158. fn: function (){
  1159. var self=this;
  1160. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1161. return $core.withContext(function($ctx1) {
  1162. //>>excludeEnd("ctx");
  1163. self["@runs"]=$recv(self["@runs"]).__plus((1));
  1164. return self;
  1165. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1166. }, function($ctx1) {$ctx1.fill(self,"increaseRuns",{},$globals.TestResult)});
  1167. //>>excludeEnd("ctx");
  1168. },
  1169. //>>excludeStart("ide", pragmas.excludeIdeData);
  1170. args: [],
  1171. source: "increaseRuns\x0a\x09runs := runs + 1",
  1172. referencedClasses: [],
  1173. //>>excludeEnd("ide");
  1174. messageSends: ["+"]
  1175. }),
  1176. $globals.TestResult);
  1177. $core.addMethod(
  1178. $core.method({
  1179. selector: "initialize",
  1180. protocol: 'initialization',
  1181. fn: function (){
  1182. var self=this;
  1183. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1184. return $core.withContext(function($ctx1) {
  1185. //>>excludeEnd("ctx");
  1186. (
  1187. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1188. $ctx1.supercall = true,
  1189. //>>excludeEnd("ctx");
  1190. ($globals.TestResult.superclass||$boot.nilAsClass).fn.prototype._initialize.apply($recv(self), []));
  1191. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1192. $ctx1.supercall = false;
  1193. //>>excludeEnd("ctx");;
  1194. self["@timestamp"]=$recv($globals.Date)._now();
  1195. self["@runs"]=(0);
  1196. self["@errors"]=$recv($globals.Array)._new();
  1197. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1198. $ctx1.sendIdx["new"]=1;
  1199. //>>excludeEnd("ctx");
  1200. self["@failures"]=$recv($globals.Array)._new();
  1201. self["@total"]=(0);
  1202. return self;
  1203. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1204. }, function($ctx1) {$ctx1.fill(self,"initialize",{},$globals.TestResult)});
  1205. //>>excludeEnd("ctx");
  1206. },
  1207. //>>excludeStart("ide", pragmas.excludeIdeData);
  1208. args: [],
  1209. source: "initialize\x0a\x09super initialize.\x0a\x09timestamp := Date now.\x0a\x09runs := 0.\x0a\x09errors := Array new.\x0a\x09failures := Array new.\x0a\x09total := 0",
  1210. referencedClasses: ["Date", "Array"],
  1211. //>>excludeEnd("ide");
  1212. messageSends: ["initialize", "now", "new"]
  1213. }),
  1214. $globals.TestResult);
  1215. $core.addMethod(
  1216. $core.method({
  1217. selector: "nextRunDo:",
  1218. protocol: 'running',
  1219. fn: function (aBlock){
  1220. var self=this;
  1221. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1222. return $core.withContext(function($ctx1) {
  1223. //>>excludeEnd("ctx");
  1224. var $2,$1;
  1225. $2=self._runs();
  1226. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1227. $ctx1.sendIdx["runs"]=1;
  1228. //>>excludeEnd("ctx");
  1229. $1=$recv($2).__eq_eq(self._total());
  1230. if(!$core.assert($1)){
  1231. return $recv(aBlock)._value_($recv(self._runs()).__plus((1)));
  1232. }
  1233. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1234. }, function($ctx1) {$ctx1.fill(self,"nextRunDo:",{aBlock:aBlock},$globals.TestResult)});
  1235. //>>excludeEnd("ctx");
  1236. },
  1237. //>>excludeStart("ide", pragmas.excludeIdeData);
  1238. args: ["aBlock"],
  1239. 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 ]",
  1240. referencedClasses: [],
  1241. //>>excludeEnd("ide");
  1242. messageSends: ["ifFalse:", "==", "runs", "total", "value:", "+"]
  1243. }),
  1244. $globals.TestResult);
  1245. $core.addMethod(
  1246. $core.method({
  1247. selector: "runCase:",
  1248. protocol: 'running',
  1249. fn: function (aTestCase){
  1250. var self=this;
  1251. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1252. return $core.withContext(function($ctx1) {
  1253. //>>excludeEnd("ctx");
  1254. $recv((function(){
  1255. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1256. return $core.withContext(function($ctx2) {
  1257. //>>excludeEnd("ctx");
  1258. return $recv((function(){
  1259. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1260. return $core.withContext(function($ctx3) {
  1261. //>>excludeEnd("ctx");
  1262. self._increaseRuns();
  1263. return $recv(aTestCase)._runCase();
  1264. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1265. }, function($ctx3) {$ctx3.fillBlock({},$ctx2,2)});
  1266. //>>excludeEnd("ctx");
  1267. }))._on_do_($globals.TestFailure,(function(ex){
  1268. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1269. return $core.withContext(function($ctx3) {
  1270. //>>excludeEnd("ctx");
  1271. return self._addFailure_(aTestCase);
  1272. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1273. }, function($ctx3) {$ctx3.fillBlock({ex:ex},$ctx2,3)});
  1274. //>>excludeEnd("ctx");
  1275. }));
  1276. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1277. }, function($ctx2) {$ctx2.fillBlock({},$ctx1,1)});
  1278. //>>excludeEnd("ctx");
  1279. }))._on_do_($globals.Error,(function(ex){
  1280. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1281. return $core.withContext(function($ctx2) {
  1282. //>>excludeEnd("ctx");
  1283. return self._addError_(aTestCase);
  1284. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1285. }, function($ctx2) {$ctx2.fillBlock({ex:ex},$ctx1,4)});
  1286. //>>excludeEnd("ctx");
  1287. }));
  1288. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1289. $ctx1.sendIdx["on:do:"]=1;
  1290. //>>excludeEnd("ctx");
  1291. return self;
  1292. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1293. }, function($ctx1) {$ctx1.fill(self,"runCase:",{aTestCase:aTestCase},$globals.TestResult)});
  1294. //>>excludeEnd("ctx");
  1295. },
  1296. //>>excludeStart("ide", pragmas.excludeIdeData);
  1297. args: ["aTestCase"],
  1298. 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 ]",
  1299. referencedClasses: ["TestFailure", "Error"],
  1300. //>>excludeEnd("ide");
  1301. messageSends: ["on:do:", "increaseRuns", "runCase", "addFailure:", "addError:"]
  1302. }),
  1303. $globals.TestResult);
  1304. $core.addMethod(
  1305. $core.method({
  1306. selector: "runs",
  1307. protocol: 'accessing',
  1308. fn: function (){
  1309. var self=this;
  1310. return self["@runs"];
  1311. },
  1312. //>>excludeStart("ide", pragmas.excludeIdeData);
  1313. args: [],
  1314. source: "runs\x0a\x09^ runs",
  1315. referencedClasses: [],
  1316. //>>excludeEnd("ide");
  1317. messageSends: []
  1318. }),
  1319. $globals.TestResult);
  1320. $core.addMethod(
  1321. $core.method({
  1322. selector: "status",
  1323. protocol: 'accessing',
  1324. fn: function (){
  1325. var self=this;
  1326. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1327. return $core.withContext(function($ctx1) {
  1328. //>>excludeEnd("ctx");
  1329. var $1;
  1330. $1=$recv(self._errors())._ifNotEmpty_ifEmpty_((function(){
  1331. return "error";
  1332. }),(function(){
  1333. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1334. return $core.withContext(function($ctx2) {
  1335. //>>excludeEnd("ctx");
  1336. return $recv(self._failures())._ifNotEmpty_ifEmpty_((function(){
  1337. return "failure";
  1338. }),(function(){
  1339. return "success";
  1340. }));
  1341. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1342. }, function($ctx2) {$ctx2.fillBlock({},$ctx1,2)});
  1343. //>>excludeEnd("ctx");
  1344. }));
  1345. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1346. $ctx1.sendIdx["ifNotEmpty:ifEmpty:"]=1;
  1347. //>>excludeEnd("ctx");
  1348. return $1;
  1349. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1350. }, function($ctx1) {$ctx1.fill(self,"status",{},$globals.TestResult)});
  1351. //>>excludeEnd("ctx");
  1352. },
  1353. //>>excludeStart("ide", pragmas.excludeIdeData);
  1354. args: [],
  1355. source: "status\x0a\x09^ self errors ifNotEmpty: [ 'error' ] ifEmpty: [\x0a\x09\x09self failures ifNotEmpty: [ 'failure' ] ifEmpty: [\x0a\x09\x09\x09'success' ]]",
  1356. referencedClasses: [],
  1357. //>>excludeEnd("ide");
  1358. messageSends: ["ifNotEmpty:ifEmpty:", "errors", "failures"]
  1359. }),
  1360. $globals.TestResult);
  1361. $core.addMethod(
  1362. $core.method({
  1363. selector: "timestamp",
  1364. protocol: 'accessing',
  1365. fn: function (){
  1366. var self=this;
  1367. return self["@timestamp"];
  1368. },
  1369. //>>excludeStart("ide", pragmas.excludeIdeData);
  1370. args: [],
  1371. source: "timestamp\x0a\x09^ timestamp",
  1372. referencedClasses: [],
  1373. //>>excludeEnd("ide");
  1374. messageSends: []
  1375. }),
  1376. $globals.TestResult);
  1377. $core.addMethod(
  1378. $core.method({
  1379. selector: "total",
  1380. protocol: 'accessing',
  1381. fn: function (){
  1382. var self=this;
  1383. return self["@total"];
  1384. },
  1385. //>>excludeStart("ide", pragmas.excludeIdeData);
  1386. args: [],
  1387. source: "total\x0a\x09^ total",
  1388. referencedClasses: [],
  1389. //>>excludeEnd("ide");
  1390. messageSends: []
  1391. }),
  1392. $globals.TestResult);
  1393. $core.addMethod(
  1394. $core.method({
  1395. selector: "total:",
  1396. protocol: 'accessing',
  1397. fn: function (aNumber){
  1398. var self=this;
  1399. self["@total"]=aNumber;
  1400. return self;
  1401. },
  1402. //>>excludeStart("ide", pragmas.excludeIdeData);
  1403. args: ["aNumber"],
  1404. source: "total: aNumber\x0a\x09total := aNumber",
  1405. referencedClasses: [],
  1406. //>>excludeEnd("ide");
  1407. messageSends: []
  1408. }),
  1409. $globals.TestResult);
  1410. $core.addClass('TestSuiteRunner', $globals.Object, ['suite', 'result', 'announcer', 'runNextTest'], 'SUnit');
  1411. //>>excludeStart("ide", pragmas.excludeIdeData);
  1412. $globals.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`.";
  1413. //>>excludeEnd("ide");
  1414. $core.addMethod(
  1415. $core.method({
  1416. selector: "announcer",
  1417. protocol: 'accessing',
  1418. fn: function (){
  1419. var self=this;
  1420. return self["@announcer"];
  1421. },
  1422. //>>excludeStart("ide", pragmas.excludeIdeData);
  1423. args: [],
  1424. source: "announcer\x0a\x09^ announcer",
  1425. referencedClasses: [],
  1426. //>>excludeEnd("ide");
  1427. messageSends: []
  1428. }),
  1429. $globals.TestSuiteRunner);
  1430. $core.addMethod(
  1431. $core.method({
  1432. selector: "contextOf:",
  1433. protocol: 'private',
  1434. fn: function (anInteger){
  1435. var self=this;
  1436. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1437. return $core.withContext(function($ctx1) {
  1438. //>>excludeEnd("ctx");
  1439. return $recv($globals.ReportingTestContext)._testCase_result_finished_($recv(self["@suite"])._at_(anInteger),self["@result"],(function(){
  1440. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1441. return $core.withContext(function($ctx2) {
  1442. //>>excludeEnd("ctx");
  1443. return self._resume();
  1444. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1445. }, function($ctx2) {$ctx2.fillBlock({},$ctx1,1)});
  1446. //>>excludeEnd("ctx");
  1447. }));
  1448. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1449. }, function($ctx1) {$ctx1.fill(self,"contextOf:",{anInteger:anInteger},$globals.TestSuiteRunner)});
  1450. //>>excludeEnd("ctx");
  1451. },
  1452. //>>excludeStart("ide", pragmas.excludeIdeData);
  1453. args: ["anInteger"],
  1454. source: "contextOf: anInteger\x0a\x09^ ReportingTestContext testCase: (suite at: anInteger) result: result finished: [ self resume ]",
  1455. referencedClasses: ["ReportingTestContext"],
  1456. //>>excludeEnd("ide");
  1457. messageSends: ["testCase:result:finished:", "at:", "resume"]
  1458. }),
  1459. $globals.TestSuiteRunner);
  1460. $core.addMethod(
  1461. $core.method({
  1462. selector: "initialize",
  1463. protocol: 'initialization',
  1464. fn: function (){
  1465. var self=this;
  1466. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1467. return $core.withContext(function($ctx1) {
  1468. //>>excludeEnd("ctx");
  1469. var $1;
  1470. (
  1471. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1472. $ctx1.supercall = true,
  1473. //>>excludeEnd("ctx");
  1474. ($globals.TestSuiteRunner.superclass||$boot.nilAsClass).fn.prototype._initialize.apply($recv(self), []));
  1475. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1476. $ctx1.supercall = false;
  1477. //>>excludeEnd("ctx");;
  1478. self["@announcer"]=$recv($globals.Announcer)._new();
  1479. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1480. $ctx1.sendIdx["new"]=1;
  1481. //>>excludeEnd("ctx");
  1482. self["@result"]=$recv($globals.TestResult)._new();
  1483. self["@runNextTest"]=(function(){
  1484. var runs;
  1485. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1486. return $core.withContext(function($ctx2) {
  1487. //>>excludeEnd("ctx");
  1488. runs=$recv(self["@result"])._runs();
  1489. runs;
  1490. $1=$recv(runs).__lt($recv(self["@result"])._total());
  1491. if($core.assert($1)){
  1492. return $recv(self._contextOf_($recv(runs).__plus((1))))._start();
  1493. }
  1494. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1495. }, function($ctx2) {$ctx2.fillBlock({runs:runs},$ctx1,1)});
  1496. //>>excludeEnd("ctx");
  1497. });
  1498. return self;
  1499. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1500. }, function($ctx1) {$ctx1.fill(self,"initialize",{},$globals.TestSuiteRunner)});
  1501. //>>excludeEnd("ctx");
  1502. },
  1503. //>>excludeStart("ide", pragmas.excludeIdeData);
  1504. args: [],
  1505. 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 ] ].",
  1506. referencedClasses: ["Announcer", "TestResult"],
  1507. //>>excludeEnd("ide");
  1508. messageSends: ["initialize", "new", "runs", "ifTrue:", "<", "total", "start", "contextOf:", "+"]
  1509. }),
  1510. $globals.TestSuiteRunner);
  1511. $core.addMethod(
  1512. $core.method({
  1513. selector: "result",
  1514. protocol: 'accessing',
  1515. fn: function (){
  1516. var self=this;
  1517. return self["@result"];
  1518. },
  1519. //>>excludeStart("ide", pragmas.excludeIdeData);
  1520. args: [],
  1521. source: "result\x0a\x09^ result",
  1522. referencedClasses: [],
  1523. //>>excludeEnd("ide");
  1524. messageSends: []
  1525. }),
  1526. $globals.TestSuiteRunner);
  1527. $core.addMethod(
  1528. $core.method({
  1529. selector: "resume",
  1530. protocol: 'actions',
  1531. fn: function (){
  1532. var self=this;
  1533. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1534. return $core.withContext(function($ctx1) {
  1535. //>>excludeEnd("ctx");
  1536. $recv(self["@runNextTest"])._fork();
  1537. $recv(self["@announcer"])._announce_($recv($recv($globals.ResultAnnouncement)._new())._result_(self["@result"]));
  1538. return self;
  1539. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1540. }, function($ctx1) {$ctx1.fill(self,"resume",{},$globals.TestSuiteRunner)});
  1541. //>>excludeEnd("ctx");
  1542. },
  1543. //>>excludeStart("ide", pragmas.excludeIdeData);
  1544. args: [],
  1545. source: "resume\x0a\x09runNextTest fork.\x0a\x09announcer announce: (ResultAnnouncement new result: result)",
  1546. referencedClasses: ["ResultAnnouncement"],
  1547. //>>excludeEnd("ide");
  1548. messageSends: ["fork", "announce:", "result:", "new"]
  1549. }),
  1550. $globals.TestSuiteRunner);
  1551. $core.addMethod(
  1552. $core.method({
  1553. selector: "run",
  1554. protocol: 'actions',
  1555. fn: function (){
  1556. var self=this;
  1557. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1558. return $core.withContext(function($ctx1) {
  1559. //>>excludeEnd("ctx");
  1560. $recv(self["@result"])._total_($recv(self["@suite"])._size());
  1561. self._resume();
  1562. return self;
  1563. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1564. }, function($ctx1) {$ctx1.fill(self,"run",{},$globals.TestSuiteRunner)});
  1565. //>>excludeEnd("ctx");
  1566. },
  1567. //>>excludeStart("ide", pragmas.excludeIdeData);
  1568. args: [],
  1569. source: "run\x0a\x09result total: suite size.\x0a\x09self resume",
  1570. referencedClasses: [],
  1571. //>>excludeEnd("ide");
  1572. messageSends: ["total:", "size", "resume"]
  1573. }),
  1574. $globals.TestSuiteRunner);
  1575. $core.addMethod(
  1576. $core.method({
  1577. selector: "suite:",
  1578. protocol: 'accessing',
  1579. fn: function (aCollection){
  1580. var self=this;
  1581. self["@suite"]=aCollection;
  1582. return self;
  1583. },
  1584. //>>excludeStart("ide", pragmas.excludeIdeData);
  1585. args: ["aCollection"],
  1586. source: "suite: aCollection\x0a\x09suite := aCollection",
  1587. referencedClasses: [],
  1588. //>>excludeEnd("ide");
  1589. messageSends: []
  1590. }),
  1591. $globals.TestSuiteRunner);
  1592. $core.addMethod(
  1593. $core.method({
  1594. selector: "new",
  1595. protocol: 'instance creation',
  1596. fn: function (){
  1597. var self=this;
  1598. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1599. return $core.withContext(function($ctx1) {
  1600. //>>excludeEnd("ctx");
  1601. self._shouldNotImplement();
  1602. return self;
  1603. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1604. }, function($ctx1) {$ctx1.fill(self,"new",{},$globals.TestSuiteRunner.klass)});
  1605. //>>excludeEnd("ctx");
  1606. },
  1607. //>>excludeStart("ide", pragmas.excludeIdeData);
  1608. args: [],
  1609. source: "new\x0a\x09self shouldNotImplement",
  1610. referencedClasses: [],
  1611. //>>excludeEnd("ide");
  1612. messageSends: ["shouldNotImplement"]
  1613. }),
  1614. $globals.TestSuiteRunner.klass);
  1615. $core.addMethod(
  1616. $core.method({
  1617. selector: "on:",
  1618. protocol: 'instance creation',
  1619. fn: function (aCollection){
  1620. var self=this;
  1621. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1622. return $core.withContext(function($ctx1) {
  1623. //>>excludeEnd("ctx");
  1624. var $1;
  1625. $1=(
  1626. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1627. $ctx1.supercall = true,
  1628. //>>excludeEnd("ctx");
  1629. ($globals.TestSuiteRunner.klass.superclass||$boot.nilAsClass).fn.prototype._new.apply($recv(self), []));
  1630. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1631. $ctx1.supercall = false;
  1632. //>>excludeEnd("ctx");;
  1633. return $recv($1)._suite_(aCollection);
  1634. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1635. }, function($ctx1) {$ctx1.fill(self,"on:",{aCollection:aCollection},$globals.TestSuiteRunner.klass)});
  1636. //>>excludeEnd("ctx");
  1637. },
  1638. //>>excludeStart("ide", pragmas.excludeIdeData);
  1639. args: ["aCollection"],
  1640. source: "on: aCollection\x0a\x09^ super new suite: aCollection",
  1641. referencedClasses: [],
  1642. //>>excludeEnd("ide");
  1643. messageSends: ["suite:", "new"]
  1644. }),
  1645. $globals.TestSuiteRunner.klass);
  1646. $core.addMethod(
  1647. $core.method({
  1648. selector: "isTestClass",
  1649. protocol: '*SUnit',
  1650. fn: function (){
  1651. var self=this;
  1652. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1653. return $core.withContext(function($ctx1) {
  1654. //>>excludeEnd("ctx");
  1655. return $recv(self._includesBehavior_($globals.TestCase))._and_((function(){
  1656. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1657. return $core.withContext(function($ctx2) {
  1658. //>>excludeEnd("ctx");
  1659. return $recv(self._isAbstract())._not();
  1660. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1661. }, function($ctx2) {$ctx2.fillBlock({},$ctx1,1)});
  1662. //>>excludeEnd("ctx");
  1663. }));
  1664. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1665. }, function($ctx1) {$ctx1.fill(self,"isTestClass",{},$globals.Behavior)});
  1666. //>>excludeEnd("ctx");
  1667. },
  1668. //>>excludeStart("ide", pragmas.excludeIdeData);
  1669. args: [],
  1670. source: "isTestClass\x0a\x09^(self includesBehavior: TestCase) and: [ \x0a\x09\x09\x09self isAbstract not ]",
  1671. referencedClasses: ["TestCase"],
  1672. //>>excludeEnd("ide");
  1673. messageSends: ["and:", "includesBehavior:", "not", "isAbstract"]
  1674. }),
  1675. $globals.Behavior);
  1676. $core.addMethod(
  1677. $core.method({
  1678. selector: "isTestPackage",
  1679. protocol: '*SUnit',
  1680. fn: function (){
  1681. var self=this;
  1682. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1683. return $core.withContext(function($ctx1) {
  1684. //>>excludeEnd("ctx");
  1685. return $recv(self._classes())._anySatisfy_((function(each){
  1686. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1687. return $core.withContext(function($ctx2) {
  1688. //>>excludeEnd("ctx");
  1689. return $recv(each)._isTestClass();
  1690. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1691. }, function($ctx2) {$ctx2.fillBlock({each:each},$ctx1,1)});
  1692. //>>excludeEnd("ctx");
  1693. }));
  1694. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1695. }, function($ctx1) {$ctx1.fill(self,"isTestPackage",{},$globals.Package)});
  1696. //>>excludeEnd("ctx");
  1697. },
  1698. //>>excludeStart("ide", pragmas.excludeIdeData);
  1699. args: [],
  1700. source: "isTestPackage\x0a\x09^ self classes anySatisfy: [ :each | each isTestClass ]",
  1701. referencedClasses: [],
  1702. //>>excludeEnd("ide");
  1703. messageSends: ["anySatisfy:", "classes", "isTestClass"]
  1704. }),
  1705. $globals.Package);
  1706. });