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

New test filters #82

Merged
merged 12 commits into from
Feb 22, 2024
13 changes: 13 additions & 0 deletions src/MuTalk-Model/MTBlockTestFilter.class.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
Class {
#name : 'MTBlockTestFilter',
#superclass : 'MTTestFilter',
#category : 'MuTalk-Model-Test filters',
#package : 'MuTalk-Model',
#tag : 'Test filters'
}

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

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

{ #category : 'instance creation' }
MTPragmaTestFilter class >> for: aPragmaSelector [

^ self new
condition: aPragmaSelector;
pragmaArguments: #( );
yourself
]

{ #category : 'instance creation' }
MTPragmaTestFilter class >> for: aPragmaSelector arguments: pragmaArguments [

^ self new
condition: aPragmaSelector;
pragmaArguments: pragmaArguments;
yourself
]

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

^ aTestCaseCollection reject: [ :testCaseReference |
| pragmas |
pragmas := testCaseReference method pragmas.
pragmas anySatisfy: [ :pragma |
pragma selector = condition
& (pragma arguments = pragmaArguments) ] ]
]

{ #category : 'accessing' }
MTPragmaTestFilter >> pragmaArguments [

^ pragmaArguments
]

{ #category : 'accessing' }
MTPragmaTestFilter >> pragmaArguments: anObject [

pragmaArguments := anObject
]
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
Class {
#name : 'MTAuxiliarClassForTimeTestFilter',
#name : 'MTAuxiliarClassForTestFilter',
#superclass : 'Object',
#category : 'MuTalk-TestResources',
#package : 'MuTalk-TestResources'
}

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

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

{ #category : 'tests' }
MTAuxiliarTestClassForBlockTestFilter >> testX [

self assert: true
]

{ #category : 'tests' }
MTAuxiliarTestClassForBlockTestFilter >> testY [

self assert: true
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
Class {
#name : 'MTAuxiliarTestClassForPragmaTestFilter',
#superclass : 'TestCase',
#category : 'MuTalk-TestResources',
#package : 'MuTalk-TestResources'
}

{ #category : 'tests' }
MTAuxiliarTestClassForPragmaTestFilter >> testWithPragma [

<aPragma>
self assert: true
]

{ #category : 'tests' }
MTAuxiliarTestClassForPragmaTestFilter >> testWithoutPragma [

self assert: true
]
49 changes: 49 additions & 0 deletions src/MuTalk-Tests/MTBlockTestFilterTest.class.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
Class {
#name : 'MTBlockTestFilterTest',
#superclass : 'MTTestFilterTest',
#category : 'MuTalk-Tests',
#package : 'MuTalk-Tests'
}

{ #category : 'running' }
MTBlockTestFilterTest >> runAnalysisForBlockCondition: aBlock [

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

{ #category : 'tests' }
MTBlockTestFilterTest >> testAllTestsAreExcluded [

self runAnalysisForBlockCondition: [ :testCase |
testCase selector beginsWith: 'testZ' ].

self
assert: (analysis generalResult particularResults at: 1) runCount
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
]

{ #category : 'tests' }
MTBlockTestFilterTest >> testYTestIsNotExcluded [

self runAnalysisForBlockCondition: [ :testCase |
testCase selector beginsWith: 'test' ].

self
assert: (analysis generalResult particularResults at: 1) runCount
equals: 2
]
58 changes: 58 additions & 0 deletions src/MuTalk-Tests/MTPragmaTestFilterTest.class.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
Class {
#name : 'MTPragmaTestFilterTest',
#superclass : 'MTTestFilterTest',
#category : 'MuTalk-Tests',
#package : 'MuTalk-Tests'
}

{ #category : 'running' }
MTPragmaTestFilterTest >> runAnalysisForPragmaCondition: aPragmaSelector [

self
runAnalysisWithFilter: (MTPragmaTestFilter for: aPragmaSelector)
on: { MTAuxiliarClassForTestFilter }
withTests: { MTAuxiliarTestClassForPragmaTestFilter }
]

{ #category : 'running' }
MTPragmaTestFilterTest >> runAnalysisForPragmaCondition: aPragmaSelector andArguments: pragmaArguments [

self
runAnalysisWithFilter:
(MTPragmaTestFilter for: aPragmaSelector arguments: pragmaArguments)
on: { MTAuxiliarClassForTestFilter }
withTests: { MTAuxiliarTestClassForPragmaTestFilter }
]

{ #category : 'tests' }
MTPragmaTestFilterTest >> testTestWithPragmaIsExcluded [

| result |
self runAnalysisForPragmaCondition: #aPragma.
result := analysis generalResult particularResults at: 1.

self assert: result runCount equals: 1.
self
assert: (result mutantResults at: 1) selector
equals: #testWithoutPragma
]

{ #category : 'tests' }
MTPragmaTestFilterTest >> testTestWithPragmaIsNotExcluded [

self runAnalysisForPragmaCondition: #anotherPragma.

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

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

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

self
assert: (analysis generalResult particularResults at: 1) runCount
equals: 2
]
17 changes: 9 additions & 8 deletions src/MuTalk-Tests/MTTestCasesSelectionStrategyTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,15 @@ Class {
{ #category : 'as yet unclassified' }
MTTestCasesSelectionStrategyTest >> allTestsFromPackage [

^ (OrderedCollection
with: MTTestClassForTestingCoverage
with: MTAuxiliarTestClassForTestingStrategies
with: MTAuxiliarClassForMTAnalysisTest
with: MTAuxiliarTestClassForMTBudget
with:
MTAuxiliarTestClassForContinuingTestsExecutionAfterFirstFail
with: MTAuxiliarClassForTimeTestFilterTest)
^ (OrderedCollection withAll: {
MTTestClassForTestingCoverage.
MTAuxiliarTestClassForTestingStrategies.
MTAuxiliarClassForMTAnalysisTest.
MTAuxiliarTestClassForMTBudget.
MTAuxiliarTestClassForContinuingTestsExecutionAfterFirstFail.
MTAuxiliarClassForTimeTestFilterTest.
MTAuxiliarTestClassForBlockTestFilter.
MTAuxiliarTestClassForPragmaTestFilter })
inject: OrderedCollection new
into: [ :tests :testClass |
tests addAll: testClass suite tests.
Expand Down
16 changes: 9 additions & 7 deletions src/MuTalk-Tests/MTTimeTestFilterTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -10,26 +10,28 @@ MTTimeTestFilterTest >> runAnalysisForTimeCondition: aDuration [

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

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

| testCaseReference |
| testCaseReference result |
testCaseReference := MTTestCaseReference
for: #test10Milliseconds
in: MTAuxiliarClassForTimeTestFilterTest.
self runAnalysisForTimeCondition:
(self timeToRunFor: testCaseReference) * 10.
result := analysis generalResult particularResults at: 1.

self assert: result runCount equals: 1.
self
assert: (analysis generalResult particularResults at: 1) runCount
equals: 1
assert: (result mutantResults at: 1) selector
equals: #test10Milliseconds
Copy link
Contributor

Choose a reason for hiding this comment

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

Oh yes this seems nicer!

]

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

| testCaseReference |
Expand All @@ -44,7 +46,7 @@ MTTimeTestFilterTest >> testWith1SecondCondition [
equals: 2
]

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

aTestCaseReference runUnchecked.
Expand Down
Loading