2
0

SUnit.js 42 KB

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