Skip to content

Commit

Permalink
refactoring tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Durieux Pol committed Feb 7, 2024
1 parent b73cad7 commit 99dbb03
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 48 deletions.
40 changes: 24 additions & 16 deletions src/MuTalk-Tests/MTMethodMutationTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,14 @@ MTMethodMutationTest >> testAccessing [
operator := MTReplacePlusWithMinusMutantOperator new.
modifiedSource := operator
modifiedSourceFor: compiledMethod
number: 1.
number: 1
newExpression: operator newExpression.
methodMutation := MTMethodMutation
for: compiledMethod
using: operator
nodeNumber: 1
ofClass: MTAuxiliarClassForMTAnalysis.
ofClass: MTAuxiliarClassForMTAnalysis
replacingWith: operator newExpression.
self
assert: methodMutation originalSource
equals: compiledMethod sourceCode asString.
Expand All @@ -43,12 +45,14 @@ MTMethodMutationTest >> testAccessingToNodes [
operator := MTReplacePlusWithMinusMutantOperator new.
modifiedSource := operator
modifiedSourceFor: compiledMethod
number: 1.
number: 1
newExpression: operator newExpression.
methodMutation := MTMethodMutation
for: compiledMethod
using: operator
nodeNumber: 1
ofClass: MTAuxiliarClassForMTAnalysis.
ofClass: MTAuxiliarClassForMTAnalysis
replacingWith: operator newExpression.
self
assert: methodMutation nodeToMutate formattedCode
equals: '1 + 2'.
Expand All @@ -69,22 +73,23 @@ MTMethodMutationTest >> testMutatedNodeBugFix [
MTMethodMutationTest >> testMutationInfiniteLoop [

| compiledMethod operator modifiedSource methodMutation res |

"This test will execute another test that will time out.
So this test will need a higher time limit"
self timeLimit: self defaultTimeLimit * 2.

compiledMethod := MTFakeInfiniteLoopForTest >> #iterativeFactorial:.
operator := MTReplaceLessOrEqualWithTrueOperator new.

modifiedSource := operator
modifiedSourceFor: compiledMethod
number: 1.
number: 1
newExpression: operator newExpression.
methodMutation := MTMethodMutation
for: compiledMethod
using: operator
nodeNumber: 1
ofClass: MTFakeInfiniteLoopForTest.
ofClass: MTFakeInfiniteLoopForTest
replacingWith: operator newExpression.

methodMutation testCaseReferences: { (MTTestCaseReference
for: #testIterativeFactorial
Expand All @@ -99,22 +104,23 @@ MTMethodMutationTest >> testMutationInfiniteLoop [
MTMethodMutationTest >> testMutationInfiniteRecursion [

| compiledMethod operator modifiedSource methodMutation res |

"This test will execute another test that will time out.
So this test will need a higher time limit"
self timeLimit: self defaultTimeLimit * 2.

compiledMethod := MTFakeInfiniteLoopForTest >> #recursiveFactorial:.
operator := MTReplaceIfTrueReceiverWithFalseOperator new.

modifiedSource := operator
modifiedSourceFor: compiledMethod
number: 1.
number: 1
newExpression: operator newExpression.
methodMutation := MTMethodMutation
for: compiledMethod
using: operator
nodeNumber: 1
ofClass: MTFakeInfiniteLoopForTest.
ofClass: MTFakeInfiniteLoopForTest
replacingWith: operator newExpression.

methodMutation testCaseReferences: { (MTTestCaseReference
for: #testRecursiveFactorial
Expand All @@ -134,12 +140,14 @@ MTMethodMutationTest >> testMutationRun [
operator := MTReplacePlusWithMinusMutantOperator new.
modifiedSource := operator
modifiedSourceFor: compiledMethod
number: 1.
number: 1
newExpression: operator newExpression.
methodMutation := MTMethodMutation
for: compiledMethod
using: operator
nodeNumber: 1
ofClass: MTAuxiliarClassForMTAnalysis.
ofClass: MTAuxiliarClassForMTAnalysis
replacingWith: operator newExpression.
methodMutation testCaseReferences:
{ (MTTestCaseReference for: #simpleTestCaseRessource in: self class) }.
res := methodMutation runMutantStoppingOnError: true.
Expand Down
61 changes: 34 additions & 27 deletions src/MuTalk-Tests/MTMutantOperatorTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -18,45 +18,52 @@ MTMutantOperatorTest class >> packageNamesUnderTest [

{ #category : 'asserts' }
MTMutantOperatorTest >> assertApplyingMutantToFirstSenderInOneSenderMethod [
^ self compareSource:
(self operator
modifiedSourceFor: self class >> #methodWithOneSender
number: 1)
withSourceInMethod: self class >> #methodWithOneSenderModified
replacingSelector: #methodWithOneSender

^ self
compareSource: (self operator
modifiedSourceFor: self class >> #methodWithOneSender
number: 1
newExpression: self operator newExpression)
withSourceInMethod: self class >> #methodWithOneSenderModified
replacingSelector: #methodWithOneSender
]

{ #category : 'asserts' }
MTMutantOperatorTest >> assertApplyingMutantToFirstSenderInTwoSendersMethod [
^self
compareSource:
(self operator
modifiedSourceFor: self class >> #methodWithTwoSenders
number: 1)
withSourceInMethod: self class >> #methodWithTwoSendersModifiedFirst
replacingSelector: #methodWithTwoSenders

^ self
compareSource: (self operator
modifiedSourceFor: self class >> #methodWithTwoSenders
number: 1
newExpression: self operator newExpression)
withSourceInMethod:
self class >> #methodWithTwoSendersModifiedFirst
replacingSelector: #methodWithTwoSenders
]

{ #category : 'asserts' }
MTMutantOperatorTest >> assertApplyingMutantToNonSenderMethod [
^self
compareSource:
(self operator
modifiedSourceFor: self class >> #methodWithNoSenders
number: 1)
withSourceInMethod: self class >> #methodWithNoSenders
replacingSelector: #methodWithNoSenders

^ self
compareSource: (self operator
modifiedSourceFor: self class >> #methodWithNoSenders
number: 1
newExpression: self operator newExpression)
withSourceInMethod: self class >> #methodWithNoSenders
replacingSelector: #methodWithNoSenders
]

{ #category : 'asserts' }
MTMutantOperatorTest >> assertApplyingMutantToSecondSenderInTwoSendersMethod [
^self
compareSource:
(self operator
modifiedSourceFor: self class >> #methodWithTwoSenders
number: 2)
withSourceInMethod: self class >> #methodWithTwoSendersModifiedSecond
replacingSelector: #methodWithTwoSenders

^ self
compareSource: (self operator
modifiedSourceFor: self class >> #methodWithTwoSenders
number: 2
newExpression: self operator newExpression)
withSourceInMethod:
self class >> #methodWithTwoSendersModifiedSecond
replacingSelector: #methodWithTwoSenders
]

{ #category : 'asserts' }
Expand Down
13 changes: 8 additions & 5 deletions src/MuTalk-Tests/MTResource.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,16 @@ MTResource >> methodForBuildingMutant [
{ #category : 'building-private' }
MTResource >> mutation [
"Build Mock Object that simulates a Mutant"
| method |

| method operator |
method := self class >> #methodForBuildingMutant.
operator := MTReplacePlusWithMinusMutantOperator new.
^ MTMethodMutation
for: method
using: MTReplacePlusWithMinusMutantOperator new
nodeNumber: 1
ofClass: self class
for: method
using: operator
nodeNumber: 1
ofClass: self class
replacingWith: operator newExpression
]

{ #category : 'running' }
Expand Down
12 changes: 12 additions & 0 deletions src/MuTalk-Tests/MTSubclassReplacementOperatorTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,18 @@ MTSubclassReplacementOperatorTest >> assertApplyingMutantToFirstSenderInTwoSende
replacingSelector: #methodWithTwoSenders
]

{ #category : 'asserts' }
MTSubclassReplacementOperatorTest >> assertApplyingMutantToNonSenderMethod [

^ self
compareSource: (self operator
modifiedSourceFor: self class >> #methodWithNoSenders
number: 1
newExpression: self newExpression)
withSourceInMethod: self class >> #methodWithNoSenders
replacingSelector: #methodWithNoSenders
]

{ #category : 'asserts' }
MTSubclassReplacementOperatorTest >> assertApplyingMutantToSecondSenderInTwoSendersMethod [

Expand Down

0 comments on commit 99dbb03

Please sign in to comment.