Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Composite test filter #106

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 61 additions & 0 deletions src/MuTalk-Model/MTCompositeTestFilter.class.st
Original file line number Diff line number Diff line change
@@ -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',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add a class comment? Does this filter filters if ALL filters say so, or if ANY filter does it? I assume it should be ANY (otherwise it will be unusable, right?)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It filters if any filter does. It's as if the tests collection passes through each filter one by one.
I'll add a class comment

#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
]
12 changes: 0 additions & 12 deletions src/MuTalk-TestResources/MTAuxiliarClassForTestFilter.class.st

This file was deleted.

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

{ #category : 'tests' }
MTAuxiliarTestClassForCompositeTestFilter >> testX1 [

<pragma>

]

{ #category : 'tests' }
MTAuxiliarTestClassForCompositeTestFilter >> testX2 [


]

{ #category : 'tests' }
MTAuxiliarTestClassForCompositeTestFilter >> testX3 [

<pragma>
100 milliSeconds wait
]

{ #category : 'tests' }
MTAuxiliarTestClassForCompositeTestFilter >> testY1 [


]

{ #category : 'tests' }
MTAuxiliarTestClassForCompositeTestFilter >> testY2 [

<pragma>

]
Original file line number Diff line number Diff line change
@@ -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
]
16 changes: 5 additions & 11 deletions src/MuTalk-Tests/MTBlockTestFilterTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ MTBlockTestFilterTest >> runAnalysisForBlockCondition: aBlock [

self
runAnalysisWithFilter: (MTBlockTestFilter for: aBlock)
on: { MTAuxiliarClassForTestFilter }
on: { }
withTests: { MTAuxiliarTestClassForBlockTestFilter }
]

Expand All @@ -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' }
Expand All @@ -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
]
29 changes: 29 additions & 0 deletions src/MuTalk-Tests/MTCompositeTestFilterTest.class.st
Original file line number Diff line number Diff line change
@@ -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
]
19 changes: 7 additions & 12 deletions src/MuTalk-Tests/MTPragmaRejectionTestFilterTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ MTPragmaRejectionTestFilterTest >> runAnalysisForPragmaCondition: aPragmaSelecto
self
runAnalysisWithFilter:
(MTPragmaRejectionTestFilter for: aPragmaSelector)
on: { MTAuxiliarClassForTestFilter }
on: { }
withTests: { MTAuxiliarTestClassForPragmaTestFilter }
]

Expand All @@ -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
]

Expand All @@ -44,17 +43,13 @@ MTPragmaRejectionTestFilterTest >> testTestWithPragmaIsNotExcluded [

self runAnalysisForPragmaCondition: #anotherPragma.

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

{ #category : 'tests' }
MTPragmaRejectionTestFilterTest >> testTestWithPragmaIsNotExcluded2 [

self runAnalysisForPragmaCondition: #aPragma: andArguments: 'arg'.

self
assert: (analysis generalResult particularResults at: 1) runCount
equals: 2
self assert: analysis testCases size equals: 2
]
19 changes: 7 additions & 12 deletions src/MuTalk-Tests/MTPragmaSelectionTestFilterTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ MTPragmaSelectionTestFilterTest >> runAnalysisForPragmaCondition: aPragmaSelecto
self
runAnalysisWithFilter:
(MTPragmaSelectionTestFilter for: aPragmaSelector)
on: { MTAuxiliarClassForTestFilter }
on: { }
withTests: { MTAuxiliarTestClassForPragmaTestFilter }
]

Expand All @@ -22,7 +22,7 @@ MTPragmaSelectionTestFilterTest >> runAnalysisForPragmaCondition: aPragmaSelecto
runAnalysisWithFilter: (MTPragmaSelectionTestFilter
for: aPragmaSelector
arguments: pragmaArguments)
on: { MTAuxiliarClassForTestFilter }
on: { }
withTests: { MTAuxiliarTestClassForPragmaTestFilter }
]

Expand All @@ -31,30 +31,25 @@ MTPragmaSelectionTestFilterTest >> testAllTestsAreExcluded [

self runAnalysisForPragmaCondition: #anotherPragma.

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

{ #category : 'tests' }
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
]
4 changes: 2 additions & 2 deletions src/MuTalk-Tests/MTRedTestFilterTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ Class {
MTRedTestFilterTest >> runAnalysis [

self
runAnalysisWithFilter: (MTRedTestFilter new)
on: { MTAuxiliarClassForTestFilter }
runAnalysisWithFilter: MTRedTestFilter new
on: { }
withTests: { MTAuxiliarTestClassForRedTestFilter }
]

Expand Down
5 changes: 3 additions & 2 deletions src/MuTalk-Tests/MTTestCasesSelectionStrategyTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
19 changes: 8 additions & 11 deletions src/MuTalk-Tests/MTTimeTestFilterTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -10,40 +10,37 @@ 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
]

{ #category : 'tests' }
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' }
Expand Down
Loading