Skip to content

Commit

Permalink
Merge pull request pharo-project#9 from hogoww/master
Browse files Browse the repository at this point in the history
[improvement] move mutant execution logic to be able to rerun it
  • Loading branch information
pavel-krivanek committed Jul 30, 2021
2 parents 3611cf5 + 8d3fa07 commit 551134f
Show file tree
Hide file tree
Showing 8 changed files with 91 additions and 18 deletions.
32 changes: 30 additions & 2 deletions src/MuTalk-Model/MethodMutation.class.st
Expand Up @@ -7,9 +7,10 @@ Class {
'operator',
'originalClass',
'mutatedNode',
'nodeToMutate'
'nodeToMutate',
'testCaseReferences'
],
#category : 'MuTalk-Model'
#category : #'MuTalk-Model'
}

{ #category : #'instance creation' }
Expand Down Expand Up @@ -125,6 +126,33 @@ MethodMutation >> printOn: aStream [
nextPutAll: originalMethod selector printString.
]

{ #category : #running }
MethodMutation >> runMutant [

^ [
self install.
self runTests
] ensure: [ self uninstall ]
]

{ #category : #private }
MethodMutation >> runTests [
| results |
results := TestAsserter classForTestResult new.
testCaseReferences collect: [ :tcr | results addAllResults: tcr runUnchecked ].
^ results
]

{ #category : #private }
MethodMutation >> testCaseReferences [
^ testCaseReferences
]

{ #category : #private }
MethodMutation >> testCaseReferences: aCollectionOfTestCaseReferences [
testCaseReferences := aCollectionOfTestCaseReferences
]

{ #category : #installing }
MethodMutation >> uninstall [
"UnInstall the mutant recompiling the original method into the class."
Expand Down
6 changes: 2 additions & 4 deletions src/MuTalk-Model/MutantEvaluation.class.st
Expand Up @@ -81,13 +81,11 @@ MutantEvaluation >> testResults [
{ #category : #evaluation }
MutantEvaluation >> value [
| testResults |

Stdio stdout nextPutAll: mutation originalMethod name asString; lf; flush.

self initializeCoverageResultIfNil.
testResults := [ mutation install.
self testResults ]
ensure: [ mutation uninstall ].
mutation testCaseReferences: (strategy testCasesToEvaluate: mutation for: self).
testResults := mutation runMutant.
^ MutantEvaluationResult
for: mutation
results: testResults
Expand Down
2 changes: 1 addition & 1 deletion src/MuTalk-Model/MutationTestingAnalysis.class.st
Expand Up @@ -260,7 +260,7 @@ MutationTestingAnalysis >> run [
methods of
those classes) and execute all mutants in the set of testClases.
We obtain a result for each mutant generated"
^[testCases do: [ :aTestCase | aTestCase run ].
^[testCases do: [ :aTestCase | aTestCase runChecked ].
logger logAnalysisStartFor:self.
elapsedTime := Time millisecondsToRun: [
self generateCoverageAnalysis.
Expand Down
25 changes: 19 additions & 6 deletions src/MuTalk-Model/TestCaseReference.class.st
Expand Up @@ -5,7 +5,7 @@ Class {
'class',
'selector'
],
#category : 'MuTalk-Model'
#category : #'MuTalk-Model'
}

{ #category : #'instance creation' }
Expand All @@ -31,18 +31,31 @@ TestCaseReference >> resources [

{ #category : #evaluating }
TestCaseReference >> run [
| result |
result := self testCase run.
(result failuresSize > 0 or: [ result errorsSize > 0])
ifTrue: [TestsWithErrorsException signal].
^ result
"kept for retrocompatibility"

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

{ #category : #evaluating }
TestCaseReference >> run: aTestResult [
^self testCase run: aTestResult
]

{ #category : #evaluating }
TestCaseReference >> runChecked [
| result |
result := self testCase run.
(result failuresSize > 0 or: [ result errorsSize > 0 ])
ifTrue: [ TestsWithErrorsException signalFor: self ].
^ result
]

{ #category : #evaluating }
TestCaseReference >> runUnchecked [
^ self testCase run
]

{ #category : #evaluating }
TestCaseReference >> testCase [
^class selector: selector.
Expand Down
9 changes: 9 additions & 0 deletions src/MuTalk-Model/TestResult.extension.st
@@ -1,5 +1,14 @@
Extension { #name : #TestResult }

{ #category : #'*MuTalk-Model' }
TestResult >> addAllResults: aTestResult [

failures addAll: aTestResult failures.
errors addAll: aTestResult errors.
passed addAll: aTestResult passed.
skipped addAll: aTestResult skipped.
]

{ #category : #'*MuTalk-Model' }
TestResult >> concreteErrors [
^ errors
Expand Down
4 changes: 2 additions & 2 deletions src/MuTalk-Tests/MethodInstallerTest.class.st
Expand Up @@ -5,7 +5,7 @@ Class {
'anonymousClass',
'anonymousClassWithMethod'
],
#category : 'MuTalk-Tests'
#category : #'MuTalk-Tests'
}

{ #category : #accessing }
Expand All @@ -20,7 +20,7 @@ MethodInstallerTest >> methodInstalled [

]

{ #category : #'test resources' }
{ #category : #'as yet unclassified' }
MethodInstallerTest >> methodToUninstall [ ^self
]

Expand Down
27 changes: 26 additions & 1 deletion src/MuTalk-Tests/MethodMutationTest.class.st
@@ -1,9 +1,14 @@
Class {
#name : #MethodMutationTest,
#superclass : #TestCase,
#category : 'MuTalk-Tests'
#category : #'MuTalk-Tests'
}

{ #category : #tests }
MethodMutationTest >> simpleTestCaseRessource [
self assert: 1 + 1 equals: 2
]

{ #category : #'testing accessing' }
MethodMutationTest >> testAccessing [
| compiledMethod operator modifiedSource methodMutation |
Expand Down Expand Up @@ -52,3 +57,23 @@ MethodMutationTest >> testMutatedNodeBugFix [
self shouldnt: [ m mutatedNode ] raise: SubscriptOutOfBounds

]

{ #category : #tests }
MethodMutationTest >> testMutationRun [
| compiledMethod operator modifiedSource methodMutation res |
compiledMethod := AuxiliarClassForMutationTestingAnalysis
>> #methodWithOnePlusSender.
operator := ReplacePlusWithMinusMutantOperator new.
modifiedSource := operator
modifiedSourceFor: compiledMethod
number: 1.
methodMutation := MethodMutation
for: compiledMethod
using: operator
result: modifiedSource
ofClass: AuxiliarClassForMutationTestingAnalysis.
methodMutation testCaseReferences: { TestCaseReference for: #simpleTestCaseRessource in: self class }.
res := methodMutation runMutant.

self assert: res runCount equals: 1.
]
4 changes: 2 additions & 2 deletions src/MuTalk-Tests/TestCaseReferenceTest.class.st
@@ -1,7 +1,7 @@
Class {
#name : #TestCaseReferenceTest,
#superclass : #TestCase,
#category : 'MuTalk-Tests'
#category : #'MuTalk-Tests'
}

{ #category : #resources }
Expand All @@ -13,7 +13,7 @@ TestCaseReferenceTest >> test1 [
TestCaseReferenceTest >> testATestReferenceResult [
| testReference |
testReference := self testReferenceForTest1.
self assert: testReference run errors isEmpty.
self assert: testReference runUnchecked errors isEmpty.

]

Expand Down

0 comments on commit 551134f

Please sign in to comment.