diff --git a/src/MuTalk-Model/MTCompositeTestFilter.class.st b/src/MuTalk-Model/MTCompositeTestFilter.class.st new file mode 100644 index 0000000..58f1ff7 --- /dev/null +++ b/src/MuTalk-Model/MTCompositeTestFilter.class.st @@ -0,0 +1,61 @@ +" +This test filter is a composition of multiple test filters. +It works as if the test collection passes through each test filter one by one. So a test is blocked by the composite test filter if any of its filters blocks the said test. In the same way, a test passes through the composite test filter if it passes through every of its filters. +" +Class { + #name : 'MTCompositeTestFilter', + #superclass : 'MTTestFilter', + #instVars : [ + 'filters' + ], + #category : 'MuTalk-Model-Test filters', + #package : 'MuTalk-Model', + #tag : 'Test filters' +} + +{ #category : 'instance creation' } +MTCompositeTestFilter class >> for: aTestFilterCollection [ + + ^ self new + filters: aTestFilterCollection; + yourself +] + +{ #category : 'enumerating' } +MTCompositeTestFilter >> excludedTestsFrom: aTestCaseCollection [ + + | excludedTestsCollection | + excludedTestsCollection := Dictionary new. + filters do: [ :filter | + excludedTestsCollection addAll: + ((filter excludedTestsFrom: aTestCaseCollection) collect: [ :test | + test -> filter filteredTestReason ]) ]. + ^ excludedTestsCollection asOrderedCollection +] + +{ #category : 'enumerating' } +MTCompositeTestFilter >> filterTests: aTestCaseCollection [ + + excludedTests := self excludedTestsFrom: aTestCaseCollection. + ^ filteredTests := self filteredTestsFrom: aTestCaseCollection +] + +{ #category : 'enumerating' } +MTCompositeTestFilter >> filteredTestsFrom: aTestCaseCollection [ + + | testCaseCollection | + ^ filters inject: aTestCaseCollection into: [ :accumulator :filter | + testCaseCollection := filter filteredTestsFrom: accumulator ] +] + +{ #category : 'accessing' } +MTCompositeTestFilter >> filters [ + + ^ filters +] + +{ #category : 'accessing' } +MTCompositeTestFilter >> filters: anObject [ + + filters := anObject +] diff --git a/src/MuTalk-TestResources/MTAuxiliarClassForTestFilter.class.st b/src/MuTalk-TestResources/MTAuxiliarClassForTestFilter.class.st deleted file mode 100644 index 46cf3f7..0000000 --- a/src/MuTalk-TestResources/MTAuxiliarClassForTestFilter.class.st +++ /dev/null @@ -1,12 +0,0 @@ -Class { - #name : 'MTAuxiliarClassForTestFilter', - #superclass : 'Object', - #category : 'MuTalk-TestResources', - #package : 'MuTalk-TestResources' -} - -{ #category : 'accessing' } -MTAuxiliarClassForTestFilter >> simpleMethod [ - - ^ 1 + 1 -] diff --git a/src/MuTalk-TestResources/MTAuxiliarTestClassForCompositeTestFilter.class.st b/src/MuTalk-TestResources/MTAuxiliarTestClassForCompositeTestFilter.class.st new file mode 100644 index 0000000..86486d1 --- /dev/null +++ b/src/MuTalk-TestResources/MTAuxiliarTestClassForCompositeTestFilter.class.st @@ -0,0 +1,39 @@ +Class { + #name : 'MTAuxiliarTestClassForCompositeTestFilter', + #superclass : 'TestCase', + #category : 'MuTalk-TestResources', + #package : 'MuTalk-TestResources' +} + +{ #category : 'tests' } +MTAuxiliarTestClassForCompositeTestFilter >> testX1 [ + + + +] + +{ #category : 'tests' } +MTAuxiliarTestClassForCompositeTestFilter >> testX2 [ + + +] + +{ #category : 'tests' } +MTAuxiliarTestClassForCompositeTestFilter >> testX3 [ + + + 100 milliSeconds wait +] + +{ #category : 'tests' } +MTAuxiliarTestClassForCompositeTestFilter >> testY1 [ + + +] + +{ #category : 'tests' } +MTAuxiliarTestClassForCompositeTestFilter >> testY2 [ + + + +] diff --git a/src/MuTalk-TestResources/MTAuxiliarClassForTimeTestFilterTest.class.st b/src/MuTalk-TestResources/MTAuxiliarTestClassForTimeTestFilter.class.st similarity index 55% rename from src/MuTalk-TestResources/MTAuxiliarClassForTimeTestFilterTest.class.st rename to src/MuTalk-TestResources/MTAuxiliarTestClassForTimeTestFilter.class.st index 64b4471..15e2758 100644 --- a/src/MuTalk-TestResources/MTAuxiliarClassForTimeTestFilterTest.class.st +++ b/src/MuTalk-TestResources/MTAuxiliarTestClassForTimeTestFilter.class.st @@ -1,18 +1,18 @@ Class { - #name : 'MTAuxiliarClassForTimeTestFilterTest', + #name : 'MTAuxiliarTestClassForTimeTestFilter', #superclass : 'TestCase', #category : 'MuTalk-TestResources', #package : 'MuTalk-TestResources' } { #category : 'tests' } -MTAuxiliarClassForTimeTestFilterTest >> test10Milliseconds [ +MTAuxiliarTestClassForTimeTestFilter >> test10Milliseconds [ 10 milliSeconds wait ] { #category : 'tests' } -MTAuxiliarClassForTimeTestFilterTest >> test1Second [ +MTAuxiliarTestClassForTimeTestFilter >> test1Second [ 1 second wait ] diff --git a/src/MuTalk-Tests/MTBlockTestFilterTest.class.st b/src/MuTalk-Tests/MTBlockTestFilterTest.class.st index cc4d669..9c5e9c4 100644 --- a/src/MuTalk-Tests/MTBlockTestFilterTest.class.st +++ b/src/MuTalk-Tests/MTBlockTestFilterTest.class.st @@ -10,7 +10,7 @@ MTBlockTestFilterTest >> runAnalysisForBlockCondition: aBlock [ self runAnalysisWithFilter: (MTBlockTestFilter for: aBlock) - on: { MTAuxiliarClassForTestFilter } + on: { } withTests: { MTAuxiliarTestClassForBlockTestFilter } ] @@ -20,21 +20,17 @@ MTBlockTestFilterTest >> testAllTestsAreExcluded [ self runAnalysisForBlockCondition: [ :testCase | testCase selector beginsWith: 'testZ' ]. - self - assert: (analysis generalResult particularResults at: 1) runCount - equals: 0 + self assert: analysis testCases size equals: 0 ] { #category : 'tests' } MTBlockTestFilterTest >> testYTestIsExcluded [ - | result | self runAnalysisForBlockCondition: [ :testCase | testCase selector beginsWith: 'testX' ]. - result := analysis generalResult particularResults at: 1. - self assert: result runCount equals: 1. - self assert: (result mutantResults at: 1) selector equals: #testX + self assert: analysis testCases size equals: 1. + self assert: (analysis testCases at: 1) selector equals: #testX ] { #category : 'tests' } @@ -43,7 +39,5 @@ MTBlockTestFilterTest >> testYTestIsNotExcluded [ self runAnalysisForBlockCondition: [ :testCase | testCase selector beginsWith: 'test' ]. - self - assert: (analysis generalResult particularResults at: 1) runCount - equals: 2 + self assert: analysis testCases size equals: 2 ] diff --git a/src/MuTalk-Tests/MTCompositeTestFilterTest.class.st b/src/MuTalk-Tests/MTCompositeTestFilterTest.class.st new file mode 100644 index 0000000..eb02ef4 --- /dev/null +++ b/src/MuTalk-Tests/MTCompositeTestFilterTest.class.st @@ -0,0 +1,29 @@ +Class { + #name : 'MTCompositeTestFilterTest', + #superclass : 'MTTestFilterTest', + #category : 'MuTalk-Tests', + #package : 'MuTalk-Tests' +} + +{ #category : 'running' } +MTCompositeTestFilterTest >> runAnalysisWithFilters: aTestFilterCollection [ + + self + runAnalysisWithFilter: + (MTCompositeTestFilter for: aTestFilterCollection) + on: { } + withTests: { MTAuxiliarTestClassForCompositeTestFilter } +] + +{ #category : 'tests' } +MTCompositeTestFilterTest >> testWithCombinedTestFilters [ + + self runAnalysisWithFilters: { + (MTBlockTestFilter for: [ :testCase | + testCase selector beginsWith: 'testX' ]). + (MTPragmaSelectionTestFilter for: #pragma). + (MTTimeTestFilter for: 10 milliSeconds) }. + + self assert: analysis testCases size equals: 1. + self assert: (analysis testCases at: 1) selector equals: #testX1 +] diff --git a/src/MuTalk-Tests/MTPragmaRejectionTestFilterTest.class.st b/src/MuTalk-Tests/MTPragmaRejectionTestFilterTest.class.st index 3e5548a..084c903 100644 --- a/src/MuTalk-Tests/MTPragmaRejectionTestFilterTest.class.st +++ b/src/MuTalk-Tests/MTPragmaRejectionTestFilterTest.class.st @@ -11,7 +11,7 @@ MTPragmaRejectionTestFilterTest >> runAnalysisForPragmaCondition: aPragmaSelecto self runAnalysisWithFilter: (MTPragmaRejectionTestFilter for: aPragmaSelector) - on: { MTAuxiliarClassForTestFilter } + on: { } withTests: { MTAuxiliarTestClassForPragmaTestFilter } ] @@ -22,20 +22,19 @@ MTPragmaRejectionTestFilterTest >> runAnalysisForPragmaCondition: aPragmaSelecto runAnalysisWithFilter: (MTPragmaRejectionTestFilter for: aPragmaSelector arguments: pragmaArguments) - on: { MTAuxiliarClassForTestFilter } + on: { } withTests: { MTAuxiliarTestClassForPragmaTestFilter } ] { #category : 'tests' } MTPragmaRejectionTestFilterTest >> testTestWithPragmaIsExcluded [ - | result | self runAnalysisForPragmaCondition: #aPragma. - result := analysis generalResult particularResults at: 1. - self assert: result runCount equals: 1. + + self assert: analysis testCases size equals: 1. self - assert: (result mutantResults at: 1) selector + assert: (analysis testCases at: 1) selector equals: #testWithoutPragma ] @@ -44,9 +43,7 @@ MTPragmaRejectionTestFilterTest >> testTestWithPragmaIsNotExcluded [ self runAnalysisForPragmaCondition: #anotherPragma. - self - assert: (analysis generalResult particularResults at: 1) runCount - equals: 2 + self assert: analysis testCases size equals: 2 ] { #category : 'tests' } @@ -54,7 +51,5 @@ MTPragmaRejectionTestFilterTest >> testTestWithPragmaIsNotExcluded2 [ self runAnalysisForPragmaCondition: #aPragma: andArguments: 'arg'. - self - assert: (analysis generalResult particularResults at: 1) runCount - equals: 2 + self assert: analysis testCases size equals: 2 ] diff --git a/src/MuTalk-Tests/MTPragmaSelectionTestFilterTest.class.st b/src/MuTalk-Tests/MTPragmaSelectionTestFilterTest.class.st index 2235d8a..05436ee 100644 --- a/src/MuTalk-Tests/MTPragmaSelectionTestFilterTest.class.st +++ b/src/MuTalk-Tests/MTPragmaSelectionTestFilterTest.class.st @@ -11,7 +11,7 @@ MTPragmaSelectionTestFilterTest >> runAnalysisForPragmaCondition: aPragmaSelecto self runAnalysisWithFilter: (MTPragmaSelectionTestFilter for: aPragmaSelector) - on: { MTAuxiliarClassForTestFilter } + on: { } withTests: { MTAuxiliarTestClassForPragmaTestFilter } ] @@ -22,7 +22,7 @@ MTPragmaSelectionTestFilterTest >> runAnalysisForPragmaCondition: aPragmaSelecto runAnalysisWithFilter: (MTPragmaSelectionTestFilter for: aPragmaSelector arguments: pragmaArguments) - on: { MTAuxiliarClassForTestFilter } + on: { } withTests: { MTAuxiliarTestClassForPragmaTestFilter } ] @@ -31,9 +31,7 @@ MTPragmaSelectionTestFilterTest >> testAllTestsAreExcluded [ self runAnalysisForPragmaCondition: #anotherPragma. - self - assert: (analysis generalResult particularResults at: 1) runCount - equals: 0 + self assert: analysis testCases size equals: 0 ] { #category : 'tests' } @@ -41,20 +39,17 @@ MTPragmaSelectionTestFilterTest >> testAllTestsAreExcluded2 [ self runAnalysisForPragmaCondition: #aPragma: andArguments: { 'arg' }. - self - assert: (analysis generalResult particularResults at: 1) runCount - equals: 0 + self assert: analysis testCases size equals: 0 ] { #category : 'tests' } MTPragmaSelectionTestFilterTest >> testTestWithoutPragmaIsExcluded [ - | result | self runAnalysisForPragmaCondition: #aPragma. - result := analysis generalResult particularResults at: 1. - self assert: result runCount equals: 1. + + self assert: analysis testCases size equals: 1. self - assert: (result mutantResults at: 1) selector + assert: (analysis testCases at: 1) selector equals: #testWithPragma ] diff --git a/src/MuTalk-Tests/MTRedTestFilterTest.class.st b/src/MuTalk-Tests/MTRedTestFilterTest.class.st index b03739c..374902d 100644 --- a/src/MuTalk-Tests/MTRedTestFilterTest.class.st +++ b/src/MuTalk-Tests/MTRedTestFilterTest.class.st @@ -9,8 +9,8 @@ Class { MTRedTestFilterTest >> runAnalysis [ self - runAnalysisWithFilter: (MTRedTestFilter new) - on: { MTAuxiliarClassForTestFilter } + runAnalysisWithFilter: MTRedTestFilter new + on: { } withTests: { MTAuxiliarTestClassForRedTestFilter } ] diff --git a/src/MuTalk-Tests/MTTestCasesSelectionStrategyTest.class.st b/src/MuTalk-Tests/MTTestCasesSelectionStrategyTest.class.st index 586e15c..74b74e7 100644 --- a/src/MuTalk-Tests/MTTestCasesSelectionStrategyTest.class.st +++ b/src/MuTalk-Tests/MTTestCasesSelectionStrategyTest.class.st @@ -17,11 +17,12 @@ MTTestCasesSelectionStrategyTest >> allTestsFromPackage [ MTAuxiliarClassForMTAnalysisTest. MTAuxiliarTestClassForMTBudget. MTAuxiliarTestClassForContinuingTestsExecutionAfterFirstFail. - MTAuxiliarClassForTimeTestFilterTest. + MTAuxiliarTestClassForTimeTestFilter. MTAuxiliarTestClassForBlockTestFilter. MTAuxiliarTestClassForPragmaTestFilter. MTAuxiliarTestClassForRedTestFilter. - MTAuxiliarParametrizedTestClass }) + MTAuxiliarParametrizedTestClass. + MTAuxiliarTestClassForCompositeTestFilter }) inject: OrderedCollection new into: [ :tests :testClass | tests addAll: testClass suite tests. diff --git a/src/MuTalk-Tests/MTTimeTestFilterTest.class.st b/src/MuTalk-Tests/MTTimeTestFilterTest.class.st index 9de92a3..4bf729b 100644 --- a/src/MuTalk-Tests/MTTimeTestFilterTest.class.st +++ b/src/MuTalk-Tests/MTTimeTestFilterTest.class.st @@ -10,24 +10,23 @@ MTTimeTestFilterTest >> runAnalysisForTimeCondition: aDuration [ self runAnalysisWithFilter: (MTTimeTestFilter for: aDuration) - on: { MTAuxiliarClassForTestFilter } - withTests: { MTAuxiliarClassForTimeTestFilterTest } + on: { } + withTests: { MTAuxiliarTestClassForTimeTestFilter } ] { #category : 'tests' } MTTimeTestFilterTest >> testWith10MillisecondsCondition [ - | testCaseReference result testCase | - testCase := MTAuxiliarClassForTimeTestFilterTest selector: + | testCaseReference testCase | + testCase := MTAuxiliarTestClassForTimeTestFilter selector: #test10Milliseconds. testCaseReference := MTTestCaseReference for: testCase. self runAnalysisForTimeCondition: (self timeToRunFor: testCaseReference) * 10. - result := analysis generalResult particularResults at: 1. - self assert: result runCount equals: 1. + self assert: analysis testCases size equals: 1. self - assert: (result mutantResults at: 1) selector + assert: (analysis testCases at: 1) selector equals: #test10Milliseconds ] @@ -35,15 +34,13 @@ MTTimeTestFilterTest >> testWith10MillisecondsCondition [ MTTimeTestFilterTest >> testWith1SecondCondition [ | testCaseReference testCase | - testCase := MTAuxiliarClassForTimeTestFilterTest selector: + testCase := MTAuxiliarTestClassForTimeTestFilter selector: #test1Second. testCaseReference := MTTestCaseReference for: testCase. self runAnalysisForTimeCondition: (self timeToRunFor: testCaseReference) * 10. - self - assert: (analysis generalResult particularResults at: 1) runCount - equals: 2 + self assert: analysis testCases size equals: 2 ] { #category : 'accessing' }