Skip to content

Commit

Permalink
Merge pull request #72 from DurieuxPol/feat/testFilter
Browse files Browse the repository at this point in the history
Implemented test filters
  • Loading branch information
guillep authored Feb 1, 2024
2 parents 70148a1 + 5842866 commit 4787a5b
Show file tree
Hide file tree
Showing 10 changed files with 204 additions and 3 deletions.
27 changes: 25 additions & 2 deletions src/MuTalk-Model/MTAnalysis.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ Class {
'mutantResults',
'stopOnErrorOrFail',
'testSelectionStrategy',
'mutantSelectionStrategy'
'mutantSelectionStrategy',
'testFilter'
],
#category : 'MuTalk-Model',
#package : 'MuTalk-Model'
Expand Down Expand Up @@ -485,6 +486,12 @@ MTAnalysis >> defaultOperators [
^ MTMutantOperator contents
]

{ #category : 'accessing - defaults' }
MTAnalysis >> defaultTestFilter [

^ MTFreeTestFilter new
]

{ #category : 'accessing - defaults' }
MTAnalysis >> defaultTestSelectionStrategy [

Expand Down Expand Up @@ -525,14 +532,17 @@ MTAnalysis >> generateMutations [
{ #category : 'running' }
MTAnalysis >> generateResults [

| tests |
mutantResults := OrderedCollection new.
tests := testFilter filterTests: testCases.

mutations do: [ :aMutation |
(budget exceedsBudgetOn: mutantResults fromTotalMutations: mutations)
ifTrue: [ ^ mutantResults ].
logger logStartEvaluating: aMutation.
mutantResults add: ((MTMutantEvaluation
for: aMutation
using: testCases
using: tests
following: testSelectionStrategy
andConsidering: self coverageAnalysisResult)
valueStoppingOnError: stopOnErrorOrFail) ].
Expand All @@ -558,6 +568,7 @@ MTAnalysis >> initialize [
elapsedTime := 0.
logger := self defaultLogger.
budget := self defaultBudget.
testFilter := self defaultTestFilter.
stopOnErrorOrFail := true
]

Expand Down Expand Up @@ -695,6 +706,18 @@ MTAnalysis >> testClasses: aClassCollection [
testCases := self testCasesFrom: aClassCollection
]

{ #category : 'accessing' }
MTAnalysis >> testFilter [

^ testFilter
]

{ #category : 'accessing' }
MTAnalysis >> testFilter: anObject [

testFilter := anObject
]

{ #category : 'accessing' }
MTAnalysis >> testSelectionStrategy [

Expand Down
13 changes: 13 additions & 0 deletions src/MuTalk-Model/MTFreeTestFilter.class.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
Class {
#name : 'MTFreeTestFilter',
#superclass : 'MTTestFilter',
#category : 'MuTalk-Model-Test filters',
#package : 'MuTalk-Model',
#tag : 'Test filters'
}

{ #category : 'enumerating' }
MTFreeTestFilter >> filterTests: aTestCaseCollection [

^ aTestCaseCollection
]
6 changes: 6 additions & 0 deletions src/MuTalk-Model/MTGeneralResult.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,12 @@ MTGeneralResult >> numberOfTerminatedMutants [
^ self terminatedMutants size
]

{ #category : 'accessing' }
MTGeneralResult >> particularResults [

^ particularResults
]

{ #category : 'printing' }
MTGeneralResult >> printDetailedInfoOn: aStream [

Expand Down
36 changes: 36 additions & 0 deletions src/MuTalk-Model/MTTestFilter.class.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
Class {
#name : 'MTTestFilter',
#superclass : 'Object',
#instVars : [
'condition'
],
#category : 'MuTalk-Model-Test filters',
#package : 'MuTalk-Model',
#tag : 'Test filters'
}

{ #category : 'instance creation' }
MTTestFilter class >> for: aCondition [

^ self new
condition: aCondition;
yourself
]

{ #category : 'accessing' }
MTTestFilter >> condition [

^ condition
]

{ #category : 'accessing' }
MTTestFilter >> condition: aCondition [

condition := aCondition
]

{ #category : 'enumerating' }
MTTestFilter >> filterTests: aTestCaseCollection [

^ self subclassResponsibility
]
14 changes: 14 additions & 0 deletions src/MuTalk-Model/MTTimeTestFilter.class.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
Class {
#name : 'MTTimeTestFilter',
#superclass : 'MTTestFilter',
#category : 'MuTalk-Model-Test filters',
#package : 'MuTalk-Model',
#tag : 'Test filters'
}

{ #category : 'enumerating' }
MTTimeTestFilter >> filterTests: aTestCaseCollection [

^ aTestCaseCollection select: [ :testCaseReference |
testCaseReference lastTimeToRun <= condition ]
]
12 changes: 12 additions & 0 deletions src/MuTalk-TestResources/MTAuxiliarClassForTimeTestFilter.class.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
Class {
#name : 'MTAuxiliarClassForTimeTestFilter',
#superclass : 'Object',
#category : 'MuTalk-TestResources',
#package : 'MuTalk-TestResources'
}

{ #category : 'accessing' }
MTAuxiliarClassForTimeTestFilter >> simpleMethod [

^ 1 + 1
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
Class {
#name : 'MTAuxiliarClassForTimeTestFilterTest',
#superclass : 'TestCase',
#category : 'MuTalk-TestResources',
#package : 'MuTalk-TestResources'
}

{ #category : 'tests' }
MTAuxiliarClassForTimeTestFilterTest >> test10Milliseconds [

10 milliSeconds wait
]

{ #category : 'tests' }
MTAuxiliarClassForTimeTestFilterTest >> test1Second [

1 second wait
]
3 changes: 2 additions & 1 deletion src/MuTalk-Tests/MTTestCasesSelectionStrategyTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ MTTestCasesSelectionStrategyTest >> allTestsFromPackage [
with: MTAuxiliarClassForMTAnalysisTest
with: MTAuxiliarTestClassForMTBudget
with:
MTAuxiliarTestClassForContinuingTestsExecutionAfterFirstFail)
MTAuxiliarTestClassForContinuingTestsExecutionAfterFirstFail
with: MTAuxiliarClassForTimeTestFilterTest)
inject: OrderedCollection new
into: [ :tests :testClass |
tests addAll: testClass suite tests.
Expand Down
26 changes: 26 additions & 0 deletions src/MuTalk-Tests/MTTestFilterTest.class.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
Class {
#name : 'MTTestFilterTest',
#superclass : 'TestCase',
#instVars : [
'analysis'
],
#category : 'MuTalk-Tests',
#package : 'MuTalk-Tests'
}

{ #category : 'testing' }
MTTestFilterTest class >> isAbstract [

^ self == MTTestFilterTest
]

{ #category : 'running' }
MTTestFilterTest >> runAnalysisWithFilter: aTestFilter on: classesToMutate withTests: testCases [

analysis := MTAnalysis new
testClasses: testCases;
classesToMutate: classesToMutate;
testFilter: aTestFilter.

analysis run
]
52 changes: 52 additions & 0 deletions src/MuTalk-Tests/MTTimeTestFilterTest.class.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
Class {
#name : 'MTTimeTestFilterTest',
#superclass : 'MTTestFilterTest',
#category : 'MuTalk-Tests',
#package : 'MuTalk-Tests'
}

{ #category : 'running' }
MTTimeTestFilterTest >> runAnalysisForTimeCondition: aDuration [

self
runAnalysisWithFilter: (MTTimeTestFilter for: aDuration)
on: { MTAuxiliarClassForTimeTestFilter }
withTests: { MTAuxiliarClassForTimeTestFilterTest }
]

{ #category : 'running' }
MTTimeTestFilterTest >> testWith10MillisecondsCondition [

| testCaseReference |
testCaseReference := MTTestCaseReference
for: #test10Milliseconds
in: MTAuxiliarClassForTimeTestFilterTest.
self runAnalysisForTimeCondition:
(self timeToRunFor: testCaseReference) * 10.

self
assert: (analysis generalResult particularResults at: 1) runCount
equals: 1
]

{ #category : 'running' }
MTTimeTestFilterTest >> testWith1SecondCondition [

| testCaseReference |
testCaseReference := MTTestCaseReference
for: #test1Second
in: MTAuxiliarClassForTimeTestFilterTest.
self runAnalysisForTimeCondition:
(self timeToRunFor: testCaseReference) * 10.

self
assert: (analysis generalResult particularResults at: 1) runCount
equals: 2
]

{ #category : 'running' }
MTTimeTestFilterTest >> timeToRunFor: aTestCaseReference [

aTestCaseReference runUnchecked.
^ aTestCaseReference lastTimeToRun
]

0 comments on commit 4787a5b

Please sign in to comment.