-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathMinitestUI.ns
837 lines (822 loc) · 26.4 KB
/
MinitestUI.ns
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
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
Newspeak3
'Root'
class MinitestUI usingPlatform: p minitest: mt ide: devEnv
(* :exemplar: ide minitestUI *)
= (
(* Hopscotch UI for unit testing using Minitest. *)
|
private List = p collections List.
private Map = p collections Map.
private Set = p collections Set.
private Holder = p hopscotch ducts Holder.
private Promise = p actors Promise.
private Color = p graphics Color.
private Gradient = p hopscotch Gradient.
private Presenter = p hopscotch Presenter.
private Subject = p hopscotch Subject.
private TestCatalog = mt TestCatalog.
private AssortedMethodsPresenter = devEnv browsing AssortedMethodsPresenter.
private AssortedMethodsSubject = devEnv browsing AssortedMethodsSubject.
private MethodSubject = devEnv browsing MethodSubject.
private MethodPresenter = devEnv browsing MethodPresenter.
private MethodModel = devEnv browsing MethodModel.
private ProgrammingPresenter = devEnv browsing ProgrammingPresenter.
private ProgrammingSubject = devEnv browsing ProgrammingSubject.
private Utilities = devEnv browsing Utilities.
private ide = devEnv.
private platform = p.
private minitest = mt.
|
) (
class TestResultListPresenter onSubject: s = AssortedMethodsPresenter onSubject: s (
(* A presenter for a list of TestResults, such as a list of successes or failures of a test run. *)
) (
public isKindOfTestResultListPresenter ^ <Boolean> = (
^true
)
isMyKind: f <Fragment> ^ <Boolean> = (
^f isKindOfTestResultListPresenter
)
runAll = (
sendUp respondToRunAll: content presenters
)
contentPresenters ^ <Collection[TestResultPresenter]> = (
| sortedTestResults |
sortedTestResults:: subject resultSubjects sort:
[:a :b | Utilities lexicallyLessOrEqual: a model testCase selector than: b model testCase selector].
^sortedTestResults collect:
[:each <TestResultSubject> | each presenter showIndicatorBar: false]
)
elementDescription ^ <String> = (
^'test methods'
)
listDescription ^ <String> = (
^'test result list methods'
)
) : (
)
class TestResultListSubject onModel: list <List[TestResult]> = ProgrammingSubject onModel: list (
(* The subject of a list of test results, such as a list of successes or failures of a test run. The model is a list of TestResult instances.
The subject is stateful. It maintains a cached list of TestResultSubjects for its results. The requirement for this state is driven by the desire to display test results with the corrresponding test method, and the test method presented should have a live exemplar and a stateful evaluator associated with it.
The results themselves may change for various reasons - test methods may be added, removed or modified, and the test results themselves may change over time as test pass or fail as the codebase is modified. Modifying the model, that is result list itself, is the responsibility of the TestOutcomeSubject that manages the various test result lists.
Clients access the cache via the method resultSubjects, which takes care maintain the cache held in the resultSubjects_slot. It derives the result subjects from the results, and this list is updated as the underlying model changes.
*)
| resultSubjects_slot <List[TestResultSubject]> |
) (
public createPresenter = (
^TestResultListPresenter onSubject: self
)
public isEmpty ^ <Boolean> = (
^model isEmpty
)
public isKindOfTestResultListSubject ^ <Booelan> = (
^true
)
isMyKind: s <Subject> ^ <Boolean> = (
^s isKindOfTestResultListSubject
)
public results ^ <List[TestResult]> = (
^model
)
public resultSubjects ^ <List[TestResultSubject]> = (
(* Answer a collection of subjects on individual elements of the group which is our subject. *)
resultSubjects_slot isNil ifTrue: [
(* First access - initialize the cache and return it *)
resultSubjects_slot:: results collect: [:each | TestResultSubject onModel: each].
^resultSubjects_slot
].
(* Cache already exists. Make sure it is up to date. *)
updateResults.
^resultSubjects_slot
)
updateResults = (
(* Ensure that the the cached result subjects are in sync with the model. This method must only be called after the cache is first populated, and it should be called on every subsequent attempt to access the result subjects cache. *)
|
(* Cached results *)
subjectResults <List[TestResult]> = resultSubjects_slot collect: [:e <Subject> | e model].
(* A list of subjects that are obsolete - they are no longer part of the model *)
obsoleteSubjects <List[TestResultSubject]> = List new.
|
(* Gather obsolete results *)
resultSubjects_slot do: [:s <TestResultSubject> |
(results includes: s model) ifFalse: [obsoleteSubjects add: s].
].
(* Clean out obsolete entries from cache *)
obsoleteSubjects do: [:s <TestResultSubject> | resultSubjects_slot remove: s].
(* Add missing model entries to cache. We keep subjectResults as a separate list so we don't traverse the cache while mutating it. *)
results do: [:m <TestResult> |
(subjectResults includes: m) ifFalse: [
resultSubjects_slot add: (TestResultSubject onModel: m)
].
].
)
) : (
)
class TestResultPresenter onSubject: s = ProgrammingPresenter onSubject: s (
(* Shows a single TestResult as an expandable selector of the method defining the test. If the result is a failure, also shows the description of the failure. *)
|
public showIndicatorBar <Boolean> ::= true.
methodPresenterSlot <MethodPresenter>
|) (
ancestorTestingOutcomePresenter = (
| ancestor ::= parent. |
[nil = ancestor] whileFalse:
[ancestor isKindOfTestingOutcomePresenter ifTrue:
[^ancestor].
ancestor:: ancestor parent].
^nil
)
public collapse = (
methodPresenter collapse
)
definition ^ <Fragment> = (
^showIndicatorBar
ifTrue: [row: {indicatorBar. elastic:: resultColumn}]
ifFalse: [resultColumn]
)
exceptionFragment ^ <Fragment> = (
| link |
link::
(link: subject exception printString
action: [ancestorTestingOutcomePresenter runWithNoExceptionHandling: subject testCase])
color: footnoteColor.
^row: {
blank: 12.
elastic: link.
}
)
public expand = (
methodPresenter expand
)
failureFragment ^ <Fragment> = (
^row: {
blank: 12.
(link: subject failureDescription
action: [ancestorTestingOutcomePresenter runToDebugFailure: subject testCase])
color: footnoteColor
}
)
footnoteColor ^ <Color> = (
^Color gray: 0.7
)
indicatorBar = (
^(row: {blank: 5} ) color: statusColor.
)
public isKindOfTestResultPresenter ^ <Boolean> = (
^true
)
isMyKind: f <Fragment> ^ <Boolean> = (
^f isKindOfTestResultPresenter
)
methodPresenter ^ <ExpandableMethodPresenter> = (
methodPresenterSlot isNil ifTrue: [
methodPresenterSlot:: subject methodSubject createPresenter showClassName: true
].
^methodPresenterSlot
)
resultColumn ^ <Fragment> = (
^column: {
methodPresenter.
subject isFailure ifTrue: [failureFragment] ifFalse: [nothing].
subject hasException ifTrue: [exceptionFragment] ifFalse: [nothing].
(* subject hasNoData ifTrue: [noDataFragment] *)
}
)
statusColor ^ <Color> = (
(* subject passed ifTrue: [^Color green].
subject failed ifTrue: [^Color red].
subject error ifTrue: [^Color black]. *)
^Color gray.
)
public tag ^ <String> = (
^methodPresenter tag
)
updateVisualsFromSameKind: oldPresenter <Self> ^ <Alien[Element]> = (
showIndicatorBar:: oldPresenter showIndicatorBar.
substanceSlot:: nil.
ensureSubstance.
^super updateVisualsFromSameKind: oldPresenter
)
) : (
)
class TestResultSubject onModel: m <TestResult> = Subject onModel: m (
(* The subject for presenting a single TestResult. *)
| methodSubject_slot <MethodSubject> |
) (
classDeclarationMirror = (
^testCase environment classDeclarationMirror
)
public exception = (
(* If the model is a test error, return the exception associated with the result. Otherwise return nil. *)
^model isError
ifTrue: [model exception]
ifFalse: [nil]
)
public failureDescription ^<String> = (
(* If the model is a failure, return the description of the failure. Otherwise return an empty string. *)
^isFailure
ifTrue: [model description]
ifFalse: ['']
)
public hasException ^<Boolean> = (
(* True if the test result has an exception associated with it, or in other words, the result is a test error. *)
^model isError
)
public hash = (
^selector hash * 37 + className hash
)
public isFailure = (
^model isFailure
)
public isKindOfTestResultSubject ^ <Boolean> = (
^true
)
isMyKind: s <Subject> ^ <Boolean> = (
^s isKindOfTestResultSubject
)
public selector ^ <Symbol> = (
^testCase selector
)
public testResult ^ <TestResult> = (
^model
)
public testCase = (
^testResult testCase
)
public createPresenter ^ <TestResultPresenter> = (
^TestResultPresenter onSubject: self
)
public = x <Object> ^ <Boolean> = (
x isKindOfTestResultSubject ifFalse: [^false].
^selector = x selector and: [className = x className]
)
public className = (
(* really should use qualified name *)
#BOGUS.
^classDeclarationMirror name
)
public methodSubject = (
methodSubject_slot isNil ifTrue: [
methodSubject_slot:: TestMethodSubject onModel: (testCaseToMethod: testCase)
].
^methodSubject_slot
)
) : (
)
class TestingInProgressPresenter onSubject: subject = Presenter onSubject: subject (
(* Presents a Tester in the process of running tests. *)
|
progress <Holder> = Holder with: 0.0.
currentSelector
errorCountHolder
failureCountHolder
|) (
definition = (
schedule: [startTests].
errorCountHolder:: holder: [nothing].
failureCountHolder:: holder: [nothing].
currentSelector:: label: 'no tests yet'.
^column: {
progressBar: progress.
row: {label: 'Running '. currentSelector . label: '...'}.
errorCountHolder.
failureCountHolder.
}
)
public isKindOfTestingInProgressPresenter ^ <Boolean> = (
^true
)
isMyKind: f <Fragment> ^ <Boolean> = (
^f isKindOfTestingInProgressPresenter
)
public isTransient = (
(* Should not be recorded in navigation history. *)
^true
)
pumpTests = (
tester atEnd ifTrue: [
tester haveAllTestsSucceeded ifTrue: [tester cleanUp].
enterSubject:: TestingOutcomeSubject tester: tester configClass: subject configClass.
^self
].
currentSelector text: tester peekSelector.
(failureCountHolder hasVisual and: [tester failures size > 0]) ifTrue:
[failureCountHolder content: (row: {label: 'Failures: ', tester failures size asString})].
(errorCountHolder hasVisual and: [tester errors size > 0]) ifTrue:
[errorCountHolder content: (row: {label: 'Errors: ', tester errors size asString})].
progress value: tester completedRatio.
schedule:
[Promise when: tester stepAsync fulfilled: [pumpTests]].
)
startTests = (
tester prepare.
pumpTests.
)
tester ^ <Tester> = (
^subject tester
)
) : (
)
public class TestingInProgressSubject tester: tester <Tester> configClass: configClass = Subject onModel: tester (
(* Represents a Tester instance, in the process of running tests. *)
|
public configClass = configClass.
|) (
public isKindOfTestingInProgressSubject ^ <Boolean> = (
^true
)
isMyKind: s <Subject> ^ <Boolean> = (
^s isKindOfTestingInProgressSubject
)
public tester ^ <Tester> = (
^model
)
public title ^ <String> = (
^'Running Tests'
)
public refreshmentSubject ^ <TestingInProgressSubject> = (
^self class tester: model configClass: configClass.
)
public createPresenter ^ <TestingInProgressPresenter> = (
^TestingInProgressPresenter onSubject: self
)
) : (
public onConfiguration: configClass <Class> platform: platform minitest: minitest = (
| config modules tester |
config:: configClass packageTestsUsing: ide namespacing manifest.
modules:: config testModulesUsingPlatform: platform minitest: minitest.
tester:: minitest Tester testModules: modules.
^self tester: tester configClass: configClass.
)
)
class TestingOutcomePresenter onSubject: s <TestingOutcomeSubject> = ProgrammingPresenter onSubject: s (
(* Shows an outcome of running a suite of tests, as a page with separate sections for errors, failures and successes. *)
) (
didAllTestsPass = (
^didNoTestsFail (* not tracking incomplete for now, so no difference from didNoTestsFail *)
)
didNoTestsFail ^ <Boolean> = (
^subject failures isEmpty and: [subject errors isEmpty]
)
errorsSectionColor = (
^Gradient from: (Color h: 0 s: 0.15 v: 1) to: (Color h: 0 s: 0.15 v: 0.9)
)
failureHeadingColor = (
^Gradient from: (Color h: 0 s: 0.5 v: 0.8) to: (Color h: 0 s: 0.5 v: 0.6)
)
failuresSectionColor = (
^Gradient from: (Color h: 50 s: 0.3 v: 1) to: (Color h: 50 s: 0.3 v: 0.9)
)
headingBlock: fragment color: aColor = (
^(padded: fragment with: {10. 5. 5. 5}) color: aColor
)
headingDefinition ^ <Presenter> = (
^(majorHeadingBlock: headingContentsDefinition)
color: (
didNoTestsFail
ifFalse: [failureHeadingColor]
ifTrue:
[successHeadingColor])
)
public isKindOfTestingOutcomePresenter ^ <Boolean> = (
^true
)
isMyKind: f <Fragment> ^ <Boolean> = (
^f isKindOfTestingOutcomePresenter
)
public noticeAbandonment = (
subject tester haveAllTestsSucceeded ifFalse: [subject tester cleanUp].
super noticeAbandonment.
)
respondToRunAll: testCases = (
(* Run the set of test cases given by testCases. The UI uses this to re-run just the failures, or errors or successes. However, tests have shared state, which one has to tear down and re-initialize.
Other sections that hold test results should be pointing at different shared state so that they can be re-examined It doesn't look like things are set up to support this. *)
halt.
)
successHeadingColor = (
^Gradient from: (Color h: 120 s: 0.5 v: 0.7) to: (Color h: 120 s: 0.5 v: 0.5)
)
successesSectionColor = (
^Gradient from: (Color h: 90 s: 0.3 v: 1) to: (Color h: 90 s: 0.3 v: 0.9)
)
sectionHeader: label <String> with: testCases <Collection[TestCase]> status: aSymbol <Symbol> color: aColor <Color | Gradient> ^ <Fragment> = (
^headingBlock: (row: {
label: (label, ' (', testCases size printString, ')') (*asText allBold *).
largeBlank.
(* (link: 'run all' action: [testedMethodsPresenter runAll]) tinyFont. *)
filler.
}) color: aColor.
)
public runWithNoExceptionHandling: testCase = (
| thread <ThreadMirror> |
thread:: platform mirrors ActivationMirror invokeSuspended:
[subject tester runWithNoExceptionHandling: testCase].
thread resume.
enterSubject:: ide debugging ThreadSubject onModel: thread.
)
testOutcomesMenu = (
^menuWithLabelsAndActions: {
{'Inspect Presenter'. [respondToInspectPresenter]}
}
)
disabledSectionColor = (
^Gradient from: (Color h: 180 s: 0.3 v: 1) to: (Color h: 180 s: 0.3 v: 0.9)
)
untestedSectionColor = (
^Gradient from: (Color h: 150 s: 0.3 v: 1) to: (Color h: 150 s: 0.3 v: 0.9)
)
public run: tc <TestCase> = (
subject tester run: tc
)
respondToRunAgain = (
| newSubject |
subject tester cleanUpResults.
subject tester haveAllTestsSucceeded ifFalse: [subject tester cleanUp].
newSubject:: TestingInProgressSubject tester: subject model configClass: subject configClass
(*onConfiguration: subject configClass
platform: platform
minitest: minitest*).
enterSubject: newSubject.
)
public runToDebugFailure: testCase = (
| thread <ThreadMirror> |
thread:: platform mirrors ActivationMirror invokeSuspended:
[subject tester runToDebugFailure: testCase].
[thread suspendedActivation method name = testCase selector] whileFalse: [
thread:: thread suspendedActivation stepOut.
].
enterSubject:: ide debugging ThreadSubject onModel: thread.
)
headingContentsDefinition ^ <Presenter> = (
| statusMessage |
statusMessage::
didAllTestsPass
ifTrue: ['Passed']
ifFalse:
[didNoTestsFail
ifTrue: ['Incomplete test results']
ifFalse: ['Failed ']].
^row: {
(link: subject configurationName (* asText allBold *)
action: [browseClass: subject configClass]) color: Color white.
smallBlank.
(label: statusMessage (* asText allBold *)) color: Color white.
filler.
button: 'Run Again' action: [respondToRunAgain].
(* smallBlank.
button: 'Forget' action: [respondToForget] *)
mediumBlank.
helpButton.
mediumBlank.
dropDownMenu: [testOutcomesMenu]
}.
)
definition ^ <Fragment> = (
^column: {
helpSection.
headingDefinition.
blank: 2.
errors.
blank: 1.
failures.
blank: 1.
disabled.
blank: 1.
inactive.
blank: 1.
successes.
}
)
section: label <String> with: testResults <TestResultListSubject> status: aSymbol <Symbol> color: aColor <Color | Gradient> ^ <Fragment> = (
| testedMethodsPresenter |
testedMethodsPresenter:: testResults presenter.
^column: {
sectionHeader: label with: testResults results status: aSymbol color: aColor.
blank: 3.
testedMethodsPresenter.
}
)
failures ^ <Fragment> = (
^section: 'Failures'
with: subject failureSubjects
status: #failure
color: failuresSectionColor
)
errors ^ <Fragment> = (
^section: 'Errors'
with: subject errorSubjects
status: #error
color: errorsSectionColor
)
inactive ^ <Fragment> = (
^column: {
sectionHeader: 'Untested' with: subject inactiveSubjects elements status: #untested color: untestedSectionColor.
blank: 3.
subject inactiveSubjects presenter.
}
)
disabled ^ <Fragment> = (
^column: {
sectionHeader: 'Disabled' with: subject disabledSubjects elements status: #disabled color: disabledSectionColor.
blank: 3.
subject disabledSubjects presenter.
}
)
successDetailsLink = (
^ subject successSubjects results isEmpty ifFalse:
[(link: 'Show details...'
action: [updateGUI: [subject showSuccesses: true]]) (*tinyFont*)]
ifTrue: [nothing]
)
successes ^ <Fragment> = (
^subject showSuccesses ifTrue: [
section: 'Successes'
with: subject successSubjects
status: #success
color: successesSectionColor
] ifFalse: [
column: {
sectionHeader: 'Successes'
with: subject successSubjects results
status: #success
color: successesSectionColor.
row: {
blank: 10.
successDetailsLink
}
}
]
)
helpText ^ <Fragment> = (
| mapping = Map new. |
mapping
at: #runAgainButton put: (button: 'Run Again' action: [respondToRunAgain]);
at: #hopscotchHelpButton put: helpButton;
at: #testOutcomesMenuButton put: (dropDownMenu: [testOutcomesMenu]);
at: #successDetails put: successDetailsLink.
^ampleforth: 'This is a test outcome presenter. It shows the results of running a test suite in a specific test configuration.
If the banner at the top of the presenter (directly below this message) is green, all active tests have passed; if it is red, there have been errors; yellow means there have been test failures but no errors.
<br>
The presentation is subdivided into sections that show errors, failures and successes, as well as listing any tests that have not been run, or have been disabled. The <i>Successes</i> section is collapsed by default, as no one cares about your successes - only your errors and failures. Below the <i>Successes</i> section, the link <div class = "successDetails"></div> allows you to bask in the glory of your successes if you need to.
<br>
The methods within sections themselves provide additional affordances to disable/enable or run individual tests etc. See their help sections for further information.
<br>
<ul>
<li> <div class="runAgainButton"> </div> Re-runs the enabled methods in the test suite.</li>
<li> <div class="hopscotchHelpButton"> </div> Shows this help message.</li>
<li> <div class="testOutcomesMenuButton"> </div> Opens a menu of additional operations, such as inspecting this presenter.</li>
</ul>
' mapping: mapping
)
) : (
)
public class TestingOutcomeSubject tester: t <Tester> configClass: c = ProgrammingSubject onModel: t (
|
public configClass = c.
public showSuccesses <Boolean> ::= false.
disabledSubjects_slot <TestResultListSubject>
errorSubjects_slot <TestResultListSubject>
failureSubjects_slot <TestResultListSubject>
inactiveSubjects_slot <AssortedMethodsSubject>
successSubjects_slot <TestResultListSubject>
|) (
public configurationName = (
^configClass name
)
public createPresenter = (
^TestingOutcomePresenter onSubject: self
)
public isKindOfTestingOutcomeSubject ^ <Boolean> = (
^true
)
isMyKind: s <Subject> ^ <Boolean> = (
^s isKindOfTestingOutcomeSubject
)
public refreshmentSubject = (
^self class tester: tester configClass: configClass
)
public tester ^ <Tester> = (
^model
)
public title = (
^'Test Results for ', configurationName
)
public successes ^ <List[TestSuccess]> = (
^tester successes
)
public failures ^ <List[TestFailure]> = (
^tester failures
)
public errors ^ <List[TestError]> = (
^tester errors
)
public activate: t <TestCase | TestResult> = (
t isKindOfTestResult ifTrue: [
] ifFalse: [
inactive remove: t ifAbsent: [shouldNotHappen]
]
)
public enable: tc <TestCase> = (
tester enable: tc
)
public isEnabled: tc ^ <Boolean> = (
^tester isEnabled: tc
)
public disable: tc <TestCase | TestResult> = (
tester disable: tc
)
public disabled ^ <Collection[TestCase]> = (
^tester disabled
)
public inactive ^ <Collection[TestCase]> = (
^tester inactive
)
public errorSubjects ^ <TestResultListSubject> = (
errorSubjects_slot isNil ifTrue: [
errorSubjects_slot:: TestResultListSubject onModel: tester errors.
^errorSubjects_slot
].
updateErrors.
^errorSubjects_slot
)
public successSubjects ^ <TestResultListSubject> = (
successSubjects_slot isNil ifTrue: [
successSubjects_slot:: TestResultListSubject onModel: tester successes.
^successSubjects_slot
].
updateSuccesses.
^successSubjects_slot
)
public failureSubjects ^ <TestResultListSubject> = (
failureSubjects_slot isNil ifTrue: [
failureSubjects_slot:: TestResultListSubject onModel: tester failures.
^failureSubjects_slot
].
updateFailures.
^failureSubjects_slot
)
updateErrors = (
^Utilities updateSubjects: [errorSubjects_slot resultSubjects] fromModel: [errors] subjectFactory: TestResultSubject
)
updateFailures = (
^Utilities updateSubjects: [failureSubjects_slot resultSubjects] fromModel: [failures] subjectFactory: TestResultSubject
)
updateSuccesses = (
^Utilities updateSubjects: [successSubjects_slot resultSubjects] fromModel: [successes] subjectFactory: TestResultSubject
)
public disabledSubjects ^ <TestResultListSubject> = (
disabledSubjects_slot isNil ifTrue: [
disabledSubjects_slot:: AssortedMethodsSubject onModel: (disabled collect: [:testCase <TestCase> |
TestMethodSubject onModel: (testCaseToMethod: testCase)
]).
^disabledSubjects_slot
].
updateDisabled.
^disabledSubjects_slot
)
public inactiveSubjects ^ <AssortedMethodsSubject> = (
inactiveSubjects_slot isNil ifTrue: [
inactiveSubjects_slot:: AssortedMethodsSubject onModel: (inactive collect: [:testCase <TestCase> |
TestMethodSubject onModel: (testCaseToMethod: testCase)
]).
^inactiveSubjects_slot
].
updateInactive.
^inactiveSubjects_slot
)
updateDisabled = (
^Utilities
updateSubjects: [disabledSubjects_slot elements]
fromModel: [disabled collect: [:testCase | testCaseToMethod: testCase]]
subjectFactory: TestMethodSubject
)
updateInactive = (
^Utilities
updateSubjects: [inactiveSubjects_slot elements]
fromModel: [inactive collect: [:testCase | testCaseToMethod: testCase]]
subjectFactory: TestMethodSubject
)
) : (
public onConfiguration: configClass <Class> platform: platform minitest: minitest = (
| config modules tester |
config:: configClass packageTestsUsing: ide namespacing manifest.
modules:: config testModulesUsingPlatform: platform minitest: minitest.
tester:: minitest Tester testModules: modules.
tester prepare.
^self tester: tester configClass: configClass.
)
)
class TestMethodPresenter onSubject: s <MethodSubject> = MethodPresenter onSubject: s(
) (
public isKindOfTestMethodPresenter ^ <Boolean> = (
^true
)
isMyKind: other ^ <Boolean> = (
^other isKindOfTestMethodPresenter
)
ancestorTestingOutcomePresenter = (
| ancestor ::= parent. |
[nil = ancestor] whileFalse:
[ancestor isKindOfTestingOutcomePresenter ifTrue:
[^ancestor].
ancestor:: ancestor parent].
^nil
)
methodMenuFor: methodName <String> = (
|
superMenu = super methodMenuFor: methodName.
menuExtensions = isEnabled ifFalse: [
{
{'enable and run'. [respondToEnableAndRun]}.
{'enable'. [respondToEnable]}
}
] ifTrue: [{ {'run'. [respondToRun] }. {'disable'. [respondToDisable]}}].
|
^superMenu, menuExtensions
)
outcomeSubject ^ <TestingOutcomeSubject> = (
^ancestorTestingOutcomePresenter subject
)
isEnabled ^ <Boolean> = (
^outcomeSubject isEnabled: test
)
respondToEnable = (
updateGUI: [outcomeSubject enable: test]
)
respondToDisable = (
updateGUI: [outcomeSubject disable: test]
)
ancestorResultPresenter = (
| ancestor ::= parent. |
[nil = ancestor or: [ancestor isKindOfHopscotchWindow]] whileFalse:
[ancestor isKindOfTestResultPresenter ifTrue:
[^ancestor].
ancestor:: ancestor parent].
^nil
)
test ^ <TestCase | TestResult> = (
(* Return the testCase or testResult I represent.*)
| resultPresenter <TestResultPresenter> = ancestorResultPresenter. |
(* If I represent an failure, error or success, I am embedded
in a TestResultPresenter.*)
resultPresenter isNil ifFalse: [
(* Return test result *)
^resultPresenter subject testResult
].
(* Otherwise I am disabled or untested *)
^outcomeSubject disabled detect: [:tc | tc selector = subject name] ifNone: [
outcomeSubject inactive detect: [:tc | tc selector = subject name] ifNone: []
].
)
respondToRun = (
|
t <TestCase | TestResult> = test.
tc <TestCase> = t isKindOfTestResult ifTrue: [t testCase] ifFalse: [t].
|
updateGUI: [
outcomeSubject activate: t.
ancestorTestingOutcomePresenter run: tc
]
)
respondToEnableAndRun = (
|
t <TestCase | TestResult> = test.
tc <TestCase> = t isKindOfTestResult ifTrue: [t testCase] ifFalse: [t].
|
updateGUI: [
outcomeSubject enable: t.
outcomeSubject activate: t.
ancestorTestingOutcomePresenter run: tc
]
)
menuHelp ^ <String> = (
|
menuExtensions <String> = isEnabled
ifFalse: [
', enabling and running the test, or just enabling it without running it'
] ifTrue: [
', running this test or disabling it'
].
|
^super menuHelp, menuExtensions
)
) : (
)
class TestMethodSubject onModel: m <MethodModel> = MethodSubject onMethodModel: m (
) (
public isKindOfTestMethodSubject ^ <Boolean> = (
^true
)
isMyKind: other <Subject> = (
^other isKindOfTestMethodSubject
)
public createPresenter ^ <TestMethodPresenter> = (
^TestMethodPresenter onSubject: self
)
) : (
)
testCaseToMethod: testCase <TestCase> ^ <MethodModel> = (
^MethodModel method: (testCase environment classDeclarationMirror instanceSide methods findMirrorNamed: testCase selector) exemplar: nil
)
) : (
)