Skip to content

Commit 4787a5b

Browse files
authored
Merge pull request #72 from DurieuxPol/feat/testFilter
Implemented test filters
2 parents 70148a1 + 5842866 commit 4787a5b

10 files changed

+204
-3
lines changed

src/MuTalk-Model/MTAnalysis.class.st

+25-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ Class {
1313
'mutantResults',
1414
'stopOnErrorOrFail',
1515
'testSelectionStrategy',
16-
'mutantSelectionStrategy'
16+
'mutantSelectionStrategy',
17+
'testFilter'
1718
],
1819
#category : 'MuTalk-Model',
1920
#package : 'MuTalk-Model'
@@ -485,6 +486,12 @@ MTAnalysis >> defaultOperators [
485486
^ MTMutantOperator contents
486487
]
487488

489+
{ #category : 'accessing - defaults' }
490+
MTAnalysis >> defaultTestFilter [
491+
492+
^ MTFreeTestFilter new
493+
]
494+
488495
{ #category : 'accessing - defaults' }
489496
MTAnalysis >> defaultTestSelectionStrategy [
490497

@@ -525,14 +532,17 @@ MTAnalysis >> generateMutations [
525532
{ #category : 'running' }
526533
MTAnalysis >> generateResults [
527534

535+
| tests |
528536
mutantResults := OrderedCollection new.
537+
tests := testFilter filterTests: testCases.
538+
529539
mutations do: [ :aMutation |
530540
(budget exceedsBudgetOn: mutantResults fromTotalMutations: mutations)
531541
ifTrue: [ ^ mutantResults ].
532542
logger logStartEvaluating: aMutation.
533543
mutantResults add: ((MTMutantEvaluation
534544
for: aMutation
535-
using: testCases
545+
using: tests
536546
following: testSelectionStrategy
537547
andConsidering: self coverageAnalysisResult)
538548
valueStoppingOnError: stopOnErrorOrFail) ].
@@ -558,6 +568,7 @@ MTAnalysis >> initialize [
558568
elapsedTime := 0.
559569
logger := self defaultLogger.
560570
budget := self defaultBudget.
571+
testFilter := self defaultTestFilter.
561572
stopOnErrorOrFail := true
562573
]
563574

@@ -695,6 +706,18 @@ MTAnalysis >> testClasses: aClassCollection [
695706
testCases := self testCasesFrom: aClassCollection
696707
]
697708

709+
{ #category : 'accessing' }
710+
MTAnalysis >> testFilter [
711+
712+
^ testFilter
713+
]
714+
715+
{ #category : 'accessing' }
716+
MTAnalysis >> testFilter: anObject [
717+
718+
testFilter := anObject
719+
]
720+
698721
{ #category : 'accessing' }
699722
MTAnalysis >> testSelectionStrategy [
700723

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
Class {
2+
#name : 'MTFreeTestFilter',
3+
#superclass : 'MTTestFilter',
4+
#category : 'MuTalk-Model-Test filters',
5+
#package : 'MuTalk-Model',
6+
#tag : 'Test filters'
7+
}
8+
9+
{ #category : 'enumerating' }
10+
MTFreeTestFilter >> filterTests: aTestCaseCollection [
11+
12+
^ aTestCaseCollection
13+
]

src/MuTalk-Model/MTGeneralResult.class.st

+6
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,12 @@ MTGeneralResult >> numberOfTerminatedMutants [
105105
^ self terminatedMutants size
106106
]
107107

108+
{ #category : 'accessing' }
109+
MTGeneralResult >> particularResults [
110+
111+
^ particularResults
112+
]
113+
108114
{ #category : 'printing' }
109115
MTGeneralResult >> printDetailedInfoOn: aStream [
110116

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
Class {
2+
#name : 'MTTestFilter',
3+
#superclass : 'Object',
4+
#instVars : [
5+
'condition'
6+
],
7+
#category : 'MuTalk-Model-Test filters',
8+
#package : 'MuTalk-Model',
9+
#tag : 'Test filters'
10+
}
11+
12+
{ #category : 'instance creation' }
13+
MTTestFilter class >> for: aCondition [
14+
15+
^ self new
16+
condition: aCondition;
17+
yourself
18+
]
19+
20+
{ #category : 'accessing' }
21+
MTTestFilter >> condition [
22+
23+
^ condition
24+
]
25+
26+
{ #category : 'accessing' }
27+
MTTestFilter >> condition: aCondition [
28+
29+
condition := aCondition
30+
]
31+
32+
{ #category : 'enumerating' }
33+
MTTestFilter >> filterTests: aTestCaseCollection [
34+
35+
^ self subclassResponsibility
36+
]
+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
Class {
2+
#name : 'MTTimeTestFilter',
3+
#superclass : 'MTTestFilter',
4+
#category : 'MuTalk-Model-Test filters',
5+
#package : 'MuTalk-Model',
6+
#tag : 'Test filters'
7+
}
8+
9+
{ #category : 'enumerating' }
10+
MTTimeTestFilter >> filterTests: aTestCaseCollection [
11+
12+
^ aTestCaseCollection select: [ :testCaseReference |
13+
testCaseReference lastTimeToRun <= condition ]
14+
]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
Class {
2+
#name : 'MTAuxiliarClassForTimeTestFilter',
3+
#superclass : 'Object',
4+
#category : 'MuTalk-TestResources',
5+
#package : 'MuTalk-TestResources'
6+
}
7+
8+
{ #category : 'accessing' }
9+
MTAuxiliarClassForTimeTestFilter >> simpleMethod [
10+
11+
^ 1 + 1
12+
]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
Class {
2+
#name : 'MTAuxiliarClassForTimeTestFilterTest',
3+
#superclass : 'TestCase',
4+
#category : 'MuTalk-TestResources',
5+
#package : 'MuTalk-TestResources'
6+
}
7+
8+
{ #category : 'tests' }
9+
MTAuxiliarClassForTimeTestFilterTest >> test10Milliseconds [
10+
11+
10 milliSeconds wait
12+
]
13+
14+
{ #category : 'tests' }
15+
MTAuxiliarClassForTimeTestFilterTest >> test1Second [
16+
17+
1 second wait
18+
]

src/MuTalk-Tests/MTTestCasesSelectionStrategyTest.class.st

+2-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ MTTestCasesSelectionStrategyTest >> allTestsFromPackage [
1717
with: MTAuxiliarClassForMTAnalysisTest
1818
with: MTAuxiliarTestClassForMTBudget
1919
with:
20-
MTAuxiliarTestClassForContinuingTestsExecutionAfterFirstFail)
20+
MTAuxiliarTestClassForContinuingTestsExecutionAfterFirstFail
21+
with: MTAuxiliarClassForTimeTestFilterTest)
2122
inject: OrderedCollection new
2223
into: [ :tests :testClass |
2324
tests addAll: testClass suite tests.
+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
Class {
2+
#name : 'MTTestFilterTest',
3+
#superclass : 'TestCase',
4+
#instVars : [
5+
'analysis'
6+
],
7+
#category : 'MuTalk-Tests',
8+
#package : 'MuTalk-Tests'
9+
}
10+
11+
{ #category : 'testing' }
12+
MTTestFilterTest class >> isAbstract [
13+
14+
^ self == MTTestFilterTest
15+
]
16+
17+
{ #category : 'running' }
18+
MTTestFilterTest >> runAnalysisWithFilter: aTestFilter on: classesToMutate withTests: testCases [
19+
20+
analysis := MTAnalysis new
21+
testClasses: testCases;
22+
classesToMutate: classesToMutate;
23+
testFilter: aTestFilter.
24+
25+
analysis run
26+
]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
Class {
2+
#name : 'MTTimeTestFilterTest',
3+
#superclass : 'MTTestFilterTest',
4+
#category : 'MuTalk-Tests',
5+
#package : 'MuTalk-Tests'
6+
}
7+
8+
{ #category : 'running' }
9+
MTTimeTestFilterTest >> runAnalysisForTimeCondition: aDuration [
10+
11+
self
12+
runAnalysisWithFilter: (MTTimeTestFilter for: aDuration)
13+
on: { MTAuxiliarClassForTimeTestFilter }
14+
withTests: { MTAuxiliarClassForTimeTestFilterTest }
15+
]
16+
17+
{ #category : 'running' }
18+
MTTimeTestFilterTest >> testWith10MillisecondsCondition [
19+
20+
| testCaseReference |
21+
testCaseReference := MTTestCaseReference
22+
for: #test10Milliseconds
23+
in: MTAuxiliarClassForTimeTestFilterTest.
24+
self runAnalysisForTimeCondition:
25+
(self timeToRunFor: testCaseReference) * 10.
26+
27+
self
28+
assert: (analysis generalResult particularResults at: 1) runCount
29+
equals: 1
30+
]
31+
32+
{ #category : 'running' }
33+
MTTimeTestFilterTest >> testWith1SecondCondition [
34+
35+
| testCaseReference |
36+
testCaseReference := MTTestCaseReference
37+
for: #test1Second
38+
in: MTAuxiliarClassForTimeTestFilterTest.
39+
self runAnalysisForTimeCondition:
40+
(self timeToRunFor: testCaseReference) * 10.
41+
42+
self
43+
assert: (analysis generalResult particularResults at: 1) runCount
44+
equals: 2
45+
]
46+
47+
{ #category : 'running' }
48+
MTTimeTestFilterTest >> timeToRunFor: aTestCaseReference [
49+
50+
aTestCaseReference runUnchecked.
51+
^ aTestCaseReference lastTimeToRun
52+
]

0 commit comments

Comments
 (0)