Helios-SUnit.st 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720
  1. Smalltalk createPackage: 'Helios-SUnit'!
  2. HLToolListWidget subclass: #HLMultiSelectToolListWidget
  3. instanceVariableNames: ''
  4. package: 'Helios-SUnit'!
  5. !HLMultiSelectToolListWidget commentStamp!
  6. This is a list that handles multiple selection!
  7. !HLMultiSelectToolListWidget methodsFor: 'accessing'!
  8. activeItemCssClass
  9. ^'selector'
  10. !
  11. listCssClass
  12. ^'nav nav-multiselect nav-pills nav-stacked'
  13. !
  14. listCssClassForItem: anObject
  15. ^(super listCssClassForItem: anObject), ((self isSelected: anObject)
  16. ifTrue: [' active']
  17. ifFalse: ['']).
  18. ! !
  19. !HLMultiSelectToolListWidget methodsFor: 'actions'!
  20. select: anObject
  21. self subclassResponsibility
  22. !
  23. toggleListItem: aListItem
  24. | item |
  25. (aListItem get: 0) ifNil: [ ^ self ].
  26. "Find item"
  27. item := aListItem data: 'item'.
  28. self toggleSelection: item
  29. !
  30. toggleSelection: anObject
  31. (self isSelected: anObject)
  32. ifTrue: [ self unselect: anObject ]
  33. ifFalse: [self select: anObject ]
  34. !
  35. unselect: anObject
  36. self subclassResponsibility
  37. ! !
  38. !HLMultiSelectToolListWidget methodsFor: 'rendering'!
  39. reselectItem: anObject
  40. anObject ifNil: [^self].
  41. self toggleSelection: anObject
  42. ! !
  43. !HLMultiSelectToolListWidget methodsFor: 'testing'!
  44. isSelected: anObject
  45. self subclassResponsibility
  46. ! !
  47. HLMultiSelectToolListWidget subclass: #HLSUnitClassesListWidget
  48. instanceVariableNames: ''
  49. package: 'Helios-SUnit'!
  50. !HLSUnitClassesListWidget commentStamp!
  51. I display a list of classes (subclasses of `TestCase`).!
  52. !HLSUnitClassesListWidget methodsFor: 'accessing'!
  53. buttonsDivCssClass
  54. ^ 'buttons_bar'
  55. !
  56. cssClassForItem: aClass
  57. ^ aClass theNonMetaClass heliosClass
  58. !
  59. items
  60. ^ items ifNil: [ self initializeItems ]
  61. !
  62. label
  63. ^ 'Classes'
  64. ! !
  65. !HLSUnitClassesListWidget methodsFor: 'actions'!
  66. observeModel
  67. self model announcer
  68. on: HLPackageSelected
  69. send: #onPackageSelected:
  70. to: self;
  71. on: HLPackageUnselected
  72. send: #onPackageUnselected:
  73. to: self;
  74. on: HLClassSelected
  75. send: #onClassSelected:
  76. to: self;
  77. on: HLClassUnselected
  78. send: #onClassUnselected:
  79. to: self.
  80. !
  81. observeSystem
  82. self model systemAnnouncer
  83. on: ClassAdded
  84. send: #onClassAdded:
  85. to: self.
  86. !
  87. select: anObject
  88. model selectClass: anObject
  89. !
  90. unselect: anObject
  91. model unselectClass: anObject
  92. ! !
  93. !HLSUnitClassesListWidget methodsFor: 'initialization'!
  94. initializeItems
  95. ^items := model testClasses
  96. ! !
  97. !HLSUnitClassesListWidget methodsFor: 'reactions'!
  98. onClassAdded: anAnnouncement
  99. (self model selectedPackages includes: anAnnouncement theClass package)
  100. ifTrue: [
  101. self
  102. initializeItems;
  103. refresh ]
  104. !
  105. onClassSelected: anAnnouncement
  106. | listItem |
  107. listItem := self findListItemFor: anAnnouncement item.
  108. listItem addClass: 'active'.
  109. !
  110. onClassUnselected: anAnnouncement
  111. | listItem |
  112. listItem := self findListItemFor: anAnnouncement item.
  113. listItem removeClass: 'active'.
  114. !
  115. onPackageSelected: anAnnouncement
  116. self initializeItems;
  117. refresh
  118. !
  119. onPackageUnselected: anAnnouncement
  120. self initializeItems;
  121. refresh
  122. ! !
  123. !HLSUnitClassesListWidget methodsFor: 'rendering'!
  124. renderButtonsOn: html
  125. html button
  126. class: 'button';
  127. with: 'Select all';
  128. with: [ self model selectAllClasses ]
  129. !
  130. renderItemLabel: aClass on: html
  131. html with: aClass name
  132. ! !
  133. !HLSUnitClassesListWidget methodsFor: 'testing'!
  134. isSelected: anObject
  135. ^model selectedClasses includes: anObject
  136. ! !
  137. HLMultiSelectToolListWidget subclass: #HLSUnitPackagesListWidget
  138. instanceVariableNames: ''
  139. package: 'Helios-SUnit'!
  140. !HLSUnitPackagesListWidget commentStamp!
  141. I display a list of packages for which unit tests are associated (packages containing subclasses of `TestCase`).!
  142. !HLSUnitPackagesListWidget methodsFor: 'accessing'!
  143. buttonsDivCssClass
  144. ^ 'buttons_bar'
  145. !
  146. cssClassForItem: anItem
  147. ^ anItem isDirty
  148. ifTrue: [ 'package_dirty' ]
  149. ifFalse: [ 'package' ]
  150. !
  151. items
  152. ^ items ifNil: [ self initializeItems ]
  153. !
  154. label
  155. ^ 'Packages'
  156. ! !
  157. !HLSUnitPackagesListWidget methodsFor: 'actions'!
  158. observeModel
  159. self model announcer
  160. on: HLPackageSelected
  161. send: #onPackageSelected:
  162. to: self;
  163. on: HLPackageUnselected
  164. send: #onPackageUnselected:
  165. to: self
  166. !
  167. observeSystem
  168. self model systemAnnouncer
  169. on: ClassAdded
  170. send: #onClassAdded:
  171. to: self.
  172. !
  173. select: anObject
  174. model selectPackage: anObject
  175. !
  176. unselect: anObject
  177. model unselectPackage: anObject
  178. ! !
  179. !HLSUnitPackagesListWidget methodsFor: 'initialization'!
  180. initializeItems
  181. ^items := model testPackages
  182. sort: [:a :b | a name < b name]
  183. ! !
  184. !HLSUnitPackagesListWidget methodsFor: 'reactions'!
  185. onClassAdded: anAnnouncement
  186. ((self items includes: anAnnouncement theClass package) not and: [anAnnouncement theClass package isTestPackage])
  187. ifTrue: [
  188. self
  189. initializeItems;
  190. refresh ]
  191. !
  192. onPackageSelected: anAnnouncement
  193. | listItem |
  194. listItem := self findListItemFor: anAnnouncement item.
  195. listItem addClass: 'active'.
  196. !
  197. onPackageUnselected: anAnnouncement
  198. | listItem |
  199. listItem := self findListItemFor: anAnnouncement item.
  200. listItem removeClass: 'active'.
  201. ! !
  202. !HLSUnitPackagesListWidget methodsFor: 'rendering'!
  203. renderButtonsOn: html
  204. html button
  205. class: 'button';
  206. with: 'Run Tests';
  207. onClick: [ self model runTests ].
  208. html button
  209. class: 'button';
  210. with: 'Select all';
  211. onClick: [ self model selectAllPackages ]
  212. !
  213. renderItemLabel: aPackage on: html
  214. html with: aPackage name
  215. ! !
  216. !HLSUnitPackagesListWidget methodsFor: 'testing'!
  217. isSelected: anObject
  218. ^model selectedPackages includes: anObject
  219. ! !
  220. HLWidget subclass: #HLSUnit
  221. instanceVariableNames: 'model packagesListWidget classesListWidget resultWidget failuresWidget errorsWidget'
  222. package: 'Helios-SUnit'!
  223. !HLSUnit commentStamp!
  224. I am the main widget for running unit tests in Helios.
  225. I provide the ability to select set of tests to run per package, and a detailed result log with passed tests, failed tests and errors.!
  226. !HLSUnit methodsFor: 'accessing'!
  227. model
  228. ^ model ifNil: [ model := HLSUnitModel new ]
  229. !
  230. resultSection
  231. ^HLHorizontalSplitter
  232. with: self resultWidget
  233. with: (HLHorizontalSplitter
  234. with: self failuresWidget
  235. with: self errorsWidget)
  236. ! !
  237. !HLSUnit methodsFor: 'keybindings'!
  238. registerBindingsOn: aBindingGroup
  239. HLToolCommand
  240. registerConcreteClassesOn: aBindingGroup
  241. for: self model
  242. ! !
  243. !HLSUnit methodsFor: 'rendering'!
  244. renderContentOn: html
  245. | resultSection |
  246. html with: (HLContainer with: (
  247. HLVerticalSplitter
  248. with: (HLVerticalSplitter
  249. with: self packagesListWidget
  250. with: self classesListWidget)
  251. with: (resultSection := self resultSection))).
  252. [resultSection resize: 0] valueWithTimeout: 100.
  253. self packagesListWidget focus
  254. ! !
  255. !HLSUnit methodsFor: 'widgets'!
  256. classesListWidget
  257. ^ classesListWidget ifNil: [
  258. classesListWidget := HLSUnitClassesListWidget on: self model.
  259. classesListWidget next: self failuresWidget ]
  260. !
  261. errorsWidget
  262. ^ errorsWidget ifNil: [errorsWidget := HLSUnitErrorsListWidget on: self model]
  263. !
  264. failuresWidget
  265. ^ failuresWidget ifNil: [
  266. failuresWidget := HLSUnitFailuresListWidget on: self model.
  267. failuresWidget next: self errorsWidget]
  268. !
  269. packagesListWidget
  270. ^ packagesListWidget ifNil: [
  271. packagesListWidget := HLSUnitPackagesListWidget on: self model.
  272. packagesListWidget next: self classesListWidget]
  273. !
  274. resultWidget
  275. ^ resultWidget ifNil: [
  276. resultWidget := HLSUnitResults new
  277. model: self model;
  278. yourself]
  279. ! !
  280. !HLSUnit class methodsFor: 'accessing'!
  281. tabClass
  282. ^ 'sunit'
  283. !
  284. tabLabel
  285. ^ 'SUnit'
  286. !
  287. tabPriority
  288. ^ 1000
  289. ! !
  290. !HLSUnit class methodsFor: 'testing'!
  291. canBeOpenAsTab
  292. ^ true
  293. ! !
  294. HLModel subclass: #HLSUnitModel
  295. instanceVariableNames: 'selectedPackages selectedClasses testResult currentSuite'
  296. package: 'Helios-SUnit'!
  297. !HLSUnitModel commentStamp!
  298. I am the model for running unit tests in Helios.
  299. I provide the ability to select set of tests to run per package, and a detailed result log with passed tests, failed tests and errors.!
  300. !HLSUnitModel methodsFor: 'accessing'!
  301. currentSuite
  302. ^currentSuite
  303. !
  304. selectedClasses
  305. ^ (self unfilteredSelectedClasses) select: [ :each |
  306. self selectedPackages includes: each package ]
  307. !
  308. selectedPackages
  309. ^ selectedPackages ifNil: [ selectedPackages := Set new ]
  310. !
  311. testCases
  312. | testCases |
  313. testCases := #().
  314. self selectedClasses
  315. do: [ :each | testCases addAll: each buildSuite ].
  316. ^ testCases
  317. !
  318. testClasses
  319. "Answer all concrete subclasses of TestCase in selected packages"
  320. | stream |
  321. stream := Array new writeStream.
  322. self selectedPackages do: [ :package |
  323. stream nextPutAll: (package classes select: [ :each |
  324. (each includesBehavior: TestCase) and: [
  325. each isAbstract not ] ] ) ].
  326. ^ stream contents
  327. !
  328. testPackages
  329. "Answer all packages containing concrete subclasses of TestCase"
  330. ^ self environment packages
  331. select: [ :each | each isTestPackage ]
  332. !
  333. testResult
  334. ^testResult ifNil: [testResult := TestResult new]
  335. ! !
  336. !HLSUnitModel methodsFor: 'actions'!
  337. invertSelectedClasses
  338. self testClasses do: [:each |
  339. (self unfilteredSelectedClasses includes: each)
  340. ifTrue: [ self unselectClass: each ]
  341. ifFalse: [ self selectClass: each ]].
  342. !
  343. invertSelectedPackages
  344. self testPackages do: [:each |
  345. (self selectedPackages includes: each)
  346. ifTrue: [ self unselectPackage: each ]
  347. ifFalse: [ self selectPackage: each ]].
  348. !
  349. runTests
  350. | worker |
  351. worker := TestSuiteRunner on: self testCases.
  352. testResult := worker result.
  353. self announcer announce: (HLRunTests on: worker).
  354. self subscribeToTestSuite: worker.
  355. worker run
  356. !
  357. selectAllClasses
  358. self testClasses do: [:each | self selectClass: each].
  359. !
  360. selectAllPackages
  361. self testPackages do: [:each | self selectPackage: each].
  362. !
  363. selectClass: aClass
  364. self unfilteredSelectedClasses add: aClass.
  365. self announcer announce: (HLClassSelected on: aClass).
  366. !
  367. selectPackage: aPackage
  368. self selectedPackages add: aPackage.
  369. self announcer announce: (HLPackageSelected on: aPackage).
  370. !
  371. subscribeToTestSuite: aTestSuiteRunner
  372. currentSuite ifNotNil: [ currentSuite announcer unsubscribe: self].
  373. currentSuite := aTestSuiteRunner.
  374. currentSuite announcer
  375. on: ResultAnnouncement
  376. send: #onResultAnnouncement:
  377. to: self
  378. !
  379. unselectClass: aClass
  380. self unfilteredSelectedClasses remove: aClass ifAbsent: [^self].
  381. self announcer announce: (HLClassUnselected on: aClass).
  382. !
  383. unselectPackage: aPackage
  384. self selectedPackages remove: aPackage ifAbsent: [^self].
  385. self announcer announce: (HLPackageUnselected on: aPackage).
  386. ! !
  387. !HLSUnitModel methodsFor: 'private'!
  388. unfilteredSelectedClasses
  389. ^ (selectedClasses ifNil: [ selectedClasses := Set new ])
  390. ! !
  391. !HLSUnitModel methodsFor: 'reacting'!
  392. onResultAnnouncement: announcement
  393. "Propogate announcement"
  394. self announcer announce: announcement.
  395. ! !
  396. HLToolListWidget subclass: #HLSUnitResultListWidget
  397. instanceVariableNames: ''
  398. package: 'Helios-SUnit'!
  399. !HLSUnitResultListWidget commentStamp!
  400. I group the lists that display test results!
  401. !HLSUnitResultListWidget methodsFor: 'actions'!
  402. performFailure: aTestCase
  403. aTestCase runCase
  404. ! !
  405. !HLSUnitResultListWidget methodsFor: 'initialization'!
  406. observeModel
  407. self model announcer
  408. on: ResultAnnouncement
  409. send: #onResultAnnouncement:
  410. to: self
  411. ! !
  412. !HLSUnitResultListWidget methodsFor: 'reacting'!
  413. onResultAnnouncement: announcement
  414. self refresh.
  415. ! !
  416. !HLSUnitResultListWidget methodsFor: 'rendering'!
  417. renderItemLabel: anObject on: html
  418. html with: anObject class name, ' >> ', anObject selector
  419. !
  420. reselectItem: anObject
  421. self performFailure: anObject
  422. ! !
  423. HLSUnitResultListWidget subclass: #HLSUnitErrorsListWidget
  424. instanceVariableNames: ''
  425. package: 'Helios-SUnit'!
  426. !HLSUnitErrorsListWidget commentStamp!
  427. I display a list of tests that have errors!
  428. !HLSUnitErrorsListWidget methodsFor: 'accessing'!
  429. items
  430. ^self model testResult errors
  431. !
  432. label
  433. ^'Errors'
  434. ! !
  435. HLSUnitResultListWidget subclass: #HLSUnitFailuresListWidget
  436. instanceVariableNames: ''
  437. package: 'Helios-SUnit'!
  438. !HLSUnitFailuresListWidget commentStamp!
  439. I display a list of tests that have failures!
  440. !HLSUnitFailuresListWidget methodsFor: 'accessing'!
  441. items
  442. ^self model testResult failures
  443. !
  444. label
  445. ^'Failures'
  446. ! !
  447. HLWidget subclass: #HLSUnitResultStatus
  448. instanceVariableNames: 'model'
  449. package: 'Helios-SUnit'!
  450. !HLSUnitResultStatus commentStamp!
  451. I display the status of the previous test run
  452. 1. How many tests where run.
  453. * How many tests passed.
  454. * How many tests failed.
  455. * How many tests resulted in an error.!
  456. !HLSUnitResultStatus methodsFor: 'accessing'!
  457. model
  458. ^ model ifNil: [model := TestResult new]
  459. !
  460. model: anObject
  461. model := anObject.
  462. self observeModel.
  463. !
  464. result
  465. ^ self model testResult
  466. !
  467. statusCssClass
  468. ^'sunit status ', self result status
  469. !
  470. statusInfo
  471. ^ self printTotal, self printPasses, self printErrors, self printFailures
  472. ! !
  473. !HLSUnitResultStatus methodsFor: 'actions'!
  474. observeModel
  475. self model announcer
  476. on: ResultAnnouncement
  477. send: #onResultAnnouncement:
  478. to: self
  479. ! !
  480. !HLSUnitResultStatus methodsFor: 'printing'!
  481. printErrors
  482. ^ self result errors size asString , ' errors, '
  483. !
  484. printFailures
  485. ^ self result failures size asString, ' failures'
  486. !
  487. printPasses
  488. ^ (self result runs - self result errors size - self result failures size) asString , ' passes, '
  489. !
  490. printTotal
  491. ^ self result total asString, ' runs, '
  492. ! !
  493. !HLSUnitResultStatus methodsFor: 'reacting'!
  494. onResultAnnouncement: announcement
  495. self refresh.
  496. ! !
  497. !HLSUnitResultStatus methodsFor: 'rendering'!
  498. renderContentOn: html
  499. html div
  500. class: self statusCssClass;
  501. with: [ html span with: self statusInfo ]
  502. ! !
  503. HLWidget subclass: #HLSUnitResults
  504. instanceVariableNames: 'model progressBarWidget resultStatusWidget'
  505. package: 'Helios-SUnit'!
  506. !HLSUnitResults commentStamp!
  507. I am the widget that displays the test results for a previous test run in Helios.
  508. I display.
  509. 1. The status of the tests.
  510. * Progress of the currently running test suite.!
  511. !HLSUnitResults methodsFor: 'accessing'!
  512. model
  513. ^model
  514. !
  515. model: anObject
  516. model := anObject.
  517. self observeModel
  518. !
  519. progressBarWidget
  520. ^progressBarWidget ifNil: [progressBarWidget := HLProgressBarWidget new
  521. label: '';
  522. yourself]
  523. !
  524. resultStatusWidget
  525. ^resultStatusWidget ifNil: [resultStatusWidget := HLSUnitResultStatus new
  526. model: self model;
  527. yourself]
  528. ! !
  529. !HLSUnitResults methodsFor: 'initialization'!
  530. observeModel
  531. self model announcer
  532. on: HLRunTests
  533. send: #onRunTests:
  534. to: self;
  535. on: ResultAnnouncement
  536. send: #onResultAnnouncement:
  537. to: self
  538. ! !
  539. !HLSUnitResults methodsFor: 'reacting'!
  540. onResultAnnouncement: announcement
  541. [self progressBarWidget
  542. updateProgress: (self model testResult runs / self model testResult total * 100) rounded] valueWithTimeout: 10
  543. !
  544. onRunTests: announcement
  545. self progressBarWidget updateProgress: 0;
  546. refresh.
  547. ! !
  548. !HLSUnitResults methodsFor: 'rendering'!
  549. renderContentOn: html
  550. html with: self resultStatusWidget;
  551. with: self progressBarWidget
  552. ! !