1
0

Helios-SUnit.st 13 KB

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