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

Mutalk handles parametrized tests correctly #95

Merged
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
4 changes: 2 additions & 2 deletions src/MuTalk-Model/MTAnalysis.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -697,8 +697,8 @@ MTAnalysis >> testCasesFrom: aClassCollection [
{ #category : 'tests' }
MTAnalysis >> testCasesReferencesFrom: testClass [

^ testClass allTestSelectors collect: [ :each |
MTTestCaseReference for: each in: testClass ]
^ testClass buildSuite tests collect: [ :each |
MTTestCaseReference for: each ]
]

{ #category : 'accessing' }
Expand Down
49 changes: 25 additions & 24 deletions src/MuTalk-Model/MTTestCaseReference.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ Class {
#name : 'MTTestCaseReference',
#superclass : 'Object',
#instVars : [
'class',
'selector',
'testCase',
guillep marked this conversation as resolved.
Show resolved Hide resolved
'lastTimeToRun'
],
#category : 'MuTalk-Model-Core',
Expand All @@ -12,13 +11,9 @@ Class {
}

{ #category : 'instance creation' }
MTTestCaseReference class >> for: aSelector in: aClass [
^self new initializeFor: aSelector in: aClass
]
MTTestCaseReference class >> for: aTestCase [

{ #category : 'instance creation' }
MTTestCaseReference class >> forTestCase: aTestCase [
^self for: aTestCase selector in: aTestCase class
^ self new initializeFor: aTestCase
]

{ #category : 'comparing' }
Expand All @@ -33,35 +28,37 @@ MTTestCaseReference >> = anObject [
{ #category : 'comparing' }
MTTestCaseReference >> hash [

^ selector hash + class hash
^ testCase selector hash + testCase class hash
]

{ #category : 'initialize' }
MTTestCaseReference >> initializeFor: aSelector in: aClass [
class := aClass.
selector := aSelector.
MTTestCaseReference >> initializeFor: aTestCase [

testCase := aTestCase
]

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

^ lastTimeToRun
]

{ #category : 'accessing' }
MTTestCaseReference >> method [
^ class >> selector

^ testCase class >> testCase selector
]
Comment on lines 47 to 50
Copy link

Choose a reason for hiding this comment

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

Maybe would be nice to have in the test case, and do testCase method or testCase methodTest or similar.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I agree but it means changing the TestCase class, which is a different thing.
For now I guess this solution is fine

Copy link
Contributor

Choose a reason for hiding this comment

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

I like the idea, maybe it's worth to do a PR to Pharo? @DurieuxPol ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes we can do that


{ #category : 'printing' }
MTTestCaseReference >> printOn: aStream [

aStream nextPutAll: (aStream print: self testCase)
aStream nextPutAll: (aStream print: testCase)
]

{ #category : 'evaluating' }
MTTestCaseReference >> resources [
^self testCase resources

^ testCase resources
]

{ #category : 'evaluating' }
Expand All @@ -74,39 +71,43 @@ MTTestCaseReference >> run [

{ #category : 'evaluating' }
MTTestCaseReference >> run: aTestResult [
^self testCase run: aTestResult

^ testCase run: aTestResult
]

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

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

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

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

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

^ selector
^ testCase selector
]

{ #category : 'evaluating' }
MTTestCaseReference >> testCase [
^class selector: selector.

^ testCase
]

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

^ class
^ testCase class
]
2 changes: 1 addition & 1 deletion src/MuTalk-Model/MTTestCasesSelectionStrategy.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,5 @@ MTTestCasesSelectionStrategy >> testCasesFromReferencies: aTestReferenceCollecti
testReference testCase ].
selectedTestCases := self testCasesFor: testCases.
^ selectedTestCases collect: [ :testCase |
MTTestCaseReference forTestCase: testCase ]
MTTestCaseReference for: testCase ]
]
29 changes: 29 additions & 0 deletions src/MuTalk-TestResources/MTAuxiliarParametrizedTestClass.class.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
Class {
#name : 'MTAuxiliarParametrizedTestClass',
#superclass : 'ParametrizedTestCase',
#instVars : [
'number'
],
#category : 'MuTalk-TestResources',
#package : 'MuTalk-TestResources'
}

{ #category : 'building suites' }
MTAuxiliarParametrizedTestClass class >> testParameters [

^ ParametrizedTestMatrix new
forSelector: #number addOptions: { 1. 2. 3 };
yourself
]

{ #category : 'accessing' }
MTAuxiliarParametrizedTestClass >> number: aNumber [

number := aNumber
]

{ #category : 'testing' }
MTAuxiliarParametrizedTestClass >> testAddZero [

self assert: number + 0 equals: number
]
11 changes: 11 additions & 0 deletions src/MuTalk-Tests/MTAnalysisTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,17 @@ MTAnalysisTest >> selectForRejectReplacementMutation [
^ OrderedCollection with: operator
]

{ #category : 'tests' }
MTAnalysisTest >> testCorrectNumberOfTestCasesWithParametrizedTestCase [

| analysis |
analysis := MTAnalysis new
testClasses: { MTAuxiliarParametrizedTestClass };
classesToMutate: { }.

self assert: analysis testCases size equals: 3
guillep marked this conversation as resolved.
Show resolved Hide resolved
]

{ #category : 'tests' }
MTAnalysisTest >> testDefaultParameters [

Expand Down
42 changes: 20 additions & 22 deletions src/MuTalk-Tests/MTMethodMutationTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,13 @@ MTMethodMutationTest >> testMutatedNodeBugFix [
{ #category : 'tests' }
MTMethodMutationTest >> testMutationInfiniteLoop [

| compiledMethod operator modifiedSource methodMutation res |
| compiledMethod operator modifiedSource methodMutation res testCase |
"This test will execute another test that will time out.
So this test will need a higher time limit"
self timeLimit: self defaultTimeLimit + (Duration milliSeconds: 10).

compiledMethod := MTFakeInfiniteLoopForTest >> #iterativeFactorial:.
testCase := MTFakeInfiniteLoopsTest selector: #testIterativeFactorial.
operator := MTReplaceLessOrEqualWithTrueOperator new.

modifiedSource := operator
Expand All @@ -85,9 +86,8 @@ MTMethodMutationTest >> testMutationInfiniteLoop [
nodeNumber: 1
ofClass: MTFakeInfiniteLoopForTest.

methodMutation testCaseReferences: { (MTTestCaseReference
for: #testIterativeFactorial
in: MTFakeInfiniteLoopsTest) }.
methodMutation testCaseReferences:
{ (MTTestCaseReference for: testCase) }.

res := methodMutation runMutantStoppingOnError: true in: nil.

Expand All @@ -97,12 +97,13 @@ MTMethodMutationTest >> testMutationInfiniteLoop [
{ #category : 'tests' }
MTMethodMutationTest >> testMutationInfiniteRecursion [

| compiledMethod operator modifiedSource methodMutation res |
| compiledMethod operator modifiedSource methodMutation res testCase |
"This test will execute another test that will time out.
So this test will need a higher time limit"
self timeLimit: self defaultTimeLimit + (Duration milliSeconds: 10).

compiledMethod := MTFakeInfiniteLoopForTest >> #recursiveFactorial:.
testCase := MTFakeInfiniteLoopsTest selector: #testRecursiveFactorial.
operator := MTReplaceIfTrueReceiverWithFalseOperator new.

modifiedSource := operator
Expand All @@ -114,9 +115,8 @@ MTMethodMutationTest >> testMutationInfiniteRecursion [
nodeNumber: 1
ofClass: MTFakeInfiniteLoopForTest.

methodMutation testCaseReferences: { (MTTestCaseReference
for: #testRecursiveFactorial
in: MTFakeInfiniteLoopsTest) }.
methodMutation testCaseReferences:
{ (MTTestCaseReference for: testCase) }.

res := methodMutation runMutantStoppingOnError: true in: nil.

Expand All @@ -126,7 +126,8 @@ MTMethodMutationTest >> testMutationInfiniteRecursion [
{ #category : 'tests' }
MTMethodMutationTest >> testMutationNotInstalling [

| methodMutation res mutantEvaluation |
| methodMutation res mutantEvaluation testCase |
testCase := MTFakeInfiniteLoopsTest selector: #testRecursiveFactorial.
methodMutation := MTFailedInstallMethodMutation
for:
MTFakeInfiniteLoopForTest >> #iterativeFactorial:
Expand All @@ -137,9 +138,7 @@ MTMethodMutationTest >> testMutationNotInstalling [

mutantEvaluation := MTMutantEvaluation
for: methodMutation
using: { (MTTestCaseReference
for: #testRecursiveFactorial
in: MTFakeInfiniteLoopsTest) }
using: { (MTTestCaseReference for: testCase) }
following:
MTAllTestsMethodsRunningTestSelectionStrategy
new
Expand All @@ -152,7 +151,8 @@ MTMethodMutationTest >> testMutationNotInstalling [
{ #category : 'tests' }
MTMethodMutationTest >> testMutationNotRunning [

| methodMutation res mutantEvaluation |
| methodMutation res mutantEvaluation testCase |
testCase := MTFakeInfiniteLoopsTest selector: #testRecursiveFactorial.
methodMutation := MTFailedRunMethodMutation
for:
MTFakeInfiniteLoopForTest >> #iterativeFactorial:
Expand All @@ -163,9 +163,7 @@ MTMethodMutationTest >> testMutationNotRunning [

mutantEvaluation := MTMutantEvaluation
for: methodMutation
using: { (MTTestCaseReference
for: #testRecursiveFactorial
in: MTFakeInfiniteLoopsTest) }
using: { (MTTestCaseReference for: testCase) }
following:
MTAllTestsMethodsRunningTestSelectionStrategy
new
Expand All @@ -178,7 +176,8 @@ MTMethodMutationTest >> testMutationNotRunning [
{ #category : 'tests' }
MTMethodMutationTest >> testMutationNotUninstalling [

| methodMutation res mutantEvaluation |
| methodMutation res mutantEvaluation testCase |
testCase := MTFakeInfiniteLoopsTest selector: #testRecursiveFactorial.
methodMutation := MTFailedUninstallMethodMutation
for:
MTFakeInfiniteLoopForTest >> #iterativeFactorial:
Expand All @@ -189,9 +188,7 @@ MTMethodMutationTest >> testMutationNotUninstalling [

mutantEvaluation := MTMutantEvaluation
for: methodMutation
using: { (MTTestCaseReference
for: #testRecursiveFactorial
in: MTFakeInfiniteLoopsTest) }
using: { (MTTestCaseReference for: testCase) }
following:
MTAllTestsMethodsRunningTestSelectionStrategy
new
Expand All @@ -204,9 +201,10 @@ MTMethodMutationTest >> testMutationNotUninstalling [
{ #category : 'tests' }
MTMethodMutationTest >> testMutationRun [

| compiledMethod operator modifiedSource methodMutation res |
| compiledMethod operator modifiedSource methodMutation res testCase |
compiledMethod := MTAuxiliarClassForMTAnalysis
>> #methodWithOnePlusSender.
testCase := self class selector: #simpleTestCaseRessource.
operator := MTReplacePlusWithMinusMutantOperator new.
modifiedSource := operator
modifiedSourceFor: compiledMethod
Expand All @@ -217,7 +215,7 @@ MTMethodMutationTest >> testMutationRun [
nodeNumber: 1
ofClass: MTAuxiliarClassForMTAnalysis.
methodMutation testCaseReferences:
{ (MTTestCaseReference for: #simpleTestCaseRessource in: self class) }.
{ (MTTestCaseReference for: testCase) }.
res := methodMutation runMutantStoppingOnError: true in: nil.

self assert: res runCount equals: 1
Expand Down
2 changes: 1 addition & 1 deletion src/MuTalk-Tests/MTTestCaseReferenceTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,5 @@ MTTestCaseReferenceTest >> testATestReferenceResult [
{ #category : 'resources' }
MTTestCaseReferenceTest >> testReferenceForTest1 [

^ MTTestCaseReference for: #test1 in: self class
^ MTTestCaseReference for: (self class selector: #test1)
]
3 changes: 2 additions & 1 deletion src/MuTalk-Tests/MTTestCasesSelectionStrategyTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ MTTestCasesSelectionStrategyTest >> allTestsFromPackage [
MTAuxiliarTestClassForContinuingTestsExecutionAfterFirstFail.
MTAuxiliarClassForTimeTestFilterTest.
MTAuxiliarTestClassForBlockTestFilter.
MTAuxiliarTestClassForPragmaTestFilter })
MTAuxiliarTestClassForPragmaTestFilter.
MTAuxiliarParametrizedTestClass })
inject: OrderedCollection new
into: [ :tests :testClass |
tests addAll: testClass suite tests.
Expand Down
16 changes: 8 additions & 8 deletions src/MuTalk-Tests/MTTimeTestFilterTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ MTTimeTestFilterTest >> runAnalysisForTimeCondition: aDuration [
{ #category : 'tests' }
MTTimeTestFilterTest >> testWith10MillisecondsCondition [

| testCaseReference result |
testCaseReference := MTTestCaseReference
for: #test10Milliseconds
in: MTAuxiliarClassForTimeTestFilterTest.
| testCaseReference result testCase |
testCase := MTAuxiliarClassForTimeTestFilterTest selector:
#test10Milliseconds.
testCaseReference := MTTestCaseReference for: testCase.
self runAnalysisForTimeCondition:
(self timeToRunFor: testCaseReference) * 10.
result := analysis generalResult particularResults at: 1.
Expand All @@ -34,10 +34,10 @@ MTTimeTestFilterTest >> testWith10MillisecondsCondition [
{ #category : 'tests' }
MTTimeTestFilterTest >> testWith1SecondCondition [

| testCaseReference |
testCaseReference := MTTestCaseReference
for: #test1Second
in: MTAuxiliarClassForTimeTestFilterTest.
| testCaseReference testCase |
testCase := MTAuxiliarClassForTimeTestFilterTest selector:
#test1Second.
testCaseReference := MTTestCaseReference for: testCase.
self runAnalysisForTimeCondition:
(self timeToRunFor: testCaseReference) * 10.

Expand Down
4 changes: 2 additions & 2 deletions src/MuTalk-Utilities/MTMatrix.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -184,8 +184,8 @@ MTMatrix >> failingTestsFor: aMutation [
{ #category : 'computing' }
MTMatrix >> failuresFor: aMutant [

^ (self evaluationResultFor: aMutant) defects asOrderedCollection collect: [ :each |
MTTestCaseReference for: each selector in: each class ]
^ (self evaluationResultFor: aMutant) defects asOrderedCollection
collect: [ :each | MTTestCaseReference for: each ]
]

{ #category : 'computing' }
Expand Down
Loading