1
0

SUnit.js 57 KB

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