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
]
14 changes: 14 additions & 0 deletions src/MuTalk-Model/MTPragmaRejectionTestFilter.class.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
Class {
#name : 'MTPragmaRejectionTestFilter',
#superclass : 'MTPragmaTestFilter',
#category : 'MuTalk-Model-Test filters',
#package : 'MuTalk-Model',
#tag : 'Test filters'
}

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

^ aTestCaseCollection reject: [ :testCaseReference |
self isPragmaValidFrom: testCaseReference ]
]
14 changes: 14 additions & 0 deletions src/MuTalk-Model/MTPragmaSelectionTestFilter.class.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
Class {
#name : 'MTPragmaSelectionTestFilter',
#superclass : 'MTPragmaTestFilter',
#category : 'MuTalk-Model-Test filters',
#package : 'MuTalk-Model',
#tag : 'Test filters'
}

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

^ aTestCaseCollection select: [ :testCaseReference |
self isPragmaValidFrom: testCaseReference ]
]
58 changes: 58 additions & 0 deletions src/MuTalk-Model/MTPragmaTestFilter.class.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
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 for: aPragmaSelector arguments: #( )
]

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

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

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

^ self == MTPragmaTestFilter
]

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

^ self subclassResponsibility
]

{ #category : 'testing' }
MTPragmaTestFilter >> isPragmaValidFrom: aTestCaseReference [

| pragmas |
pragmas := aTestCaseReference 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
]
60 changes: 60 additions & 0 deletions src/MuTalk-Tests/MTPragmaRejectionTestFilterTest.class.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
Class {
#name : 'MTPragmaRejectionTestFilterTest',
#superclass : 'MTTestFilterTest',
#category : 'MuTalk-Tests',
#package : 'MuTalk-Tests'
}

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

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

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

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

{ #category : 'tests' }
MTPragmaRejectionTestFilterTest >> 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' }
MTPragmaRejectionTestFilterTest >> testTestWithPragmaIsNotExcluded [

self runAnalysisForPragmaCondition: #anotherPragma.

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

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

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

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

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

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

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

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

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

self runAnalysisForPragmaCondition: #anotherPragma.

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

{ #category : 'tests' }
MTPragmaSelectionTestFilterTest >> testAllTestsAreExcluded2 [

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

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

{ #category : 'tests' }
MTPragmaSelectionTestFilterTest >> testTestWithoutPragmaIsExcluded [

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

self assert: result runCount equals: 1.
self
assert: (result mutantResults at: 1) selector
equals: #testWithPragma
]
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