forked from pharo-project/pharo
/
DrTests.class.st
526 lines (458 loc) · 13.9 KB
/
DrTests.class.st
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
"
I provide the ability to:
* select a plugin to create/run tests
* select sets of items to analyze
* obtain a detailed log of the results
UI Description
___________
The droplist contains all the plugins available to start the analysis.
My left-most pane lists all of the categories that contain items (could subclasses of TestCase, executable comments, etc.); Once items are selected, the items that can be analyzed appear in the pane to right.
The right-most pane shows the results in different groups, depends the plugin's analysis.
Run and browse buttons behaviour are defined by the current plugin selected.
"
Class {
#name : #DrTests,
#superclass : #AbstractDrTestsUI,
#instVars : [
'pluginsDropList',
'packagesList',
'resultsList',
'statusLabel',
'plugins',
'itemsList',
'resultViewsDropList',
'pluginResult',
'resultLabel'
],
#category : #'DrTests-Spec'
}
{ #category : #'tools registry' }
DrTests class >> beDefaultTestRunner [
<script>
self registerToolsOn: Smalltalk tools
]
{ #category : #commands }
DrTests class >> buildCommandsGroupWith: presenterInstance forRoot: rootCommandGroup [
rootCommandGroup
register: (self buildContextualPackageGroupWith: presenterInstance);
register: (self buildItemsListGroupWith: presenterInstance);
register: (self buildResultGroupWith: presenterInstance)
]
{ #category : #commands }
DrTests class >> buildContextualPackageGroupWith: presenterIntance [
^ (CmCommandGroup named: 'Package menu') asSpecGroup
register: (self buildPackageGroupWith: presenterIntance);
yourself
]
{ #category : #commands }
DrTests class >> buildItemsListGroupWith: presenterInstance [
^ (CmCommandGroup named: 'List items menu') asSpecGroup
register: (DTBrowseSelectedItem forSpec context: presenterInstance);
yourself
]
{ #category : #commands }
DrTests class >> buildPackageGroupWith: presenterIntance [
^ (CmCommandGroup named: 'Package tools') asSpecGroup
description: 'Commands related to packages list.';
register: (DTPackagesSelectAllCommand forSpec context: presenterIntance);
beDisplayedAsGroup;
yourself
]
{ #category : #commands }
DrTests class >> buildResultGroupWith: presenterIntance [
| commandGroup pluginCommands |
commandGroup := (CmCommandGroup named: 'Results tools') asSpecGroup
description: 'Commands related to result.';
register:
(DTResultBrowseCommand forSpec context: presenterIntance)
beHiddenWhenCantBeRun;
yourself.
pluginCommands := presenterIntance currentPlugin
buildContextualMenuGroupWith: presenterIntance.
pluginCommands entries ifEmpty: [ ^ commandGroup ].
^ commandGroup
register: pluginCommands beDisplayedAsGroup;
yourself
]
{ #category : #specs }
DrTests class >> defaultSpec [
^ SpBoxLayout newVertical
add:
(SpBoxLayout newHorizontal
add: #pluginsDropList;
add: #switchButton
withConstraints: [ :constraints | constraints width: self buttonWidth * 2 ];
yourself)
withConstraints: [ :constraints |
constraints
expand: false;
height: self toolbarHeight ];
add:
(SpPanedLayout newHorizontal
add:
(SpPanedLayout newHorizontal
add:
(SpBoxLayout newVertical
add: #packagesList;
yourself);
add:
(SpBoxLayout newVertical
add: #itemsList;
yourself);
yourself);
add:
(SpBoxLayout newVertical
add: #resultViewsDropList
withConstraints: [ :constraints | constraints expand: false ];
add: #resultLabel
withConstraints: [ :constraints | constraints height: self labelHeight ];
add: #resultsList;
yourself);
yourself);
add: #startButton
withConstraints: [ :constraints | constraints width: self buttonWidth ];
yourself
]
{ #category : #'world menu' }
DrTests class >> menuCommandOn: aBuilder [
<worldMenu>
(aBuilder item: #'Dr Test (preview)')
parent: #Tools;
action: [ self open ];
order: 20;
keyText: 'o, u';
help: 'Let you run and debug SUnit tests.';
icon: self taskbarIcon.
aBuilder withSeparatorAfter
]
{ #category : #api }
DrTests class >> open [
^ self new
openWithSpec;
yourself
]
{ #category : #'tools registry' }
DrTests class >> registerToolsOn: registry [
"Add DrTests to registry to replace the old test runner."
registry register: self as: #testRunner
]
{ #category : #specs }
DrTests class >> reloadConfiguration: aDTPluginConfiguration withResults: aDTPluginResult andPlugin: aDTPlugin [
self open
updateStatus: 'Tests finished.';
currentPlugin: aDTPlugin;
testsConfiguration: aDTPluginConfiguration;
updateWithPluginResult: aDTPluginResult
]
{ #category : #actions }
DrTests >> browseSelectedItem [
"Because of DTBrowseSelectedItem>>#canBeExecuted, we know there is a single item in the selection.
Thus, we take the first one and browse it.
"
self selectedItems first drTestsBrowse
]
{ #category : #actions }
DrTests >> browseSelectedResult [
self resultSelected drTestsBrowse
]
{ #category : #private }
DrTests >> buildLabelString: nameOfItems numberOfItemsSelected: aInt [
^ String
streamContents: [ :s |
s
<< nameOfItems;
nextPut: $(;
<< aInt asString;
<< ' selected):' ]
]
{ #category : #accessing }
DrTests >> currentPlugin: anObject [
pluginResult := nil.
super currentPlugin: anObject.
]
{ #category : #private }
DrTests >> dateAndTimeString [
^ DateAndTime now asStringYMDHM
]
{ #category : #initialization }
DrTests >> initializeButtons [
super initializeButtons.
switchButton
label: 'mini Dr';
disable.
]
{ #category : #initialization }
DrTests >> initializeItemsListAndLabel [
itemsList := self newFilterableListPresenter..
itemsList
help: 'Select the classes to analyze. Cmd+A or Ctrl+A to select all classes.';
sortingBlock: #name ascending;
displayBlock: [ :item | item name ];
whenSelectionChangedDo: [ self whenItemsSelectionChanged: self selectedItems ];
beMultipleSelection;
contextMenu: [ (self rootCommandsGroup / 'List items menu') beRoot asMenuPresenter ].
packagesList
whenSelectionChangedDo: [ self whenPackagesSelectionChanged: self packagesSelected ]
]
{ #category : #initialization }
DrTests >> initializePackagesListAndLabel [
packagesList := self newFilterableListPresenter.
packagesList
help: 'Select the packages to analyze. Cmd+A or Ctrl+A to select all packages.';
sortingBlock: #name ascending;
displayBlock: [ :package | package name ];
beMultipleSelection;
contextMenu: [ (self rootCommandsGroup / 'Package menu') beRoot asMenuPresenter ]
]
{ #category : #initialization }
DrTests >> initializePluginsDropList [
pluginsDropList := self newDropList.
self pluginsDropList
help: 'Select the plugin used by Dr Tests UI.';
items: self plugins;
display: [ :pluginClass | pluginClass pluginName ];
iconBlock: [ :pluginClass | pluginClass pluginIcon ];
whenSelectedItemChangedDo: [ :pluginClass | self currentPlugin: pluginClass new ]
]
{ #category : #initialization }
DrTests >> initializePresenter [
super initializePresenter.
self resultViewsDropList
whenSelectedItemChangedDo: [ :resultTreeViewOrNil |
resultTreeViewOrNil
ifNotNil: [ resultsList
roots: (resultTreeViewOrNil resultTreeFor: pluginResult) subResults ] ].
self pluginsDropList selectIndex: 1
]
{ #category : #initialization }
DrTests >> initializeResultViewsDropList [
resultViewsDropList := self newDropList.
self resultViewsDropList
help: 'Select the different views for results';
display: [ :resultTreeView | resultTreeView name ]
]
{ #category : #initialization }
DrTests >> initializeResultsTreeAndLabel [
resultLabel := self newLabel label: 'Results:'.
resultsList := self newTreeTable.
resultsList
addColumn: (SpStringTableColumn evaluated: #drTestsName);
children: [ :node | node subResults ];
contextMenu: [ (self rootCommandsGroup / 'Results tools') beRoot asMenuPresenter ]
]
{ #category : #initialization }
DrTests >> initializeWidgets [
statusLabel := self newLabel.
self
initializePluginsDropList;
initializeButtons;
initializePackagesListAndLabel;
initializeItemsListAndLabel;
initializeResultsTreeAndLabel;
initializeResultViewsDropList
]
{ #category : #initialization }
DrTests >> initializeWindow: aWindowPresenter [
aWindowPresenter
title: self title;
initialExtent: 700 @ 500;
statusBar: statusLabel
]
{ #category : #'accessing - subwidgets' }
DrTests >> itemsList [
^ itemsList
]
{ #category : #private }
DrTests >> menuForSelectedResult: menu [
self resultSelected ifNil: [ ^ self ].
self resultSelected content drTestsBuildContextMenu: menu
]
{ #category : #widgets }
DrTests >> newFilterableListPresenter [
^ self instantiate: DTFilterableListPresenter
]
{ #category : #'accessing - subwidgets' }
DrTests >> packagesList [
^ packagesList
]
{ #category : #private }
DrTests >> packagesSelected [
^ self packagesList ifNil: [ #() ] ifNotNil: #selectedItems
]
{ #category : #'accessing - subwidgets' }
DrTests >> pluginResult [
^ pluginResult
]
{ #category : #'api - subwidgets configuration' }
DrTests >> pluginResult: anObject [
pluginResult := anObject
]
{ #category : #accessing }
DrTests >> plugins [
^ plugins ifNil: [ DrTestsPlugin availablePlugins ]
]
{ #category : #'accessing - subwidgets' }
DrTests >> pluginsDropList [
^ pluginsDropList
]
{ #category : #accessing }
DrTests >> resultSelected [
^ self resultsList selectedItem
]
{ #category : #api }
DrTests >> resultTree: aResultGroup [
aResultGroup
ifNotNil: [ self resultsList roots: aResultGroup subResults ]
]
{ #category : #'accessing - subwidgets' }
DrTests >> resultViewsDropList [
^ resultViewsDropList
]
{ #category : #'api - subwidgets configuration' }
DrTests >> resultViewsDropList: anObject [
resultViewsDropList:= anObject
]
{ #category : #'accessing - subwidgets' }
DrTests >> resultsList [
^ resultsList
]
{ #category : #api }
DrTests >> selectAllPackageList [
packagesList selectAll
]
{ #category : #accessing }
DrTests >> selectedItems [
^ self itemsList selectedItems
]
{ #category : #'accessing model' }
DrTests >> setModelBeforeInitialization: aDomainObject [
plugins := aDomainObject
]
{ #category : #'accessing - subwidgets' }
DrTests >> statusLabel [
^ statusLabel
]
{ #category : #'api - locking' }
DrTests >> subwidgetsToLock [
^ { self packagesList. self itemsList. self resultsList. self startButton }
]
{ #category : #actions }
DrTests >> switchUI [
super switchUI.
(MiniDrTests new
testsConfiguration: self testsConfiguration;
currentPlugin: self currentPlugin;
updateWithPluginResult:self pluginResult ;
yourself) openWithSpec
]
{ #category : #accessing }
DrTests >> testsConfiguration [
testsConfiguration := self currentPlugin buildConfigurationFrom: self.
^ testsConfiguration
]
{ #category : #accessing }
DrTests >> testsConfiguration: aDTTestsConfiguration [
self packagesList selectItems: aDTTestsConfiguration packagesSelected.
self itemsList selectItems: aDTTestsConfiguration items
]
{ #category : #accessing }
DrTests >> title [
^ 'Dr Tests - ' , currentPlugin pluginName
]
{ #category : #private }
DrTests >> updateItemsListLabel [
self itemsList
label:
(self
buildLabelString: self currentPlugin secondListLabel
numberOfItemsSelected: self selectedItems size)
]
{ #category : #private }
DrTests >> updatePackagesList [
packagesList unselectAll.
itemsList beEmpty.
packagesList items: currentPlugin packagesAvailableForAnalysis.
packagesList label: currentPlugin firstListLabel.
itemsList label: currentPlugin secondListLabel.
currentPlugin setSelectionModeOfPackageList: packagesList.
currentPlugin setSelectionModeOfItemsList: itemsList
]
{ #category : #private }
DrTests >> updatePackagesListLabel [
self packagesList
label:
(self
buildLabelString: self currentPlugin firstListLabel
numberOfItemsSelected: self packagesSelected size)
]
{ #category : #api }
DrTests >> updateResultLabel [
resultLabel
label: 'Results: ■';
color: pluginResult color
]
{ #category : #api }
DrTests >> updateResultViewsDropList [
| newPragmas |
newPragmas := self currentPlugin resultTreeViews.
(self resultViewsDropList listItems = newPragmas
and: [ newPragmas isNotEmpty ])
ifTrue: [ self resultViewsDropList
selectedIndex: self resultViewsDropList selectedIndex. "Trigger action attached to selection change."
^ self ].
self resultViewsDropList selectedItem
ifNotNil: [ self resultViewsDropList resetSelection ].
self resultViewsDropList items: newPragmas.
newPragmas isNotEmpty
ifTrue: [ self resultViewsDropList selectIndex: 1 ]
]
{ #category : #api }
DrTests >> updateStatus: aString [
self statusLabel
label: ('{1}: {2}' format: { self dateAndTimeString . aString }).
]
{ #category : #updating }
DrTests >> updateSwitchButton: itemsSelected [
currentPlugin allowMiniDrTests
ifTrue: [ switchButton enabled: itemsSelected isNotEmpty ]
ifFalse: switchButton disable
]
{ #category : #updating }
DrTests >> updateUI [
self
startButtonLabel: self currentPlugin startButtonLabel;
startButtonHelp: self currentPlugin startButtonHelp;
updateStatus: self currentPlugin pluginName , ' plugin is ready to work!' translated.
self withWindowDo: [ :window | window title: self title ].
self packagesList resetFilter.
self updatePackagesList.
self resultTree: DTTreeNode empty.
self packagesList resetFilter.
self itemsList resetFilter.
self updateResultViewsDropList
]
{ #category : #api }
DrTests >> updateWithPluginResult: aPluginResult [
aPluginResult ifNotNil: [ self updateWithResults: aPluginResult ]
]
{ #category : #api }
DrTests >> updateWithResults: results [
pluginResult := results.
self resultTree: pluginResult buildTreeForUI.
self updateResultViewsDropList.
self updateResultLabel.
resultsList
contextMenu: [ (self rootCommandsGroup / 'Results tools') beRoot asMenuPresenter ]
]
{ #category : #private }
DrTests >> whenItemsSelectionChanged: itemsSelected [
self updateItemsListLabel.
self updateSwitchButton: itemsSelected
]
{ #category : #private }
DrTests >> whenPackagesSelectionChanged: packagesSelected [
itemsList
items: (currentPlugin itemsToBeAnalysedFor: packagesSelected);
selectAll.
self updatePackagesListLabel
]