From b4980f5b042d6524bf4ddcb16b52d3e09f604d33 Mon Sep 17 00:00:00 2001 From: Durieux Pol Date: Wed, 24 Jan 2024 17:18:53 +0100 Subject: [PATCH 1/3] added test filter --- src/MuTalk-Model/MTAnalysis.class.st | 27 ++++++++++++++-- src/MuTalk-Model/MTFreeTestFilter.class.st | 13 ++++++++ src/MuTalk-Model/MTTestFilter.class.st | 36 ++++++++++++++++++++++ src/MuTalk-Model/MTTimeTestFilter.class.st | 13 ++++++++ 4 files changed, 87 insertions(+), 2 deletions(-) create mode 100644 src/MuTalk-Model/MTFreeTestFilter.class.st create mode 100644 src/MuTalk-Model/MTTestFilter.class.st create mode 100644 src/MuTalk-Model/MTTimeTestFilter.class.st diff --git a/src/MuTalk-Model/MTAnalysis.class.st b/src/MuTalk-Model/MTAnalysis.class.st index 8fa9b381..472d1e68 100644 --- a/src/MuTalk-Model/MTAnalysis.class.st +++ b/src/MuTalk-Model/MTAnalysis.class.st @@ -13,7 +13,8 @@ Class { 'mutantResults', 'stopOnErrorOrFail', 'testSelectionStrategy', - 'mutantSelectionStrategy' + 'mutantSelectionStrategy', + 'testFilter' ], #category : 'MuTalk-Model', #package : 'MuTalk-Model' @@ -485,6 +486,12 @@ MTAnalysis >> defaultOperators [ ^ MTMutantOperator contents ] +{ #category : 'accessing - defaults' } +MTAnalysis >> defaultTestFilter [ + + ^ MTFreeTestFilter new +] + { #category : 'accessing - defaults' } MTAnalysis >> defaultTestSelectionStrategy [ @@ -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) ]. @@ -558,6 +568,7 @@ MTAnalysis >> initialize [ elapsedTime := 0. logger := self defaultLogger. budget := self defaultBudget. + testFilter := self defaultTestFilter. stopOnErrorOrFail := true ] @@ -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 [ diff --git a/src/MuTalk-Model/MTFreeTestFilter.class.st b/src/MuTalk-Model/MTFreeTestFilter.class.st new file mode 100644 index 00000000..eb3ecbec --- /dev/null +++ b/src/MuTalk-Model/MTFreeTestFilter.class.st @@ -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 +] diff --git a/src/MuTalk-Model/MTTestFilter.class.st b/src/MuTalk-Model/MTTestFilter.class.st new file mode 100644 index 00000000..fae0ebe5 --- /dev/null +++ b/src/MuTalk-Model/MTTestFilter.class.st @@ -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 +] diff --git a/src/MuTalk-Model/MTTimeTestFilter.class.st b/src/MuTalk-Model/MTTimeTestFilter.class.st new file mode 100644 index 00000000..0128661e --- /dev/null +++ b/src/MuTalk-Model/MTTimeTestFilter.class.st @@ -0,0 +1,13 @@ +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 ] +] From 6133fb85c40d4ce7f1108fbd1f0ca1ba69324dce Mon Sep 17 00:00:00 2001 From: Durieux Pol Date: Thu, 25 Jan 2024 11:30:29 +0100 Subject: [PATCH 2/3] tests for time test filter --- src/MuTalk-Model/MTGeneralResult.class.st | 6 +++ src/MuTalk-Model/MTTimeTestFilter.class.st | 3 +- .../MTAuxiliarClassForTimeTestFilter.class.st | 12 +++++ ...uxiliarClassForTimeTestFilterTest.class.st | 18 +++++++ src/MuTalk-Tests/MTTestFilterTest.class.st | 26 ++++++++++ .../MTTimeTestFilterTest.class.st | 52 +++++++++++++++++++ 6 files changed, 116 insertions(+), 1 deletion(-) create mode 100644 src/MuTalk-TestResources/MTAuxiliarClassForTimeTestFilter.class.st create mode 100644 src/MuTalk-TestResources/MTAuxiliarClassForTimeTestFilterTest.class.st create mode 100644 src/MuTalk-Tests/MTTestFilterTest.class.st create mode 100644 src/MuTalk-Tests/MTTimeTestFilterTest.class.st diff --git a/src/MuTalk-Model/MTGeneralResult.class.st b/src/MuTalk-Model/MTGeneralResult.class.st index 7d30972c..8c3b55ad 100644 --- a/src/MuTalk-Model/MTGeneralResult.class.st +++ b/src/MuTalk-Model/MTGeneralResult.class.st @@ -105,6 +105,12 @@ MTGeneralResult >> numberOfTerminatedMutants [ ^ self terminatedMutants size ] +{ #category : 'accessing' } +MTGeneralResult >> particularResults [ + + ^ particularResults +] + { #category : 'printing' } MTGeneralResult >> printDetailedInfoOn: aStream [ diff --git a/src/MuTalk-Model/MTTimeTestFilter.class.st b/src/MuTalk-Model/MTTimeTestFilter.class.st index 0128661e..2f2f0bf5 100644 --- a/src/MuTalk-Model/MTTimeTestFilter.class.st +++ b/src/MuTalk-Model/MTTimeTestFilter.class.st @@ -9,5 +9,6 @@ Class { { #category : 'enumerating' } MTTimeTestFilter >> filterTests: aTestCaseCollection [ - ^ aTestCaseCollection select: [ :testCaseReference | testCaseReference lastTimeToRun <= condition ] + ^ aTestCaseCollection select: [ :testCaseReference | + testCaseReference lastTimeToRun <= condition ] ] diff --git a/src/MuTalk-TestResources/MTAuxiliarClassForTimeTestFilter.class.st b/src/MuTalk-TestResources/MTAuxiliarClassForTimeTestFilter.class.st new file mode 100644 index 00000000..cb3eebf6 --- /dev/null +++ b/src/MuTalk-TestResources/MTAuxiliarClassForTimeTestFilter.class.st @@ -0,0 +1,12 @@ +Class { + #name : 'MTAuxiliarClassForTimeTestFilter', + #superclass : 'Object', + #category : 'MuTalk-TestResources', + #package : 'MuTalk-TestResources' +} + +{ #category : 'accessing' } +MTAuxiliarClassForTimeTestFilter >> simpleMethod [ + + ^ 1 + 1 +] diff --git a/src/MuTalk-TestResources/MTAuxiliarClassForTimeTestFilterTest.class.st b/src/MuTalk-TestResources/MTAuxiliarClassForTimeTestFilterTest.class.st new file mode 100644 index 00000000..64b4471f --- /dev/null +++ b/src/MuTalk-TestResources/MTAuxiliarClassForTimeTestFilterTest.class.st @@ -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 +] diff --git a/src/MuTalk-Tests/MTTestFilterTest.class.st b/src/MuTalk-Tests/MTTestFilterTest.class.st new file mode 100644 index 00000000..b7e133d4 --- /dev/null +++ b/src/MuTalk-Tests/MTTestFilterTest.class.st @@ -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 +] diff --git a/src/MuTalk-Tests/MTTimeTestFilterTest.class.st b/src/MuTalk-Tests/MTTimeTestFilterTest.class.st new file mode 100644 index 00000000..4e20ce8c --- /dev/null +++ b/src/MuTalk-Tests/MTTimeTestFilterTest.class.st @@ -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 +] From 584286688e90d425d5fa1f45404f51f2799ff4aa Mon Sep 17 00:00:00 2001 From: Durieux Pol Date: Thu, 25 Jan 2024 11:42:42 +0100 Subject: [PATCH 3/3] fix --- src/MuTalk-Tests/MTTestCasesSelectionStrategyTest.class.st | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/MuTalk-Tests/MTTestCasesSelectionStrategyTest.class.st b/src/MuTalk-Tests/MTTestCasesSelectionStrategyTest.class.st index 6a55f6f5..bab49688 100644 --- a/src/MuTalk-Tests/MTTestCasesSelectionStrategyTest.class.st +++ b/src/MuTalk-Tests/MTTestCasesSelectionStrategyTest.class.st @@ -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.