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

Red test filter #96

Merged
merged 19 commits into from
Mar 14, 2024
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
2 changes: 1 addition & 1 deletion .smalltalk.ston
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ SmalltalkCISpec {
],
#testing : {
#exclude : {
#classes : [ #MTAuxiliarTestClassForContinuingTestsExecutionAfterFirstFail ]
#classes : [ #MTAuxiliarTestClassForContinuingTestsExecutionAfterFirstFail, #MTAuxiliarTestClassForRedTestFilter ]
}
}
}
2 changes: 1 addition & 1 deletion src/MuTalk-CI/MTCoveragePropagationPreparation.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ MTCoveragePropagationPreparation >> runTestCase: testCaseReference [
| results |
counter := 1.
results := TestAsserter classForTestResult new.
results addAllResults: testCaseReference runUnchecked.
results addAllResults: testCaseReference run.
^ results
]

Expand Down
14 changes: 7 additions & 7 deletions src/MuTalk-Model/MTAnalysis.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ MTAnalysis >> defaultBudget [
^ MTFreeBudget new
]

{ #category : 'defaults' }
{ #category : 'accessing - defaults' }
MTAnalysis >> defaultLogger [

^ MTNullAnalysisLogger new
Expand Down Expand Up @@ -124,17 +124,15 @@ MTAnalysis >> generateMutations [
{ #category : 'running' }
MTAnalysis >> generateResults [

| filteredTests |
mutantResults := OrderedCollection new.
filteredTests := testFilter filterTests: testCases.

mutations do: [ :aMutation |
(budget exceedsBudgetOn: mutantResults fromTotalMutations: mutations)
ifTrue: [ ^ mutantResults ].
logger logStartEvaluating: aMutation.
mutantResults add: ((MTMutantEvaluation
for: aMutation
using: filteredTests
using: testCases
following: testSelectionStrategy
andConsidering: self coverageAnalysisResult)
valueStoppingOnError: stopOnErrorOrFail) ].
Expand All @@ -143,10 +141,12 @@ MTAnalysis >> generateResults [

{ #category : 'running' }
MTAnalysis >> initialTestRun [
"Do an initial run of the tests to check that they are all green.
Only green tests count for the mutation testing analysis"
"Runs all tests once and filters them"

testCases do: [ :aTestCase | aTestCase runChecked ]
| results |
results := testCases collect: [ :aTestCase | aTestCase run ].
testFilter validateFailuresIn: results.
testCases := testFilter filterTests: testCases
]

{ #category : 'initialization' }
Expand Down
21 changes: 21 additions & 0 deletions src/MuTalk-Model/MTRedTestFilter.class.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
Class {
#name : 'MTRedTestFilter',
#superclass : 'MTTestFilter',
#category : 'MuTalk-Model-Test filters',
#package : 'MuTalk-Model',
#tag : 'Test filters'
}

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

^ aTestCaseCollection reject: [ :testCase |
self failuresOrErrorsIn: testCase lastResult ]
]

{ #category : 'testing' }
MTRedTestFilter >> unwantedFailuresOrErrorsIn: results [
"It is not a problem if there are unwanted failures or errors because they will be filtered out anyway"

^ false
]
41 changes: 17 additions & 24 deletions src/MuTalk-Model/MTTestCaseReference.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ Class {
#superclass : 'Object',
#instVars : [
'testCase',
'lastTimeToRun'
'lastTimeToRun',
'lastResult'
],
#category : 'MuTalk-Model-Core',
#package : 'MuTalk-Model',
Expand Down Expand Up @@ -37,6 +38,18 @@ MTTestCaseReference >> initializeFor: aTestCase [
testCase := aTestCase
]

{ #category : 'accessing' }
MTTestCaseReference >> lastResult [

^ lastResult
]

{ #category : 'accessing' }
MTTestCaseReference >> lastResult: anObject [

lastResult := anObject
]

{ #category : 'accessing' }
MTTestCaseReference >> lastTimeToRun [

Expand All @@ -63,10 +76,9 @@ MTTestCaseReference >> resources [

{ #category : 'evaluating' }
MTTestCaseReference >> run [
"kept for retrocompatibility"

self deprecated: 'Use #runChecked instead.' transformWith: '`@receiver run' -> '`@receiver runChecked'.
^ self runChecked

lastTimeToRun := [ lastResult := self testCase run ] timeToRun.
^ lastResult
]

{ #category : 'evaluating' }
Expand All @@ -75,25 +87,6 @@ MTTestCaseReference >> run: aTestResult [
^ testCase run: aTestResult
]

{ #category : 'evaluating' }
MTTestCaseReference >> runChecked [

| result |
result := self runUnchecked.
(result unexpectedFailureCount > 0 or: [
result unexpectedErrorCount > 0 ]) ifTrue: [
MTTestsWithErrorsException signal ].
^ result
]

{ #category : 'evaluating' }
MTTestCaseReference >> runUnchecked [

| result |
lastTimeToRun := [ result := testCase run ] timeToRun.
^ result
]

{ #category : 'accessing' }
MTTestCaseReference >> selector [

Expand Down
20 changes: 20 additions & 0 deletions src/MuTalk-Model/MTTestFilter.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,12 @@ MTTestFilter >> excludedTestsFrom: aTestCaseCollection [
^ self subclassResponsibility
]

{ #category : 'testing' }
MTTestFilter >> failuresOrErrorsIn: result [

^ result failures isNotEmpty or: [ result unexpectedErrorCount > 0 ]
]

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

Expand Down Expand Up @@ -80,3 +86,17 @@ MTTestFilter >> filteredTestsFrom: aTestCaseCollection [

^ self subclassResponsibility
]

{ #category : 'testing' }
MTTestFilter >> unwantedFailuresOrErrorsIn: results [
"Checks if the results contain failures or errors while they shouldn't"

^ results anySatisfy: [ :result | self failuresOrErrorsIn: result ]
]

{ #category : 'checking' }
MTTestFilter >> validateFailuresIn: results [

(self unwantedFailuresOrErrorsIn: results) ifTrue: [
MTTestsWithErrorsException signal ]
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
Class {
#name : 'MTAuxiliarTestClassForRedTestFilter',
#superclass : 'TestCase',
#category : 'MuTalk-TestResources',
#package : 'MuTalk-TestResources'
}

{ #category : 'tests' }
MTAuxiliarTestClassForRedTestFilter >> testWithError [

self error
]

{ #category : 'tests' }
MTAuxiliarTestClassForRedTestFilter >> testWithoutError [

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

{ #category : 'running' }
MTRedTestFilterTest >> runAnalysis [

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

{ #category : 'tests' }
MTRedTestFilterTest >> testRedTestIsExcluded [

self runAnalysis.

self assert: analysis testCases size equals: 1.
self assert: (analysis testCases includes: (MTTestCaseReference for:
(MTAuxiliarTestClassForRedTestFilter selector: #testWithoutError)))
]
2 changes: 1 addition & 1 deletion src/MuTalk-Tests/MTTestCaseReferenceTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ MTTestCaseReferenceTest >> test1 [
MTTestCaseReferenceTest >> testATestReferenceResult [
| testReference |
testReference := self testReferenceForTest1.
self assert: testReference runUnchecked errors isEmpty.
self assert: testReference run errors isEmpty.

]

Expand Down
1 change: 1 addition & 0 deletions src/MuTalk-Tests/MTTestCasesSelectionStrategyTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ MTTestCasesSelectionStrategyTest >> allTestsFromPackage [
MTAuxiliarClassForTimeTestFilterTest.
MTAuxiliarTestClassForBlockTestFilter.
MTAuxiliarTestClassForPragmaTestFilter.
MTAuxiliarTestClassForRedTestFilter.
MTAuxiliarParametrizedTestClass })
inject: OrderedCollection new
into: [ :tests :testClass |
Expand Down
2 changes: 1 addition & 1 deletion src/MuTalk-Tests/MTTimeTestFilterTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,6 @@ MTTimeTestFilterTest >> testWith1SecondCondition [
{ #category : 'accessing' }
MTTimeTestFilterTest >> timeToRunFor: aTestCaseReference [

aTestCaseReference runUnchecked.
aTestCaseReference run.
^ aTestCaseReference lastTimeToRun
]
Loading