Helios-SUnit.st 12 KB

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