Helios-SUnit.st 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719
  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 isTestClass ] ) ].
  325. ^ stream contents
  326. !
  327. testPackages
  328. "Answer all packages containing concrete subclasses of TestCase"
  329. ^ self environment packages
  330. select: [ :each | each isTestPackage ]
  331. !
  332. testResult
  333. ^testResult ifNil: [testResult := TestResult new]
  334. ! !
  335. !HLSUnitModel methodsFor: 'actions'!
  336. invertSelectedClasses
  337. self testClasses do: [:each |
  338. (self unfilteredSelectedClasses includes: each)
  339. ifTrue: [ self unselectClass: each ]
  340. ifFalse: [ self selectClass: each ]].
  341. !
  342. invertSelectedPackages
  343. self testPackages do: [:each |
  344. (self selectedPackages includes: each)
  345. ifTrue: [ self unselectPackage: each ]
  346. ifFalse: [ self selectPackage: each ]].
  347. !
  348. runTests
  349. | worker |
  350. worker := TestSuiteRunner on: self testCases.
  351. testResult := worker result.
  352. self announcer announce: (HLRunTests on: worker).
  353. self subscribeToTestSuite: worker.
  354. worker run
  355. !
  356. selectAllClasses
  357. self testClasses do: [:each | self selectClass: each].
  358. !
  359. selectAllPackages
  360. self testPackages do: [:each | self selectPackage: each].
  361. !
  362. selectClass: aClass
  363. self unfilteredSelectedClasses add: aClass.
  364. self announcer announce: (HLClassSelected on: aClass).
  365. !
  366. selectPackage: aPackage
  367. self selectedPackages add: aPackage.
  368. self announcer announce: (HLPackageSelected on: aPackage).
  369. !
  370. subscribeToTestSuite: aTestSuiteRunner
  371. currentSuite ifNotNil: [ currentSuite announcer unsubscribe: self].
  372. currentSuite := aTestSuiteRunner.
  373. currentSuite announcer
  374. on: ResultAnnouncement
  375. send: #onResultAnnouncement:
  376. to: self
  377. !
  378. unselectClass: aClass
  379. self unfilteredSelectedClasses remove: aClass ifAbsent: [^self].
  380. self announcer announce: (HLClassUnselected on: aClass).
  381. !
  382. unselectPackage: aPackage
  383. self selectedPackages remove: aPackage ifAbsent: [^self].
  384. self announcer announce: (HLPackageUnselected on: aPackage).
  385. ! !
  386. !HLSUnitModel methodsFor: 'private'!
  387. unfilteredSelectedClasses
  388. ^ (selectedClasses ifNil: [ selectedClasses := Set new ])
  389. ! !
  390. !HLSUnitModel methodsFor: 'reacting'!
  391. onResultAnnouncement: announcement
  392. "Propogate announcement"
  393. self announcer announce: announcement.
  394. ! !
  395. HLToolListWidget subclass: #HLSUnitResultListWidget
  396. instanceVariableNames: ''
  397. package: 'Helios-SUnit'!
  398. !HLSUnitResultListWidget commentStamp!
  399. I group the lists that display test results!
  400. !HLSUnitResultListWidget methodsFor: 'actions'!
  401. performFailure: aTestCase
  402. aTestCase runCase
  403. ! !
  404. !HLSUnitResultListWidget methodsFor: 'initialization'!
  405. observeModel
  406. self model announcer
  407. on: ResultAnnouncement
  408. send: #onResultAnnouncement:
  409. to: self
  410. ! !
  411. !HLSUnitResultListWidget methodsFor: 'reacting'!
  412. onResultAnnouncement: announcement
  413. self refresh.
  414. ! !
  415. !HLSUnitResultListWidget methodsFor: 'rendering'!
  416. renderItemLabel: anObject on: html
  417. html with: anObject class name, ' >> ', anObject selector
  418. !
  419. reselectItem: anObject
  420. self performFailure: anObject
  421. ! !
  422. HLSUnitResultListWidget subclass: #HLSUnitErrorsListWidget
  423. instanceVariableNames: ''
  424. package: 'Helios-SUnit'!
  425. !HLSUnitErrorsListWidget commentStamp!
  426. I display a list of tests that have errors!
  427. !HLSUnitErrorsListWidget methodsFor: 'accessing'!
  428. items
  429. ^self model testResult errors
  430. !
  431. label
  432. ^'Errors'
  433. ! !
  434. HLSUnitResultListWidget subclass: #HLSUnitFailuresListWidget
  435. instanceVariableNames: ''
  436. package: 'Helios-SUnit'!
  437. !HLSUnitFailuresListWidget commentStamp!
  438. I display a list of tests that have failures!
  439. !HLSUnitFailuresListWidget methodsFor: 'accessing'!
  440. items
  441. ^self model testResult failures
  442. !
  443. label
  444. ^'Failures'
  445. ! !
  446. HLWidget subclass: #HLSUnitResultStatus
  447. instanceVariableNames: 'model'
  448. package: 'Helios-SUnit'!
  449. !HLSUnitResultStatus commentStamp!
  450. I display the status of the previous test run
  451. 1. How many tests where run.
  452. * How many tests passed.
  453. * How many tests failed.
  454. * How many tests resulted in an error.!
  455. !HLSUnitResultStatus methodsFor: 'accessing'!
  456. model
  457. ^ model ifNil: [model := TestResult new]
  458. !
  459. model: anObject
  460. model := anObject.
  461. self observeModel.
  462. !
  463. result
  464. ^ self model testResult
  465. !
  466. statusCssClass
  467. ^'sunit status ', self result status
  468. !
  469. statusInfo
  470. ^ self printTotal, self printPasses, self printErrors, self printFailures
  471. ! !
  472. !HLSUnitResultStatus methodsFor: 'actions'!
  473. observeModel
  474. self model announcer
  475. on: ResultAnnouncement
  476. send: #onResultAnnouncement:
  477. to: self
  478. ! !
  479. !HLSUnitResultStatus methodsFor: 'printing'!
  480. printErrors
  481. ^ self result errors size asString , ' errors, '
  482. !
  483. printFailures
  484. ^ self result failures size asString, ' failures'
  485. !
  486. printPasses
  487. ^ (self result runs - self result errors size - self result failures size) asString , ' passes, '
  488. !
  489. printTotal
  490. ^ self result total asString, ' runs, '
  491. ! !
  492. !HLSUnitResultStatus methodsFor: 'reacting'!
  493. onResultAnnouncement: announcement
  494. self refresh.
  495. ! !
  496. !HLSUnitResultStatus methodsFor: 'rendering'!
  497. renderContentOn: html
  498. html div
  499. class: self statusCssClass;
  500. with: [ html span with: self statusInfo ]
  501. ! !
  502. HLWidget subclass: #HLSUnitResults
  503. instanceVariableNames: 'model progressBarWidget resultStatusWidget'
  504. package: 'Helios-SUnit'!
  505. !HLSUnitResults commentStamp!
  506. I am the widget that displays the test results for a previous test run in Helios.
  507. I display.
  508. 1. The status of the tests.
  509. * Progress of the currently running test suite.!
  510. !HLSUnitResults methodsFor: 'accessing'!
  511. model
  512. ^model
  513. !
  514. model: anObject
  515. model := anObject.
  516. self observeModel
  517. !
  518. progressBarWidget
  519. ^progressBarWidget ifNil: [progressBarWidget := HLProgressBarWidget new
  520. label: '';
  521. yourself]
  522. !
  523. resultStatusWidget
  524. ^resultStatusWidget ifNil: [resultStatusWidget := HLSUnitResultStatus new
  525. model: self model;
  526. yourself]
  527. ! !
  528. !HLSUnitResults methodsFor: 'initialization'!
  529. observeModel
  530. self model announcer
  531. on: HLRunTests
  532. send: #onRunTests:
  533. to: self;
  534. on: ResultAnnouncement
  535. send: #onResultAnnouncement:
  536. to: self
  537. ! !
  538. !HLSUnitResults methodsFor: 'reacting'!
  539. onResultAnnouncement: announcement
  540. [self progressBarWidget
  541. updateProgress: (self model testResult runs / self model testResult total * 100) rounded] valueWithTimeout: 10
  542. !
  543. onRunTests: announcement
  544. self progressBarWidget updateProgress: 0;
  545. refresh.
  546. ! !
  547. !HLSUnitResults methodsFor: 'rendering'!
  548. renderContentOn: html
  549. html with: self resultStatusWidget;
  550. with: self progressBarWidget
  551. ! !