2
0

SUnit.js 42 KB

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