SUnit.js 58 KB

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