From c5d585d2c6447c23a727ee0c43bc80e37274d018 Mon Sep 17 00:00:00 2001 From: anquetil Date: Tue, 29 Oct 2024 14:58:26 +0100 Subject: [PATCH 01/12] refactor FamixDiffResolver: renamed methods, decompose method --- .../FamixDiffResolver.class.st | 147 ++++++++++-------- 1 file changed, 84 insertions(+), 63 deletions(-) diff --git a/src/Famix-Diff-Core/FamixDiffResolver.class.st b/src/Famix-Diff-Core/FamixDiffResolver.class.st index 1e42e9a..65fd089 100644 --- a/src/Famix-Diff-Core/FamixDiffResolver.class.st +++ b/src/Famix-Diff-Core/FamixDiffResolver.class.st @@ -119,10 +119,12 @@ FamixDiffResolver >> diff [ "Compute the diff between the #base MooseModel and the #target MooseModel." [ - self diffEntities. - self result addAll: self changesDico values asSet. - self diffAssociations. - self result addAll: self associationChanges asSet ] ensure: [ self removeFamixDiffCaches ] + self diffEntities. + self result addAll: self changesDico values asSet. + self diffAssociations. + self result addAll: self associationChanges asSet + ] + ensure: [ self removeFamixDiffCaches ] ] { #category : #'run-associations' } @@ -135,35 +137,62 @@ FamixDiffResolver >> diffAssociations [ FamixDiffResolver >> diffEntities [ [ :job | - job max: self baseModel entities size. - "loops on this block" - [ - [ - | baseTodo targetTodo | - self updateProgressBarOf: job. - baseTodo := self topEntitiesToMatchIn: self baseModel. - targetTodo := self topEntitiesToMatchIn: self targetModel. "as soon as one return true, go to next loop iteration" - (self identityMatchesFrom: baseTodo to: targetTodo) or: [ - (self renameMatchesFrom: baseTodo to: targetTodo) or: [ self moveMatchesFrom: baseTodo to: targetTodo ] ] ] whileTrue. + "loops on this block" + job max: self baseModel entities size. + [ + [ + self updateProgressBarOf: job. + self matchTopLevelEntities + ] whileTrue. + self updateProgressBarOf: job. + self lookForMovedEntitiesInUnmatchedEntities + ] whileTrue. + + self updateProgressBarOf: job. + self recordAddRemoveChanges + ] asJob run +] - self updateProgressBarOf: job. +{ #category : #'run-entities' } +FamixDiffResolver >> entitiesToMatchIn: aModel [ - self lookForMovedEntitiesInUnmatchedEntities ] whileTrue. + "not stub, not matched entities" - self updateProgressBarOf: job. - "Each entities in target model that couldn't be matched with entity in base model is considered as added." - (self entitiesToMatchIn: self targetModel) do: [ :entity | self changesDico at: entity put: (FamixAddChange entity: entity) ]. + ^ aModel entities select: [ :e | self shouldMatch: e ] +] - "Each entities in base model that couldn't be matched with entity in target model is considered as removed." - (self entitiesToMatchIn: self baseModel) do: [ :entity | self changesDico at: entity put: (FamixRemovalChange entity: entity) ] ] asJob run +{ #category : #'run-entities' } +FamixDiffResolver >> findIdentityMatchesFrom: baseEntities to: targetEntities [ + "Find the entities that are exactly the same between base version and target version (using #identityMatch:resolver: message). + If there is a match, a FamixUnchangedChange is created and stored." + + ^ self + matches: [ :baseEntity :targetEntity | baseEntity identityMatch: targetEntity resolver: self ] + from: baseEntities + to: targetEntities + changeType: FamixUnchangedChange ] { #category : #'run-entities' } -FamixDiffResolver >> entitiesToMatchIn: aModel [ +FamixDiffResolver >> findMoveMatchesFrom: baseEntities to: targetEntities [ - "not stub, not matched entities" + ^ self + matches: [ :baseEntity :targetEntity | baseEntity moveMatch: targetEntity resolver: self ] + from: baseEntities + to: targetEntities + changeType: FamixMoveChange +] - ^ aModel entities select: [ :e | self shouldMatch: e ] +{ #category : #'run-entities' } +FamixDiffResolver >> findRenameMatchesFrom: baseEntities to: targetEntities [ + "Find the entities that have been renamed between base version and target version (using #renameMatch:resolver: message). + If there is a match, a FamixRenameChange is created and stored." + + ^ self + matches: [ :baseEntity :targetEntity | baseEntity renameMatch: targetEntity resolver: self ] + from: baseEntities + to: targetEntities + changeType: FamixRenameChange ] { #category : #testing } @@ -185,18 +214,6 @@ FamixDiffResolver >> hasParentMatched: entity ignoringParentsIn: aCollection [ ^ true ] -{ #category : #'run-entities' } -FamixDiffResolver >> identityMatchesFrom: baseEntities to: targetEntities [ - "Find the entities that are exactly the same between base version and target version (using #identityMatch:resolver: message). - If there is a match, a FamixUnchangedChange is created and stored." - - ^ self - matches: [ :baseEntity :targetEntity | baseEntity identityMatch: targetEntity resolver: self ] - from: baseEntities - to: targetEntities - changeType: FamixUnchangedChange -] - { #category : #initialization } FamixDiffResolver >> initialize [ super initialize. @@ -229,8 +246,8 @@ FamixDiffResolver >> lookForMovedEntitiesInUnmatchedEntities [ baseTodo := self topEntitiesToMatchIn: self baseModel ignoringParentsIn: unmatchedBasedEntities. targetTodo := self topEntitiesToMatchIn: self targetModel ignoringParentsIn: unmatchedTargetEntities. - ((self moveMatchesFrom: baseTodo to: unmatchedTargetEntities) or: [ - (self moveMatchesFrom: baseTodo to: targetTodo) or: [ self moveMatchesFrom: unmatchedBasedEntities to: targetTodo ] ]) ifTrue: [ ^ true ]. + ((self findMoveMatchesFrom: baseTodo to: unmatchedTargetEntities) or: [ + (self findMoveMatchesFrom: baseTodo to: targetTodo) or: [ self findMoveMatchesFrom: unmatchedBasedEntities to: targetTodo ] ]) ifTrue: [ ^ true ]. unmatchedBasedEntities addAll: baseTodo. unmatchedTargetEntities addAll: targetTodo. @@ -240,6 +257,22 @@ FamixDiffResolver >> lookForMovedEntitiesInUnmatchedEntities [ ^ false ] +{ #category : #'run-entities' } +FamixDiffResolver >> matchTopLevelEntities [ + "Tries to find some match between top level entities (those with parent matched, but not matched themselves) + return whether it could create new matches or not" + + | baseTodo targetTodo | + + baseTodo := self topEntitiesToMatchIn: self baseModel. + targetTodo := self topEntitiesToMatchIn: self targetModel. + + ^(self findIdentityMatchesFrom: baseTodo to: targetTodo) or: + [ (self findRenameMatchesFrom: baseTodo to: targetTodo) or: + [ self findMoveMatchesFrom: baseTodo to: targetTodo ] ] + +] + { #category : #testing } FamixDiffResolver >> matched: entity [ ^ self changesDico includesKey: entity @@ -248,9 +281,7 @@ FamixDiffResolver >> matched: entity [ { #category : #'run-entities' } FamixDiffResolver >> matches: matchblock from: baseEntities to: targetEntities changeType: aChangeClass [ "Find matches defined by matchblock (returns true -> match) between baseEntities and targetEntities. - - When a match is found, ia change is created and added to the change dictionary. - + When a match is found, aChangeClass instance is created and added to the change dictionary. This algorithm essentially takes each entity from baseEntities and try to match them with an entity in targetEntity list." | matchFound | @@ -269,16 +300,6 @@ FamixDiffResolver >> matches: matchblock from: baseEntities to: targetEntities c ^ matchFound ] -{ #category : #'run-entities' } -FamixDiffResolver >> moveMatchesFrom: baseEntities to: targetEntities [ - - ^ self - matches: [ :baseEntity :targetEntity | baseEntity moveMatch: targetEntity resolver: self ] - from: baseEntities - to: targetEntities - changeType: FamixMoveChange -] - { #category : #accessing } FamixDiffResolver >> orchestrator [ ^ orchestrator @@ -289,6 +310,18 @@ FamixDiffResolver >> orchestrator: anObject [ orchestrator := anObject ] +{ #category : #'run-entities' } +FamixDiffResolver >> recordAddRemoveChanges [ + "Each entity in target model that couldn't be matched to an entity in base model is considered added. + Each entity in base model that couldn't be matched to an entity in target model is considered removed." + + (self entitiesToMatchIn: self targetModel) do: [ :entity | + self changesDico at: entity put: (FamixAddChange entity: entity) ]. + + (self entitiesToMatchIn: self baseModel) do: [ :entity | + self changesDico at: entity put: (FamixRemovalChange entity: entity) ] +] + { #category : #run } FamixDiffResolver >> removeFamixDiffCaches [ "FamixDiff will generate some methods to speed up the diff computation process. Here we remove the generated code because we do not want to poluate the image. @@ -308,18 +341,6 @@ FamixDiffResolver >> removedEntitiesFrom: baseEntities [ ^ true ] -{ #category : #'run-entities' } -FamixDiffResolver >> renameMatchesFrom: baseEntities to: targetEntities [ - "Find the entities that have been renamed between base version and target version (using #renameMatch:resolver: message). - If there is a match, a FamixRenameChange is created and stored." - - ^ self - matches: [ :baseEntity :targetEntity | baseEntity renameMatch: targetEntity resolver: self ] - from: baseEntities - to: targetEntities - changeType: FamixRenameChange -] - { #category : #accessing } FamixDiffResolver >> result [ ^ self orchestrator result From a8d05acd409d6a551e855654b28948ef7f7b0f85 Mon Sep 17 00:00:00 2001 From: anquetil Date: Tue, 29 Oct 2024 14:59:46 +0100 Subject: [PATCH 02/12] Refactor FamixDiffEntitiesIdentityTest: decompose tests , introduced a assert/deny helper methods --- .../AbstractFamixDiffWithModelTest.class.st | 36 +++ .../FamixDiffEntitiesIdentityTest.class.st | 257 ++++++++++++------ 2 files changed, 207 insertions(+), 86 deletions(-) diff --git a/src/Famix-Diff-Core-Tests/AbstractFamixDiffWithModelTest.class.st b/src/Famix-Diff-Core-Tests/AbstractFamixDiffWithModelTest.class.st index 90ff9a6..04f769d 100644 --- a/src/Famix-Diff-Core-Tests/AbstractFamixDiffWithModelTest.class.st +++ b/src/Famix-Diff-Core-Tests/AbstractFamixDiffWithModelTest.class.st @@ -7,6 +7,24 @@ Class { #category : #'Famix-Diff-Core-Tests' } +{ #category : #running } +AbstractFamixDiffWithModelTest >> assertIdentityMatch: entity1 to: entity2 [ + + self assert: (entity1 identityMatch: entity2 resolver: self resolver) +] + +{ #category : #running } +AbstractFamixDiffWithModelTest >> assertMoveMatch: entity1 to: entity2 [ + + self assert: (entity1 moveMatch: entity2 resolver: self resolver) +] + +{ #category : #running } +AbstractFamixDiffWithModelTest >> assertRenameMatch: entity1 to: entity2 [ + + self assert: (entity1 renameMatch: entity2 resolver: self resolver) +] + { #category : #accessing } AbstractFamixDiffWithModelTest >> baseEntityNamed: aString [ @@ -33,6 +51,24 @@ AbstractFamixDiffWithModelTest >> createChange: changeClass with: baseEntity and diff result add: change ] +{ #category : #running } +AbstractFamixDiffWithModelTest >> denyIdentityMatch: entity1 to: entity2 [ + + self deny: (entity1 identityMatch: entity2 resolver: self resolver) +] + +{ #category : #running } +AbstractFamixDiffWithModelTest >> denyMoveMatch: entity1 to: entity2 [ + + self deny: (entity1 moveMatch: entity2 resolver: self resolver) +] + +{ #category : #running } +AbstractFamixDiffWithModelTest >> denyRenameMatch: entity1 to: entity2 [ + + self deny: (entity1 renameMatch: entity2 resolver: self resolver) +] + { #category : #accessing } AbstractFamixDiffWithModelTest >> resolver [ diff --git a/src/Famix-Diff-Core-Tests/FamixDiffEntitiesIdentityTest.class.st b/src/Famix-Diff-Core-Tests/FamixDiffEntitiesIdentityTest.class.st index a25e699..73c17e6 100644 --- a/src/Famix-Diff-Core-Tests/FamixDiffEntitiesIdentityTest.class.st +++ b/src/Famix-Diff-Core-Tests/FamixDiffEntitiesIdentityTest.class.st @@ -5,22 +5,42 @@ Class { } { #category : #tests } -FamixDiffEntitiesIdentityTest >> testIdentityMatchClassNot [ +FamixDiffEntitiesIdentityTest >> testIdentityMatchClassMatching [ "setup: create changes for parents" + self + createChange: FamixUnchangedChange + with: (self baseEntityNamed: 'Famix-Diff-TestResource-P2') + and: (self targetEntityNamed: 'Famix-Diff-TestResource-P2'). + + self + assertIdentityMatch: (self baseEntityNamed: 'Smalltalk::A3diff') + to: (self targetEntityNamed: 'Smalltalk::A3diff'). + self + assertIdentityMatch: (self targetEntityNamed: 'Smalltalk::A3diff') + to: (self baseEntityNamed: 'Smalltalk::A3diff') +] + +{ #category : #tests } +FamixDiffEntitiesIdentityTest >> testIdentityMatchClassNoMatch [ + self createChange: FamixUnchangedChange with: (self baseEntityNamed: 'Famix-Diff-TestResource-P2') and: (self targetEntityNamed: 'Famix-Diff-TestResource-P2'). self createChange: FamixAddChange with: (self baseEntityNamed: 'Famix-Diff-TestResource-P1'). - "tests" - self deny: ((self baseEntityNamed: 'Smalltalk::A3diff') identityMatch: (self targetEntityNamed: 'Smalltalk::A2diff') resolver: self resolver). - self deny: ((self targetEntityNamed: 'Smalltalk::A2diff') identityMatch: (self baseEntityNamed: 'Smalltalk::A3diff') resolver: self resolver) + self + denyIdentityMatch: (self baseEntityNamed: 'Smalltalk::A3diff') + to: (self targetEntityNamed: 'Smalltalk::A2diff'). + self + denyIdentityMatch: (self targetEntityNamed: 'Smalltalk::A3diff') + to: (self baseEntityNamed: 'Smalltalk::A2diff'). + ] { #category : #tests } -FamixDiffEntitiesIdentityTest >> testIdentityMatchClassNotPackageDifferent [ +FamixDiffEntitiesIdentityTest >> testIdentityMatchClassNoMatchPackageDifferent [ "setup: create changes for parents" self createChange: FamixAddChange with: (self baseEntityNamed: 'Famix-Diff-TestResource-P1'). @@ -31,8 +51,14 @@ FamixDiffEntitiesIdentityTest >> testIdentityMatchClassNotPackageDifferent [ name: 'A4diff'; parentPackage: (self targetEntityNamed: 'Famix-Diff-TestResource-P1'); typeContainer: (self targetEntityNamed: 'Smalltalk')). - self deny: ((self baseEntityNamed: 'Smalltalk::A4diff') identityMatch: (self targetEntityNamed: 'Smalltalk::A4diff') resolver: self resolver). - self deny: ((self targetEntityNamed: 'Smalltalk::A4diff') identityMatch: (self baseEntityNamed: 'Smalltalk::A4diff') resolver: self resolver) + + self + denyIdentityMatch: (self baseEntityNamed: 'Smalltalk::A4diff') + to: (self targetEntityNamed: 'Smalltalk::A4diff'). + self + denyIdentityMatch: (self targetEntityNamed: 'Smalltalk::A4diff') + to: (self baseEntityNamed: 'Smalltalk::A4diff'). + ] { #category : #tests } @@ -40,106 +66,165 @@ FamixDiffEntitiesIdentityTest >> testIdentityMatchClassParentIsNil [ "classes with same name but different packages" diff targetModel add: (FamixStClass new name: 'A4diff'). - self deny: ((self baseEntityNamed: 'Smalltalk::A4diff') identityMatch: (self targetEntityNamed: 'A4diff') resolver: self resolver). - self deny: ((self targetEntityNamed: 'A4diff') identityMatch: (self baseEntityNamed: 'Smalltalk::A4diff') resolver: self resolver) + self + denyIdentityMatch: (self baseEntityNamed: 'Smalltalk::A4diff') + to: (self targetEntityNamed: 'A4diff'). + self + denyIdentityMatch: (self targetEntityNamed: 'A4diff') + to: (self baseEntityNamed: 'Smalltalk::A4diff') ] { #category : #tests } -FamixDiffEntitiesIdentityTest >> testIdentityMatchClassSame [ - "setup: create changes for parents" +FamixDiffEntitiesIdentityTest >> testIdentityMatchLocalVariableMatching [ + "testing variable 'toto' against itself" - self createChange: FamixUnchangedChange with: (self baseEntityNamed: 'Famix-Diff-TestResource-P2') and: (self targetEntityNamed: 'Famix-Diff-TestResource-P2'). - self assert: ((self baseEntityNamed: 'Smalltalk::A3diff') identityMatch: (self targetEntityNamed: 'Smalltalk::A3diff') resolver: self resolver). - self assert: ((self targetEntityNamed: 'Smalltalk::A3diff') identityMatch: (self baseEntityNamed: 'Smalltalk::A3diff') resolver: self resolver) + self + createChange: FamixUnchangedChange + with: (self baseEntityNamed: 'Smalltalk::A3diff.c3()') + and: (self targetEntityNamed: 'Smalltalk::A3diff.c3()'). + self + createChange: FamixRemovalChange + with: (self baseEntityNamed: 'Smalltalk::A4diff'). + + self + assertIdentityMatch: (self baseEntityNamed: 'Smalltalk::A3diff.c3().toto') + to: (self targetEntityNamed: 'Smalltalk::A3diff.c3().toto'). + self + assertIdentityMatch: (self targetEntityNamed: 'Smalltalk::A3diff.c3().toto') + to: (self baseEntityNamed: 'Smalltalk::A3diff.c3().toto') +] + +{ #category : #tests } +FamixDiffEntitiesIdentityTest >> testIdentityMatchLocalVariableNoMatch [ + "testing variable 'toto' against 'var2'" + + self + createChange: FamixUnchangedChange + with: (self baseEntityNamed: 'Smalltalk::A3diff.c3()') + and: (self targetEntityNamed: 'Smalltalk::A3diff.c3()'). + self + createChange: FamixRemovalChange + with: (self baseEntityNamed: 'Smalltalk::A4diff'). + + self + denyIdentityMatch: (self baseEntityNamed: 'Smalltalk::A3diff.c3().toto') + to: (self targetEntityNamed: 'Smalltalk::A3diff.c3().var2'). + self + denyIdentityMatch: (self targetEntityNamed: 'Smalltalk::A3diff.c3().var2') + to: (self baseEntityNamed: 'Smalltalk::A3diff.c3().toto') ] { #category : #tests } -FamixDiffEntitiesIdentityTest >> testIdentityMatchMethod [ +FamixDiffEntitiesIdentityTest >> testIdentityMatchLocalVariableNoMatchSameName [ "setup: create changes for parents" - self createChange: FamixUnchangedChange with: (self baseEntityNamed: 'Smalltalk::A3diff') and: (self targetEntityNamed: 'Smalltalk::A3diff'). - self createChange: FamixRemovalChange with: (self baseEntityNamed: 'Smalltalk::A4diff'). - self assert: ((self baseEntityNamed: 'Smalltalk::A3diff.c3()') identityMatch: (self targetEntityNamed: 'Smalltalk::A3diff.c3()') resolver: self resolver). - self assert: ((self targetEntityNamed: 'Smalltalk::A3diff.c3()') identityMatch: (self baseEntityNamed: 'Smalltalk::A3diff.c3()') resolver: self resolver). - self deny: ((self baseEntityNamed: 'Smalltalk::A3diff.c3()') identityMatch: (self targetEntityNamed: 'Smalltalk::A3diff.b2()') resolver: self resolver). - self deny: ((self targetEntityNamed: 'Smalltalk::A3diff.b3()') identityMatch: (self baseEntityNamed: 'Smalltalk::A3diff.c3()') resolver: self resolver). - self deny: ((self baseEntityNamed: 'Smalltalk::A3diff.c3()') identityMatch: (self targetEntityNamed: 'Smalltalk::B3diff.c3()') resolver: self resolver). - self deny: ((self targetEntityNamed: 'Smalltalk::B3diff.c3()') identityMatch: (self baseEntityNamed: 'Smalltalk::A3diff.c3()') resolver: self resolver) + | newVar | + self + createChange: FamixUnchangedChange + with: (self baseEntityNamed: 'Smalltalk::A3diff.c3()') + and: (self targetEntityNamed: 'Smalltalk::A3diff.c3()'). + self + createChange: FamixRemovalChange + with: (self baseEntityNamed: 'Smalltalk::A4diff'). + + newVar := FamixStLocalVariable new + name: 'toto'; + parentBehaviouralEntity: (self targetEntityNamed: 'Smalltalk::B3diff.c3()'); + yourself. + + "testing variables 'toto'" + self + denyIdentityMatch: (self baseEntityNamed: 'Smalltalk::A3diff.c3().toto') + to: newVar. + + newVar := FamixStLocalVariable new + name: 'toto'; + parentBehaviouralEntity: (self targetEntityNamed: 'Smalltalk::B3diff.c3()'); + yourself. + + self + denyIdentityMatch: newVar + to: (self baseEntityNamed: 'Smalltalk::A3diff.c3().toto') ] { #category : #tests } -FamixDiffEntitiesIdentityTest >> testIdentityMatchPackage [ - - self assert: - ((self baseEntityNamed: 'Famix-Diff-TestResource-P2') identityMatch: (self targetEntityNamed: 'Famix-Diff-TestResource-P2') resolver: self resolver). - self assert: - ((self targetEntityNamed: 'Famix-Diff-TestResource-P2') identityMatch: (self baseEntityNamed: 'Famix-Diff-TestResource-P2') resolver: self resolver). - self deny: ((self baseEntityNamed: 'Famix-Diff-TestResource-P2') identityMatch: (self targetEntityNamed: 'Famix-Diff-TestResource-P1') resolver: self resolver). - self deny: ((self targetEntityNamed: 'Famix-Diff-TestResource-P1') identityMatch: (self baseEntityNamed: 'Famix-Diff-TestResource-P2') resolver: self resolver) +FamixDiffEntitiesIdentityTest >> testIdentityMatchMethodMatching [ + "setup: create changes for parents" + + self + createChange: FamixUnchangedChange + with: (self baseEntityNamed: 'Smalltalk::A3diff') + and: (self targetEntityNamed: 'Smalltalk::A3diff'). + self + createChange: FamixRemovalChange + with: (self baseEntityNamed: 'Smalltalk::A4diff'). + + self + assertIdentityMatch: (self baseEntityNamed: 'Smalltalk::A3diff.c3()') + to: (self targetEntityNamed: 'Smalltalk::A3diff.c3()'). + self + assertIdentityMatch: (self targetEntityNamed: 'Smalltalk::A3diff.c3()') + to: (self baseEntityNamed: 'Smalltalk::A3diff.c3()') ] { #category : #tests } -FamixDiffEntitiesIdentityTest >> testIdentityMatchStubs [ - - | basP3 tgtP3 basA3 tgtA3 basA3c3 tgtA3c3 tgtB3c3 basA3c3toto tgtA3c3toto | - basP3 := self baseEntityNamed: 'Famix-Diff-TestResource-P2'. - tgtP3 := self targetEntityNamed: 'Famix-Diff-TestResource-P2'. - basA3 := self baseEntityNamed: 'Smalltalk::A3diff'. - tgtA3 := self targetEntityNamed: 'Smalltalk::A3diff'. - basA3c3 := self baseEntityNamed: 'Smalltalk::A3diff.c3()'. - tgtA3c3 := self targetEntityNamed: 'Smalltalk::A3diff.c3()'. - tgtB3c3 := self targetEntityNamed: 'Smalltalk::B3diff.c3()'. - basA3c3toto := self baseEntityNamed: 'Smalltalk::A3diff.c3().toto'. - tgtA3c3toto := self targetEntityNamed: 'Smalltalk::A3diff.c3().toto'. - basP3 isStub: true. - tgtP3 isStub: true. - basA3 isStub: true. - tgtA3 isStub: true. - basA3c3 isStub: true. - tgtA3c3 isStub: true. - tgtB3c3 isStub: true. - basA3c3toto isStub: true. - tgtA3c3toto isStub: true. - self assert: (basP3 identityMatch: tgtP3 resolver: self resolver). - self createChange: FamixUnchangedChange with: basP3 and: tgtP3. - self assert: (basA3 identityMatch: tgtA3 resolver: self resolver). - self createChange: FamixUnchangedChange with: basA3 and: tgtA3. - self assert: (basA3c3 identityMatch: tgtA3c3 resolver: self resolver). - self deny: (basA3c3 identityMatch: tgtB3c3 resolver: self resolver). - self createChange: FamixUnchangedChange with: basA3c3 and: tgtA3c3. - self assert: (basA3c3toto identityMatch: tgtA3c3toto resolver: self resolver). - self assert: - ((self targetEntityNamed: 'Smalltalk::A3diff.c3().toto') identityMatch: (self baseEntityNamed: 'Smalltalk::A3diff.c3().toto') resolver: self resolver) +FamixDiffEntitiesIdentityTest >> testIdentityMatchMethodNoMatch [ + "setup: create changes for parents" + + self + createChange: FamixUnchangedChange + with: (self baseEntityNamed: 'Smalltalk::A3diff') + and: (self targetEntityNamed: 'Smalltalk::A3diff'). + self + createChange: FamixRemovalChange + with: (self baseEntityNamed: 'Smalltalk::A4diff'). + + self + denyIdentityMatch: (self baseEntityNamed: 'Smalltalk::A3diff.c3()') + to: (self targetEntityNamed: 'Smalltalk::A3diff.b2()'). + self + denyIdentityMatch: (self targetEntityNamed: 'Smalltalk::A3diff.b3()') + to: (self baseEntityNamed: 'Smalltalk::A3diff.c3()') ] { #category : #tests } -FamixDiffEntitiesIdentityTest >> testIdentityMatchVariable [ +FamixDiffEntitiesIdentityTest >> testIdentityMatchMethodNoMatchSameName [ "setup: create changes for parents" - self createChange: FamixUnchangedChange with: (self baseEntityNamed: 'Smalltalk::A3diff.c3()') and: (self targetEntityNamed: 'Smalltalk::A3diff.c3()'). - self createChange: FamixRemovalChange with: (self baseEntityNamed: 'Smalltalk::A4diff'). + self + createChange: FamixUnchangedChange + with: (self baseEntityNamed: 'Smalltalk::A3diff') + and: (self targetEntityNamed: 'Smalltalk::A3diff'). + self + createChange: FamixRemovalChange + with: (self baseEntityNamed: 'Smalltalk::A4diff'). - "testing variable 'toto'" - self assert: - ((self baseEntityNamed: 'Smalltalk::A3diff.c3().toto') identityMatch: (self targetEntityNamed: 'Smalltalk::A3diff.c3().toto') resolver: self resolver). - self assert: - ((self targetEntityNamed: 'Smalltalk::A3diff.c3().toto') identityMatch: (self baseEntityNamed: 'Smalltalk::A3diff.c3().toto') resolver: self resolver). + self + denyIdentityMatch: (self baseEntityNamed: 'Smalltalk::A3diff.c3()') + to: (self targetEntityNamed: 'Smalltalk::B3diff.c3()'). + self + denyIdentityMatch: (self targetEntityNamed: 'Smalltalk::B3diff.c3()') + to: (self baseEntityNamed: 'Smalltalk::A3diff.c3()') +] - "testing variable 'toto' against 'var2'" - self deny: - ((self baseEntityNamed: 'Smalltalk::A3diff.c3().toto') identityMatch: (self targetEntityNamed: 'Smalltalk::A3diff.c3().var2') resolver: self resolver). - self deny: - ((self targetEntityNamed: 'Smalltalk::A3diff.c3().var2') identityMatch: (self baseEntityNamed: 'Smalltalk::A3diff.c3().toto') resolver: self resolver). +{ #category : #tests } +FamixDiffEntitiesIdentityTest >> testIdentityMatchPackageMatching [ - "testing variables 'toto'" - self deny: ((self baseEntityNamed: 'Smalltalk::A3diff.c3().toto') - identityMatch: (FamixStLocalVariable new - name: 'toto'; - parentBehaviouralEntity: (self targetEntityNamed: 'Smalltalk::B3diff.c3()'); - yourself) - resolver: self resolver). - self deny: ((FamixStLocalVariable new - name: 'toto'; - parentBehaviouralEntity: (self targetEntityNamed: 'Smalltalk::B3diff.c3()'); - yourself) identityMatch: (self baseEntityNamed: 'Smalltalk::A3diff.c3().toto') resolver: self resolver) + self + assertIdentityMatch: (self baseEntityNamed: 'Famix-Diff-TestResource-P2') + to: (self targetEntityNamed: 'Famix-Diff-TestResource-P2'). + self + assertIdentityMatch: (self targetEntityNamed: 'Famix-Diff-TestResource-P2') + to: (self baseEntityNamed: 'Famix-Diff-TestResource-P2') +] + +{ #category : #tests } +FamixDiffEntitiesIdentityTest >> testIdentityMatchPackageNoMatch [ + + self + denyIdentityMatch: (self baseEntityNamed: 'Famix-Diff-TestResource-P2') + to: (self targetEntityNamed: 'Famix-Diff-TestResource-P1'). + self + denyIdentityMatch: (self targetEntityNamed: 'Famix-Diff-TestResource-P1') + to: (self baseEntityNamed: 'Famix-Diff-TestResource-P2') ] From 6e403102f8fa32ee581abbb20c65857541c9b27a Mon Sep 17 00:00:00 2001 From: anquetil Date: Tue, 29 Oct 2024 15:00:30 +0100 Subject: [PATCH 03/12] Moved some tests to a new class (FamixDiffStubEntitiesIdentityTest) with a setup --- ...FamixDiffStubEntitiesIdentityTest.class.st | 80 +++++++++++++++++++ 1 file changed, 80 insertions(+) create mode 100644 src/Famix-Diff-Core-Tests/FamixDiffStubEntitiesIdentityTest.class.st diff --git a/src/Famix-Diff-Core-Tests/FamixDiffStubEntitiesIdentityTest.class.st b/src/Famix-Diff-Core-Tests/FamixDiffStubEntitiesIdentityTest.class.st new file mode 100644 index 0000000..3a4f3b7 --- /dev/null +++ b/src/Famix-Diff-Core-Tests/FamixDiffStubEntitiesIdentityTest.class.st @@ -0,0 +1,80 @@ +Class { + #name : #FamixDiffStubEntitiesIdentityTest, + #superclass : #AbstractFamixDiffWithModelTest, + #instVars : [ + 'basP3', + 'tgtP3', + 'basA3', + 'tgtA3', + 'basA3c3', + 'tgtA3c3', + 'tgtB3c3', + 'basA3c3toto', + 'tgtA3c3toto' + ], + #category : #'Famix-Diff-Core-Tests' +} + +{ #category : #running } +FamixDiffStubEntitiesIdentityTest >> setUp [ + super setUp. + + basP3 := (self baseEntityNamed: 'Famix-Diff-TestResource-P2') isStub: true ; yourself. + tgtP3 := (self targetEntityNamed: 'Famix-Diff-TestResource-P2') isStub: true ; yourself. + basA3 := (self baseEntityNamed: 'Smalltalk::A3diff') isStub: true ; yourself. + tgtA3 := (self targetEntityNamed: 'Smalltalk::A3diff') isStub: true ; yourself. + basA3c3 := (self baseEntityNamed: 'Smalltalk::A3diff.c3()') isStub: true ; yourself. + tgtA3c3 := (self targetEntityNamed: 'Smalltalk::A3diff.c3()') isStub: true ; yourself. + tgtB3c3 := (self targetEntityNamed: 'Smalltalk::B3diff.c3()') isStub: true ; yourself. + basA3c3toto := (self baseEntityNamed: 'Smalltalk::A3diff.c3().toto') isStub: true ; yourself. + tgtA3c3toto := (self targetEntityNamed: 'Smalltalk::A3diff.c3().toto') isStub: true ; yourself. + +] + +{ #category : #tests } +FamixDiffStubEntitiesIdentityTest >> testIdentityMatchStubsClassMatching [ + + self createChange: FamixUnchangedChange with: basP3 and: tgtP3. + self assert: (basA3 identityMatch: tgtA3 resolver: self resolver). + +] + +{ #category : #tests } +FamixDiffStubEntitiesIdentityTest >> testIdentityMatchStubsLocalVariableSameName [ + + self createChange: FamixUnchangedChange with: basP3 and: tgtP3. + self createChange: FamixUnchangedChange with: basA3 and: tgtA3. + self createChange: FamixUnchangedChange with: basA3c3 and: tgtA3c3. + + self assert: (basA3c3toto identityMatch: tgtA3c3toto resolver: self resolver). + self assert: + ((self targetEntityNamed: 'Smalltalk::A3diff.c3().toto') + identityMatch: (self baseEntityNamed: 'Smalltalk::A3diff.c3().toto') + resolver: self resolver) +] + +{ #category : #tests } +FamixDiffStubEntitiesIdentityTest >> testIdentityMatchStubsMethodMatching [ + + self createChange: FamixUnchangedChange with: basP3 and: tgtP3. + self createChange: FamixUnchangedChange with: basA3 and: tgtA3. + self assert: (basA3c3 identityMatch: tgtA3c3 resolver: self resolver). + +] + +{ #category : #tests } +FamixDiffStubEntitiesIdentityTest >> testIdentityMatchStubsMethodsNoMatch [ + + self createChange: FamixUnchangedChange with: basP3 and: tgtP3. + self createChange: FamixUnchangedChange with: basA3 and: tgtA3. + + self deny: (basA3c3 identityMatch: tgtB3c3 resolver: self resolver). + +] + +{ #category : #tests } +FamixDiffStubEntitiesIdentityTest >> testIdentityMatchStubsPackageMatching [ + + self assert: (basP3 identityMatch: tgtP3 resolver: self resolver). + +] From 74286e5a1fd01d5b2d9d84a2b4347354b7876970 Mon Sep 17 00:00:00 2001 From: anquetil Date: Tue, 29 Oct 2024 15:01:06 +0100 Subject: [PATCH 04/12] Diff of FamixTComments with two tests --- .../FamixDiffEntitiesIdentityTest.class.st | 48 +++++++++++++++++++ .../FamixTComment.extension.st | 10 ++++ 2 files changed, 58 insertions(+) create mode 100644 src/Famix-Diff-Core/FamixTComment.extension.st diff --git a/src/Famix-Diff-Core-Tests/FamixDiffEntitiesIdentityTest.class.st b/src/Famix-Diff-Core-Tests/FamixDiffEntitiesIdentityTest.class.st index 73c17e6..aecc473 100644 --- a/src/Famix-Diff-Core-Tests/FamixDiffEntitiesIdentityTest.class.st +++ b/src/Famix-Diff-Core-Tests/FamixDiffEntitiesIdentityTest.class.st @@ -74,6 +74,54 @@ FamixDiffEntitiesIdentityTest >> testIdentityMatchClassParentIsNil [ to: (self baseEntityNamed: 'Smalltalk::A4diff') ] +{ #category : #tests } +FamixDiffEntitiesIdentityTest >> testIdentityMatchCommentMatching [ + + | baseCmt targetCmt | + baseCmt := FamixStComment new + content: 'This is a comment'; + commentedEntity: + (self baseEntityNamed: 'Smalltalk::B3diff.c3()'); + yourself. + targetCmt := FamixStComment new + content: 'This is a comment'; + commentedEntity: + (self targetEntityNamed: 'Smalltalk::B3diff.c3()'); + yourself. + + self + createChange: FamixUnchangedChange + with: (self baseEntityNamed: 'Smalltalk::B3diff.c3()') + and: (self targetEntityNamed: 'Smalltalk::B3diff.c3()'). + + self assertIdentityMatch: baseCmt to: targetCmt. + self assertIdentityMatch: targetCmt to: baseCmt +] + +{ #category : #tests } +FamixDiffEntitiesIdentityTest >> testIdentityMatchCommentNotMatching [ + + | baseCmt targetCmt | + baseCmt := FamixStComment new + content: 'This is a comment'; + commentedEntity: + (self baseEntityNamed: 'Smalltalk::B3diff.c3()'); + yourself. + targetCmt := FamixStComment new + content: 'This is another comment'; + commentedEntity: + (self targetEntityNamed: 'Smalltalk::B3diff.c3()'); + yourself. + + self + createChange: FamixUnchangedChange + with: (self baseEntityNamed: 'Smalltalk::B3diff.c3()') + and: (self targetEntityNamed: 'Smalltalk::B3diff.c3()'). + + self denyIdentityMatch: baseCmt to: targetCmt. + self denyIdentityMatch: targetCmt to: baseCmt +] + { #category : #tests } FamixDiffEntitiesIdentityTest >> testIdentityMatchLocalVariableMatching [ "testing variable 'toto' against itself" diff --git a/src/Famix-Diff-Core/FamixTComment.extension.st b/src/Famix-Diff-Core/FamixTComment.extension.st new file mode 100644 index 0000000..8dfa1f2 --- /dev/null +++ b/src/Famix-Diff-Core/FamixTComment.extension.st @@ -0,0 +1,10 @@ +Extension { #name : #FamixTComment } + +{ #category : #'*Famix-Diff-Core' } +FamixTComment >> isIdenticalTo: otherEntity resolver: resolver [ + + (self hasSameClassAs: otherEntity resolver: resolver) ifFalse: [ ^ false ]. + (self compareParentsWith: otherEntity resolver: resolver) ifFalse: [ ^ false ]. + (self content = otherEntity content) ifFalse: [ ^ false ]. + ^ true +] From 97fe50a80b5b6f51b35e1b36d10320e0116ac455 Mon Sep 17 00:00:00 2001 From: anquetil Date: Tue, 29 Oct 2024 16:01:48 +0100 Subject: [PATCH 05/12] Refactor on MoveTests --- .../FamixDiffEntitiesMoveTest.class.st | 78 +++++++++++-------- ...FamixDiffStubEntitiesIdentityTest.class.st | 20 ++--- .../FamixDiffStubEntitiesMoveTest.class.st | 44 +++++++++++ .../TEntityMetaLevelDependency.extension.st | 6 +- 4 files changed, 101 insertions(+), 47 deletions(-) create mode 100644 src/Famix-Diff-Core-Tests/FamixDiffStubEntitiesMoveTest.class.st diff --git a/src/Famix-Diff-Core-Tests/FamixDiffEntitiesMoveTest.class.st b/src/Famix-Diff-Core-Tests/FamixDiffEntitiesMoveTest.class.st index 021830a..e8df7e8 100644 --- a/src/Famix-Diff-Core-Tests/FamixDiffEntitiesMoveTest.class.st +++ b/src/Famix-Diff-Core-Tests/FamixDiffEntitiesMoveTest.class.st @@ -7,50 +7,49 @@ Class { { #category : #tests } FamixDiffEntitiesMoveTest >> testMoveMatchClass [ - self createChange: FamixUnchangedChange with: (self baseEntityNamed: 'Famix-Diff-TestResource-P2') and: (self targetEntityNamed: 'Famix-Diff-TestResource-P2'). - self createChange: FamixAddChange with: (self baseEntityNamed: 'Famix-Diff-TestResource-P1'). "changing package of A3 in target model" - (self targetEntityNamed: 'Smalltalk::A3diff') parentPackage: (self targetEntityNamed: 'Famix-Diff-TestResource-P1'). - self assert: ((self baseEntityNamed: 'Smalltalk::A3diff') moveMatch: (self targetEntityNamed: 'Smalltalk::A3diff') resolver: self resolver). - self assert: ((self targetEntityNamed: 'Smalltalk::A3diff') moveMatch: (self baseEntityNamed: 'Smalltalk::A3diff') resolver: self resolver) + self + createChange: FamixUnchangedChange + with: (self baseEntityNamed: 'Famix-Diff-TestResource-P2') + and: (self targetEntityNamed: 'Famix-Diff-TestResource-P2'). + self + createChange: FamixAddChange + with: (self baseEntityNamed: 'Famix-Diff-TestResource-P1'). + + "changing package of A3 in target model" + (self targetEntityNamed: 'Smalltalk::A3diff') parentPackage: + (self targetEntityNamed: 'Famix-Diff-TestResource-P1'). + + self + assertMoveMatch: (self baseEntityNamed: 'Smalltalk::A3diff') + to: (self targetEntityNamed: 'Smalltalk::A3diff'). + self + assertMoveMatch: (self targetEntityNamed: 'Smalltalk::A3diff') + to: (self baseEntityNamed: 'Smalltalk::A3diff') ] { #category : #tests } FamixDiffEntitiesMoveTest >> testMoveMatchMethod [ "moving c3 metod" - (self targetEntityNamed: 'Smalltalk::A3diff.c3()') parentType: (self targetEntityNamed: 'Smalltalk::A2diff'). - self assert: ((self baseEntityNamed: 'Smalltalk::A3diff.c3()') moveMatch: (self targetEntityNamed: 'Smalltalk::A2diff.c3()') resolver: self resolver). - self assert: ((self targetEntityNamed: 'Smalltalk::A2diff.c3()') moveMatch: (self baseEntityNamed: 'Smalltalk::A3diff.c3()') resolver: self resolver) -] + (self targetEntityNamed: 'Smalltalk::A3diff.c3()') parentType: + (self targetEntityNamed: 'Smalltalk::A2diff'). -{ #category : #tests } -FamixDiffEntitiesMoveTest >> testMoveMatchStub [ - - | basA3 tgtA3 basA3c3 tgtA3c3 | - basA3 := self baseEntityNamed: 'Smalltalk::A3diff'. - tgtA3 := self targetEntityNamed: 'Smalltalk::A3diff'. - basA3c3 := self baseEntityNamed: 'Smalltalk::A3diff.c3()'. - tgtA3c3 := self targetEntityNamed: 'Smalltalk::A3diff.c3()'. - self assert: (basA3c3 moveMatch: tgtA3c3 resolver: self resolver). - basA3c3 isStub: true. - tgtA3c3 isStub: true. - self deny: (basA3c3 moveMatch: tgtA3c3 resolver: self resolver). - self assert: (basA3 moveMatch: tgtA3 resolver: self resolver). - basA3 isStub: true. - tgtA3 isStub: true. - self deny: (basA3 moveMatch: tgtA3 resolver: self resolver) + self + assertMoveMatch: (self baseEntityNamed: 'Smalltalk::A3diff.c3()') + to: (self targetEntityNamed: 'Smalltalk::A2diff.c3()'). + self + assertMoveMatch: (self targetEntityNamed: 'Smalltalk::A2diff.c3()') + to: (self baseEntityNamed: 'Smalltalk::A3diff.c3()') ] { #category : #tests } -FamixDiffEntitiesMoveTest >> testMoveMatchVariable [ +FamixDiffEntitiesMoveTest >> testMoveMatchVariableMatching [ + "Maching of variables depend on accesses + Now create one access for the matching to happen" | var1 var2 | - "creating fake accesses because maching of variables depend on them - First we don't create enough accesses (need at least 1)" var1 := self baseEntityNamed: 'Smalltalk::A3diff.c3().toto'. var2 := self targetEntityNamed: 'Smalltalk::B3diff.c3().toto'. - self deny: (var1 moveMatch: var2 resolver: self resolver). - self deny: (var2 moveMatch: var1 resolver: self resolver). "now create one more access" FamixStAccess new variable: var1; @@ -62,6 +61,21 @@ FamixDiffEntitiesMoveTest >> testMoveMatchVariable [ variable: var2; accessor: (self targetEntityNamed: 'Smalltalk::A3diff.b3()'). - self assert: (var1 moveMatch: var2 resolver: self resolver). - self assert: (var2 moveMatch: var1 resolver: self resolver) + self assertMoveMatch: var1 to: var2. + self assertMoveMatch: var2 to: var1 +] + +{ #category : #tests } +FamixDiffEntitiesMoveTest >> testMoveMatchVariableNoMatch [ + "Maching of variables depend on accesses + Here there is not enough (need at least 1)" + + | var1 var2 | + + var1 := self baseEntityNamed: 'Smalltalk::A3diff.c3().toto'. + var2 := self targetEntityNamed: 'Smalltalk::B3diff.c3().toto'. + + self denyMoveMatch: var1 to: var2. + self denyMoveMatch: var2 to: var1. + ] diff --git a/src/Famix-Diff-Core-Tests/FamixDiffStubEntitiesIdentityTest.class.st b/src/Famix-Diff-Core-Tests/FamixDiffStubEntitiesIdentityTest.class.st index 3a4f3b7..bfffbb7 100644 --- a/src/Famix-Diff-Core-Tests/FamixDiffStubEntitiesIdentityTest.class.st +++ b/src/Famix-Diff-Core-Tests/FamixDiffStubEntitiesIdentityTest.class.st @@ -35,8 +35,7 @@ FamixDiffStubEntitiesIdentityTest >> setUp [ FamixDiffStubEntitiesIdentityTest >> testIdentityMatchStubsClassMatching [ self createChange: FamixUnchangedChange with: basP3 and: tgtP3. - self assert: (basA3 identityMatch: tgtA3 resolver: self resolver). - + self assertIdentityMatch: basA3 to: tgtA3 ] { #category : #tests } @@ -46,11 +45,10 @@ FamixDiffStubEntitiesIdentityTest >> testIdentityMatchStubsLocalVariableSameName self createChange: FamixUnchangedChange with: basA3 and: tgtA3. self createChange: FamixUnchangedChange with: basA3c3 and: tgtA3c3. - self assert: (basA3c3toto identityMatch: tgtA3c3toto resolver: self resolver). - self assert: - ((self targetEntityNamed: 'Smalltalk::A3diff.c3().toto') - identityMatch: (self baseEntityNamed: 'Smalltalk::A3diff.c3().toto') - resolver: self resolver) + self assertIdentityMatch: basA3c3toto to: tgtA3c3toto. + self + assertIdentityMatch: (self targetEntityNamed: 'Smalltalk::A3diff.c3().toto') + to: (self baseEntityNamed: 'Smalltalk::A3diff.c3().toto') ] { #category : #tests } @@ -58,8 +56,8 @@ FamixDiffStubEntitiesIdentityTest >> testIdentityMatchStubsMethodMatching [ self createChange: FamixUnchangedChange with: basP3 and: tgtP3. self createChange: FamixUnchangedChange with: basA3 and: tgtA3. - self assert: (basA3c3 identityMatch: tgtA3c3 resolver: self resolver). + self assertIdentityMatch: basA3c3 to: tgtA3c3 ] { #category : #tests } @@ -68,13 +66,11 @@ FamixDiffStubEntitiesIdentityTest >> testIdentityMatchStubsMethodsNoMatch [ self createChange: FamixUnchangedChange with: basP3 and: tgtP3. self createChange: FamixUnchangedChange with: basA3 and: tgtA3. - self deny: (basA3c3 identityMatch: tgtB3c3 resolver: self resolver). - + self denyIdentityMatch: basA3c3 to: tgtB3c3 ] { #category : #tests } FamixDiffStubEntitiesIdentityTest >> testIdentityMatchStubsPackageMatching [ - self assert: (basP3 identityMatch: tgtP3 resolver: self resolver). - + self assertIdentityMatch: basP3 to: tgtP3 ] diff --git a/src/Famix-Diff-Core-Tests/FamixDiffStubEntitiesMoveTest.class.st b/src/Famix-Diff-Core-Tests/FamixDiffStubEntitiesMoveTest.class.st new file mode 100644 index 0000000..5b729ed --- /dev/null +++ b/src/Famix-Diff-Core-Tests/FamixDiffStubEntitiesMoveTest.class.st @@ -0,0 +1,44 @@ +Class { + #name : #FamixDiffStubEntitiesMoveTest, + #superclass : #AbstractFamixDiffWithModelTest, + #instVars : [ + 'basA3', + 'tgtA3', + 'basA3c3', + 'tgtA3c3' + ], + #category : #'Famix-Diff-Core-Tests' +} + +{ #category : #running } +FamixDiffStubEntitiesMoveTest >> setUp [ + + super setUp. + + basA3 := self baseEntityNamed: 'Smalltalk::A3diff'. + tgtA3 := self targetEntityNamed: 'Smalltalk::A3diff'. + basA3c3 := self baseEntityNamed: 'Smalltalk::A3diff.c3()'. + tgtA3c3 := self targetEntityNamed: 'Smalltalk::A3diff.c3()'. +] + +{ #category : #tests } +FamixDiffStubEntitiesMoveTest >> testMoveMatchStubClass [ + + self assertMoveMatch: basA3 to: tgtA3. + + basA3 isStub: true. + tgtA3 isStub: true. + + self denyMoveMatch: basA3 to: tgtA3 +] + +{ #category : #tests } +FamixDiffStubEntitiesMoveTest >> testMoveMatchStubMethod [ + + self assertMoveMatch: basA3c3 to: tgtA3c3. + + basA3c3 isStub: true. + tgtA3c3 isStub: true. + + self denyMoveMatch: basA3c3 to: tgtA3c3 +] diff --git a/src/Famix-Diff-Core/TEntityMetaLevelDependency.extension.st b/src/Famix-Diff-Core/TEntityMetaLevelDependency.extension.st index 881c1b3..8d28b8a 100644 --- a/src/Famix-Diff-Core/TEntityMetaLevelDependency.extension.st +++ b/src/Famix-Diff-Core/TEntityMetaLevelDependency.extension.st @@ -147,11 +147,11 @@ TEntityMetaLevelDependency >> moveMatch: otherEntity resolver: resolver [ (self compareParentsWith: otherEntity resolver: resolver) ifTrue: [ ^ false ]. "See comment in #identityMatch:resolver: to understand what we are doing here" - ^ [ self isMovedOf: otherEntity resolver: resolver ] + ^ [ self isMoveOf: otherEntity resolver: resolver ] on: MessageNotUnderstood do: [ - self generateMethodNamed: #isMovedOf:resolver: basedOnPragmaName: #move. - self isMovedOf: otherEntity resolver: resolver ] + self generateMethodNamed: #isMoveOf:resolver: basedOnPragmaName: #move. + self isMoveOf: otherEntity resolver: resolver ] ] { #category : #'*Famix-Diff-Core' } From b7ee0fb55e3fd7af5a19b00f1cdef77bba2ad508 Mon Sep 17 00:00:00 2001 From: anquetil Date: Tue, 29 Oct 2024 16:07:27 +0100 Subject: [PATCH 06/12] testing Move change for comments --- .../FamixDiffEntitiesMoveTest.class.st | 23 +++++++++++++++++++ .../FamixTComment.extension.st | 7 ++++++ 2 files changed, 30 insertions(+) diff --git a/src/Famix-Diff-Core-Tests/FamixDiffEntitiesMoveTest.class.st b/src/Famix-Diff-Core-Tests/FamixDiffEntitiesMoveTest.class.st index e8df7e8..efa5ff5 100644 --- a/src/Famix-Diff-Core-Tests/FamixDiffEntitiesMoveTest.class.st +++ b/src/Famix-Diff-Core-Tests/FamixDiffEntitiesMoveTest.class.st @@ -27,6 +27,29 @@ FamixDiffEntitiesMoveTest >> testMoveMatchClass [ to: (self baseEntityNamed: 'Smalltalk::A3diff') ] +{ #category : #tests } +FamixDiffEntitiesMoveTest >> testMoveMatchCommentNoMatch [ + "Comments are never moved" + + | baseCmt targetCmt | + baseCmt := FamixStComment new + content: 'This is a comment'; + commentedEntity: (self baseEntityNamed: 'Smalltalk::B3diff.c3()'); + yourself. + targetCmt := FamixStComment new + content: 'This is a comment'; + commentedEntity: (self targetEntityNamed: 'Smalltalk::B3diff.c3()'); + yourself. + + self + createChange: FamixUnchangedChange + with: (self baseEntityNamed: 'Smalltalk::B3diff.c3()') + and: (self targetEntityNamed: 'Smalltalk::B3diff.c3()'). + + self denyMoveMatch: baseCmt to: targetCmt. + self denyMoveMatch: targetCmt to: baseCmt +] + { #category : #tests } FamixDiffEntitiesMoveTest >> testMoveMatchMethod [ "moving c3 metod" diff --git a/src/Famix-Diff-Core/FamixTComment.extension.st b/src/Famix-Diff-Core/FamixTComment.extension.st index 8dfa1f2..1429724 100644 --- a/src/Famix-Diff-Core/FamixTComment.extension.st +++ b/src/Famix-Diff-Core/FamixTComment.extension.st @@ -8,3 +8,10 @@ FamixTComment >> isIdenticalTo: otherEntity resolver: resolver [ (self content = otherEntity content) ifFalse: [ ^ false ]. ^ true ] + +{ #category : #'*Famix-Diff-Core' } +FamixTComment >> moveMatch: otherEntity resolver: resolver [ + "Comments are never moved" + + ^false +] From a5b463607d24393877399e79b0a20eaf62b6bf38 Mon Sep 17 00:00:00 2001 From: anquetil Date: Tue, 29 Oct 2024 17:12:23 +0100 Subject: [PATCH 07/12] Comments in test method --- .../FamixDiffEntitiesMoveTest.class.st | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Famix-Diff-Core-Tests/FamixDiffEntitiesMoveTest.class.st b/src/Famix-Diff-Core-Tests/FamixDiffEntitiesMoveTest.class.st index efa5ff5..02f6f2f 100644 --- a/src/Famix-Diff-Core-Tests/FamixDiffEntitiesMoveTest.class.st +++ b/src/Famix-Diff-Core-Tests/FamixDiffEntitiesMoveTest.class.st @@ -67,8 +67,8 @@ FamixDiffEntitiesMoveTest >> testMoveMatchMethod [ { #category : #tests } FamixDiffEntitiesMoveTest >> testMoveMatchVariableMatching [ - "Maching of variables depend on accesses - Now create one access for the matching to happen" + "MoveMatching of variables depends on accesses + Create one access for the matching to happen" | var1 var2 | var1 := self baseEntityNamed: 'Smalltalk::A3diff.c3().toto'. @@ -90,7 +90,7 @@ FamixDiffEntitiesMoveTest >> testMoveMatchVariableMatching [ { #category : #tests } FamixDiffEntitiesMoveTest >> testMoveMatchVariableNoMatch [ - "Maching of variables depend on accesses + "MoveMatching of variables depends on accesses Here there is not enough (need at least 1)" | var1 var2 | From 31439ce1f4270c2605c96708dc9729249fe9f90b Mon Sep 17 00:00:00 2001 From: anquetil Date: Tue, 29 Oct 2024 17:13:05 +0100 Subject: [PATCH 08/12] Refactored DiffEntitiesRenameTest-s --- .../FamixDiffEntitiesRenameTest.class.st | 102 ++++++++++-------- .../FamixDiffStubEntitiesRenameTest.class.st | 61 +++++++++++ 2 files changed, 120 insertions(+), 43 deletions(-) create mode 100644 src/Famix-Diff-Core-Tests/FamixDiffStubEntitiesRenameTest.class.st diff --git a/src/Famix-Diff-Core-Tests/FamixDiffEntitiesRenameTest.class.st b/src/Famix-Diff-Core-Tests/FamixDiffEntitiesRenameTest.class.st index 82811f0..f75d480 100644 --- a/src/Famix-Diff-Core-Tests/FamixDiffEntitiesRenameTest.class.st +++ b/src/Famix-Diff-Core-Tests/FamixDiffEntitiesRenameTest.class.st @@ -8,9 +8,17 @@ Class { FamixDiffEntitiesRenameTest >> testRenameMatchClass [ (self targetEntityNamed: 'Smalltalk::A3diff') name: 'X3diff'. - self createChange: FamixUnchangedChange with: (self baseEntityNamed: 'Famix-Diff-TestResource-P2') and: (self targetEntityNamed: 'Famix-Diff-TestResource-P2'). - self assert: ((self baseEntityNamed: 'Smalltalk::A3diff') renameMatch: (self targetEntityNamed: 'Smalltalk::X3diff') resolver: self resolver). - self assert: ((self targetEntityNamed: 'Smalltalk::X3diff') renameMatch: (self baseEntityNamed: 'Smalltalk::A3diff') resolver: self resolver) + self + createChange: FamixUnchangedChange + with: (self baseEntityNamed: 'Famix-Diff-TestResource-P2') + and: (self targetEntityNamed: 'Famix-Diff-TestResource-P2'). + + self + assertRenameMatch: (self baseEntityNamed: 'Smalltalk::A3diff') + to: (self targetEntityNamed: 'Smalltalk::X3diff'). + self + assertRenameMatch: (self targetEntityNamed: 'Smalltalk::X3diff') + to: (self baseEntityNamed: 'Smalltalk::A3diff') ] { #category : #tests } @@ -19,57 +27,46 @@ FamixDiffEntitiesRenameTest >> testRenameMatchMethod [ (self targetEntityNamed: 'Smalltalk::B3diff.c3()') name: 'x3'. "Note: does not change the mooseName, so we still look for it later using 'Smalltalk::B3diff.c3()'" (self targetEntityNamed: 'Smalltalk::B3diff.c3()') signature: 'x3()'. - self createChange: FamixUnchangedChange with: (self baseEntityNamed: 'Smalltalk::B3diff') and: (self targetEntityNamed: 'Smalltalk::B3diff'). - self assert: ((self baseEntityNamed: 'Smalltalk::B3diff.c3()') renameMatch: (self targetEntityNamed: 'Smalltalk::B3diff.c3()') resolver: self resolver). - self assert: ((self targetEntityNamed: 'Smalltalk::B3diff.c3()') renameMatch: (self baseEntityNamed: 'Smalltalk::B3diff.c3()') resolver: self resolver) + self + createChange: FamixUnchangedChange + with: (self baseEntityNamed: 'Smalltalk::B3diff') + and: (self targetEntityNamed: 'Smalltalk::B3diff'). + + self + assertRenameMatch: (self baseEntityNamed: 'Smalltalk::B3diff.c3()') + to: (self targetEntityNamed: 'Smalltalk::B3diff.c3()'). + self + assertRenameMatch: (self targetEntityNamed: 'Smalltalk::B3diff.c3()') + to: (self baseEntityNamed: 'Smalltalk::B3diff.c3()') ] { #category : #tests } FamixDiffEntitiesRenameTest >> testRenameMatchPackage [ - (self targetEntityNamed: 'Famix-Diff-TestResource-P2') name: 'Famix-Diff-TestResource-X0'. - self assert: ((self baseEntityNamed: 'Famix-Diff-TestResource-P2') renameMatch: (self targetEntityNamed: 'Famix-Diff-TestResource-X0') resolver: self resolver). - self assert: ((self targetEntityNamed: 'Famix-Diff-TestResource-X0') renameMatch: (self baseEntityNamed: 'Famix-Diff-TestResource-P2') resolver: self resolver) -] + (self targetEntityNamed: 'Famix-Diff-TestResource-P2') name: + 'Famix-Diff-TestResource-X0'. -{ #category : #tests } -FamixDiffEntitiesRenameTest >> testRenameMatchStub [ - - | basA3 tgtA3 basA3c3 tgtA3c3 basP3 tgtP3 | - basP3 := self baseEntityNamed: 'Famix-Diff-TestResource-P2'. - tgtP3 := self targetEntityNamed: 'Famix-Diff-TestResource-P2'. - basA3 := self baseEntityNamed: 'Smalltalk::A3diff'. - tgtA3 := self targetEntityNamed: 'Smalltalk::A3diff'. - basA3c3 := self baseEntityNamed: 'Smalltalk::A3diff.c3()'. - tgtA3c3 := self targetEntityNamed: 'Smalltalk::A3diff.c3()'. "self assert: (basA3c3 renameMatch: tgtA3c3 givenChanges: testChanges). - basA3c3 isStub: true. - tgtA3c3 isStub: true. - self deny: (basA3c3 renameMatch: tgtA3c3 givenChanges: testChanges)." - self createChange: FamixUnchangedChange with: basP3 and: tgtP3. - tgtA3 name: 'X3'. - self assert: (basA3 renameMatch: tgtA3 resolver: self resolver). - basA3 isStub: true. - tgtA3 isStub: true. - self deny: (basA3 renameMatch: tgtA3 resolver: self resolver). - self createChange: FamixUnchangedChange with: basA3 and: tgtA3. - tgtA3c3 name: 'x3'. - tgtA3c3 signature: 'x3()'. - self assert: (basA3c3 renameMatch: tgtA3c3 resolver: self resolver). - basA3c3 isStub: true. - tgtA3c3 isStub: true. - self deny: (basA3c3 renameMatch: tgtA3c3 resolver: self resolver) + self + assertRenameMatch: (self baseEntityNamed: 'Famix-Diff-TestResource-P2') + to: (self targetEntityNamed: 'Famix-Diff-TestResource-X0'). + self + assertRenameMatch: (self targetEntityNamed: 'Famix-Diff-TestResource-X0') + to: (self baseEntityNamed: 'Famix-Diff-TestResource-P2') ] { #category : #tests } -FamixDiffEntitiesRenameTest >> testRenameMatchVariable [ +FamixDiffEntitiesRenameTest >> testRenameMatchVariableMatching [ + "RenameMatching of variables depends on accesses + Create one access for the matching to happen" | var1 var2 | - self createChange: FamixUnchangedChange with: (self baseEntityNamed: 'Smalltalk::A3diff.c3()') and: (self targetEntityNamed: 'Smalltalk::A3diff.c3()'). "creating fake accesses because maching of variables depends on them - First we don't create enough accesses (need at least 1)" + self + createChange: FamixUnchangedChange + with: (self baseEntityNamed: 'Smalltalk::A3diff.c3()') + and: (self targetEntityNamed: 'Smalltalk::A3diff.c3()'). + var1 := self baseEntityNamed: 'Smalltalk::A3diff.c3().toto'. var2 := self targetEntityNamed: 'Smalltalk::A3diff.c3().var2'. - self deny: (var1 renameMatch: var2 resolver: self resolver). - self deny: (var2 renameMatch: var1 resolver: self resolver). "now create one more access" FamixStAccess new variable: var1; @@ -80,6 +77,25 @@ FamixDiffEntitiesRenameTest >> testRenameMatchVariable [ FamixStAccess new variable: var2; accessor: (self targetEntityNamed: 'Smalltalk::A3diff.b3()'). - self assert: (var1 renameMatch: var2 resolver: self resolver). - self assert: (var2 renameMatch: var1 resolver: self resolver) + + self assertRenameMatch: var1 to: var2. + self assertRenameMatch: var2 to: var1 +] + +{ #category : #tests } +FamixDiffEntitiesRenameTest >> testRenameMatchVariableNoMatch [ + "RnameMatching of variables depend on accesses + Here there is not enough (need at least 1)" + + | var1 var2 | + self + createChange: FamixUnchangedChange + with: (self baseEntityNamed: 'Smalltalk::A3diff.c3()') + and: (self targetEntityNamed: 'Smalltalk::A3diff.c3()'). + + var1 := self baseEntityNamed: 'Smalltalk::A3diff.c3().toto'. + var2 := self targetEntityNamed: 'Smalltalk::A3diff.c3().var2'. + + self denyRenameMatch: var1 to: var2. + self denyRenameMatch: var2 to: var1 ] diff --git a/src/Famix-Diff-Core-Tests/FamixDiffStubEntitiesRenameTest.class.st b/src/Famix-Diff-Core-Tests/FamixDiffStubEntitiesRenameTest.class.st new file mode 100644 index 0000000..1da0c02 --- /dev/null +++ b/src/Famix-Diff-Core-Tests/FamixDiffStubEntitiesRenameTest.class.st @@ -0,0 +1,61 @@ +Class { + #name : #FamixDiffStubEntitiesRenameTest, + #superclass : #AbstractFamixDiffWithModelTest, + #instVars : [ + 'basP3', + 'tgtP3', + 'basA3', + 'tgtA3', + 'basA3c3', + 'tgtA3c3' + ], + #category : #'Famix-Diff-Core-Tests' +} + +{ #category : #running } +FamixDiffStubEntitiesRenameTest >> setUp [ + + super setUp. + + basP3 := self baseEntityNamed: 'Famix-Diff-TestResource-P2'. + tgtP3 := self targetEntityNamed: 'Famix-Diff-TestResource-P2'. + basA3 := self baseEntityNamed: 'Smalltalk::A3diff'. + tgtA3 := self targetEntityNamed: 'Smalltalk::A3diff'. + basA3c3 := self baseEntityNamed: 'Smalltalk::A3diff.c3()'. + tgtA3c3 := self targetEntityNamed: 'Smalltalk::A3diff.c3()'. +] + +{ #category : #tests } +FamixDiffStubEntitiesRenameTest >> testRenameMatchStubMatching [ + + self createChange: FamixUnchangedChange with: basP3 and: tgtP3. + tgtA3 name: 'X3'. + + self assertRenameMatch: basA3 to: tgtA3 +] + +{ #category : #tests } +FamixDiffStubEntitiesRenameTest >> testRenameMatchStubMethodMatching [ + + self createChange: FamixUnchangedChange with: basA3 and: tgtA3. + basA3 isStub: true. + tgtA3 isStub: true. + tgtA3c3 name: 'x3'. + tgtA3c3 signature: 'x3()'. + + self assertRenameMatch: basA3c3 to: tgtA3c3 +] + +{ #category : #tests } +FamixDiffStubEntitiesRenameTest >> testRenameMatchStubMethodNoMatch [ + + self createChange: FamixUnchangedChange with: basA3 and: tgtA3. + basA3 isStub: true. + tgtA3 isStub: true. + basA3c3 isStub: true. + tgtA3c3 isStub: true. + tgtA3c3 name: 'x3'. + tgtA3c3 signature: 'x3()'. + + self denyRenameMatch: basA3c3 to: tgtA3c3 +] From b9b47f7a2e5bcb7c2dfb257a5bec9795b46398cc Mon Sep 17 00:00:00 2001 From: anquetil Date: Tue, 29 Oct 2024 17:25:58 +0100 Subject: [PATCH 09/12] More test refactor: FamixDiffResultTest , FamixDiffTest --- .../FamixDiffResultTest.class.st | 19 +++-- .../FamixDiffTest.class.st | 69 ++++++++++++------- 2 files changed, 58 insertions(+), 30 deletions(-) diff --git a/src/Famix-Diff-Core-Tests/FamixDiffResultTest.class.st b/src/Famix-Diff-Core-Tests/FamixDiffResultTest.class.st index dc8b4f1..f9166c8 100644 --- a/src/Famix-Diff-Core-Tests/FamixDiffResultTest.class.st +++ b/src/Famix-Diff-Core-Tests/FamixDiffResultTest.class.st @@ -25,8 +25,10 @@ FamixDiffResultTest >> testAdditions [ | additions | additions := result additions. + self assert: additions size equals: 5. - additions do: [ :change | self assert: change isAddition ]. + additions do: [ :change | + self assert: change isAddition ]. self assert: additions class equals: result class ] @@ -45,8 +47,10 @@ FamixDiffResultTest >> testMoves [ | moves | moves := result moves. + self assert: moves size equals: 0. - moves do: [ :change | self assert: change isMove ]. + moves do: [ :change | + self assert: change isMove ]. self assert: moves class equals: result class ] @@ -55,8 +59,10 @@ FamixDiffResultTest >> testRemovals [ | removals | removals := result removals. + self assert: removals size equals: 11. - removals do: [ :change | self assert: change isRemoval ]. + removals do: [ :change | + self assert: change isRemoval ]. self assert: removals class equals: result class ] @@ -65,8 +71,10 @@ FamixDiffResultTest >> testRenames [ | moves | moves := result renames. + self assert: moves size equals: 0. - moves do: [ :change | self assert: change isRename ]. + moves do: [ :change | + self assert: change isRename ]. self assert: moves class equals: result class ] @@ -76,9 +84,10 @@ FamixDiffResultTest >> testWithoutStubs [ | withoutStubs | self assert: (result anySatisfy: [ :change | change entity isStub ]). + "We want a new collection, not to update the original one." withoutStubs := result withoutStubs. - self deny: result identicalTo: withoutStubs. "We want a new collection, not to update the original one." + self deny: result identicalTo: withoutStubs. self assert: (withoutStubs noneSatisfy: [ :change | change entity isStub ]). self assert: withoutStubs class equals: result class ] diff --git a/src/Famix-Diff-Core-Tests/FamixDiffTest.class.st b/src/Famix-Diff-Core-Tests/FamixDiffTest.class.st index 3f829ee..b43fbc8 100644 --- a/src/Famix-Diff-Core-Tests/FamixDiffTest.class.st +++ b/src/Famix-Diff-Core-Tests/FamixDiffTest.class.st @@ -8,6 +8,13 @@ Class { #category : #'Famix-Diff-Core-Tests' } +{ #category : #running } +FamixDiffTest >> changes: aCollection ofType: aClass [ + + ^aCollection select: [ :change | + change baseEntity isKindOf: aClass ] +] + { #category : #running } FamixDiffTest >> createModelWith: somePackages [ @@ -133,14 +140,17 @@ FamixDiffTest >> testAddedEntities [ self createTestDiffForAdditionsAndRemovalsEdgeCases. addition := result additions. - self assert: (addition select: [ :change | change baseEntity isKindOf: FamixStPackage ]) size equals: 1. - self assert: (addition detect: [ :change | change baseEntity isKindOf: FamixStPackage ]) entity name equals: self packageName3. - self assert: (addition select: [ :change | change baseEntity isKindOf: FamixStClass ]) size equals: 1. - self assert: (addition detect: [ :change | change baseEntity isKindOf: FamixStClass ]) entity name equals: #C3. - self assert: (addition select: [ :change | change baseEntity isKindOf: FamixStMethod ]) size equals: 1. - self assert: (addition detect: [ :change | change baseEntity isKindOf: FamixStMethod ]) entity name equals: #m5. - self assert: (addition select: [ :change | change baseEntity isKindOf: FamixStLocalVariable ]) size equals: 1. - self assert: (addition detect: [ :change | change baseEntity isKindOf: FamixStLocalVariable ]) entity name equals: #temp3 + self assert: (self changes: addition ofType: FamixStPackage) size equals: 1. + self assert: (self changes: addition ofType: FamixStPackage) first entity name equals: self packageName3. + + self assert: (self changes: addition ofType: FamixStClass ) size equals: 1. + self assert: (self changes: addition ofType: FamixStClass ) first entity name equals: #C3. + + self assert: (self changes: addition ofType: FamixStMethod ) size equals: 1. + self assert: (self changes: addition ofType: FamixStMethod ) first entity name equals: #m5. + + self assert: (self changes: addition ofType: FamixStLocalVariable ) size equals: 1. + self assert: (self changes: addition ofType: FamixStLocalVariable ) first entity name equals: #temp3 ] { #category : #tests } @@ -149,6 +159,7 @@ FamixDiffTest >> testDiffAssociations [ baseModel: (self createModelWith: #(#'Famix-Diff-TestResource-P3' #'Famix-Diff-TestResource-P2')); targetModel: (self createModelWith: #(#'Famix-Diff-TestResource-P1' #'Famix-Diff-TestResource-P2')). self runDiff. + self assert: result associationChanges size equals: 6. self assert: (result associationChanges select: [ :c | c isAddition ]) size equals: 2. self assert: (result associationChanges select: [ :c | c isRemoval ]) size equals: 4 @@ -170,6 +181,7 @@ FamixDiffTest >> testDiffEntitiesDelP1 [ snapshot baseModel: (self createModelWith: #( #'Famix-Diff-TestResource-P1' )). snapshot targetModel: MooseModel new. self runDiff. + self assert: result entityChanges size equals: 7. self assert: (result entityChanges select: [ :e | e isRemoval ]) size equals: 7 "Smalltalk P1 A2 B2 + stubs: ProtoObject Object Kernel" ] @@ -180,6 +192,7 @@ FamixDiffTest >> testDiffEntitiesMatchP1 [ snapshot baseModel: (self createModelWith: #( #'Famix-Diff-TestResource-P1' )). snapshot targetModel: (self createModelWith: #( #'Famix-Diff-TestResource-P1' )). self runDiff. + self assert: result entityChanges size equals: 7. "because in the old version result were duplicated" self assert: (result entityChanges select: [ :e | e isMatch ]) asSet size equals: 7 ] @@ -210,9 +223,9 @@ FamixDiffTest >> testMakeChangeWith [ name: 'A'; yourself. change := FamixAddChange entity: entity. - self - assert: change class equals: FamixAddChange; - assert: change entity equals: entity + + self assert: change class equals: FamixAddChange. + self assert: change entity equals: entity ] { #category : #'tests-run-entities' } @@ -226,10 +239,10 @@ FamixDiffTest >> testMakeChangeWithWith [ name: 'B'; yourself. change := FamixRenameChange base: entityA target: entityB. - self - assert: change class equals: FamixRenameChange; - assert: change baseEntity equals: entityA; - assert: change targetEntity equals: entityB + + self assert: change class equals: FamixRenameChange. + self assert: change baseEntity equals: entityA. + self assert: change targetEntity equals: entityB ] { #category : #'tests-run-entities' } @@ -237,8 +250,11 @@ FamixDiffTest >> testMatched [ | entity | entity := FamixStNamedEntity new. + self deny: (snapshot resolver matched: entity). + snapshot resolver changesDico at: entity put: FamixMoveChange new. + self assert: (snapshot resolver matched: entity) ] @@ -249,10 +265,10 @@ FamixDiffTest >> testMovedEntities [ self createTestDiffForAdditionsAndRemovalsEdgeCases. moves := result moves. - self assertEmpty: (moves select: [ :change | change baseEntity isKindOf: FamixStPackage ]). - self assertEmpty: (moves select: [ :change | change baseEntity isKindOf: FamixStClass ]). - self assert: (moves select: [ :change | change baseEntity isKindOf: FamixStMethod ]) size equals: 2. - self assertEmpty: (moves select: [ :change | change baseEntity isKindOf: FamixStLocalVariable ]) + self assertEmpty: (self changes: moves ofType: FamixStPackage). + self assertEmpty: (self changes: moves ofType: FamixStClass). + self assert: (self changes: moves ofType: FamixStMethod) size equals: 2. + self assertEmpty: (self changes: moves ofType: FamixStLocalVariable) ] { #category : #tests } @@ -262,11 +278,14 @@ FamixDiffTest >> testRemovedEntities [ self createTestDiffForAdditionsAndRemovalsEdgeCases. removals := result removals. - self assert: (removals select: [ :change | change baseEntity isKindOf: FamixStPackage ]) size equals: 1. - self assert: (removals detect: [ :change | change baseEntity isKindOf: FamixStPackage ]) entity name equals: self packageName1. - self assert: (removals select: [ :change | change baseEntity isKindOf: FamixStClass ]) size equals: 1. - self assert: (removals detect: [ :change | change baseEntity isKindOf: FamixStClass ]) entity name equals: #C1. - self assert: (removals select: [ :change | change baseEntity isKindOf: FamixStMethod ]) size equals: 1. - self assert: (removals detect: [ :change | change baseEntity isKindOf: FamixStMethod ]) entity name equals: #m1. + self assert: (self changes: removals ofType: FamixStPackage) size equals: 1. + self assert: (self changes: removals ofType: FamixStPackage) first entity name equals: self packageName1. + + self assert: (self changes: removals ofType: FamixStClass) size equals: 1. + self assert: (self changes: removals ofType: FamixStClass) first entity name equals: #C1. + + self assert: (self changes: removals ofType: FamixStMethod) size equals: 1. + self assert: (self changes: removals ofType: FamixStMethod) first entity name equals: #m1. + self assertEmpty: (removals select: [ :change | change baseEntity isKindOf: FamixStLocalVariable ]) ] From c3049cb1b8aeceb892ecb6bcc26e594c81c484f1 Mon Sep 17 00:00:00 2001 From: anquetil Date: Tue, 29 Oct 2024 17:53:26 +0100 Subject: [PATCH 10/12] "RenameChange" on comments (with test) --- .../FamixDiffEntitiesRenameTest.class.st | 46 +++++++++++++++++++ .../FamixTComment.extension.st | 27 +++++++++++ .../TEntityMetaLevelDependency.extension.st | 6 +-- 3 files changed, 76 insertions(+), 3 deletions(-) diff --git a/src/Famix-Diff-Core-Tests/FamixDiffEntitiesRenameTest.class.st b/src/Famix-Diff-Core-Tests/FamixDiffEntitiesRenameTest.class.st index f75d480..0df839c 100644 --- a/src/Famix-Diff-Core-Tests/FamixDiffEntitiesRenameTest.class.st +++ b/src/Famix-Diff-Core-Tests/FamixDiffEntitiesRenameTest.class.st @@ -21,6 +21,52 @@ FamixDiffEntitiesRenameTest >> testRenameMatchClass [ to: (self baseEntityNamed: 'Smalltalk::A3diff') ] +{ #category : #tests } +FamixDiffEntitiesRenameTest >> testRenameMatchCommentMatching [ + + | baseCmt targetCmt | + baseCmt := FamixStComment new + content: 'This is a comments'; + commentedEntity: (self baseEntityNamed: 'Smalltalk::B3diff.c3()'); + yourself. + targetCmt := FamixStComment new + content: 'This is a comment'; + commentedEntity: (self targetEntityNamed: 'Smalltalk::B3diff.c3()'); + yourself. + + self + createChange: FamixUnchangedChange + with: (self baseEntityNamed: 'Smalltalk::B3diff.c3()') + and: (self targetEntityNamed: 'Smalltalk::B3diff.c3()'). + + self assertRenameMatch: baseCmt to: targetCmt. + self assertRenameMatch: targetCmt to: baseCmt +] + +{ #category : #tests } +FamixDiffEntitiesRenameTest >> testRenameMatchCommentNoMatch [ + "too much difference to be accepted (6 differences on a longer length of 22) + 6 / 22 = 0.27 (default tolerance is 0.20)" + + | baseCmt targetCmt | + baseCmt := FamixStComment new + content: 'This is a comment'; + commentedEntity: (self baseEntityNamed: 'Smalltalk::B3diff.c3()'); + yourself. + targetCmt := FamixStComment new + content: 'This is also another comment'; + commentedEntity: (self targetEntityNamed: 'Smalltalk::B3diff.c3()'); + yourself. + + self + createChange: FamixUnchangedChange + with: (self baseEntityNamed: 'Smalltalk::B3diff.c3()') + and: (self targetEntityNamed: 'Smalltalk::B3diff.c3()'). + + self denyRenameMatch: baseCmt to: targetCmt. + self denyRenameMatch: targetCmt to: baseCmt +] + { #category : #tests } FamixDiffEntitiesRenameTest >> testRenameMatchMethod [ diff --git a/src/Famix-Diff-Core/FamixTComment.extension.st b/src/Famix-Diff-Core/FamixTComment.extension.st index 1429724..302f36e 100644 --- a/src/Famix-Diff-Core/FamixTComment.extension.st +++ b/src/Famix-Diff-Core/FamixTComment.extension.st @@ -9,9 +9,36 @@ FamixTComment >> isIdenticalTo: otherEntity resolver: resolver [ ^ true ] +{ #category : #'*Famix-Diff-Core' } +FamixTComment >> isRenameOf: otherEntity resolver: resolver [ + "using Pharo diff to compute differences + percentage of differences (compared to max size) must be less that `resolver tolerance` " + + | diffs sizeMax | + diffs := DiffBuilder new + diffFrom: self content + to: otherEntity content. + + sizeMax := (self content size) max: (otherEntity content size). + + ^(diffs size / sizeMax) asFloat <= (resolver tolerance) +] + { #category : #'*Famix-Diff-Core' } FamixTComment >> moveMatch: otherEntity resolver: resolver [ "Comments are never moved" ^false ] + +{ #category : #'*Famix-Diff-Core' } +FamixTComment >> renameMatch: otherEntity resolver: resolver [ + "we consider a 'RenameMatch' between 2 comments if there is 'not too much' differences in their texts" + + ((otherEntity usesFamixTrait: FamixTComment) and: + [ self content ~= otherEntity content ]) + ifFalse: [ ^ false ]. + + "See comment in #identityMatch:resolver: to understand what we are doing here" + ^self isRenameOf: otherEntity resolver: resolver +] diff --git a/src/Famix-Diff-Core/TEntityMetaLevelDependency.extension.st b/src/Famix-Diff-Core/TEntityMetaLevelDependency.extension.st index 8d28b8a..f422048 100644 --- a/src/Famix-Diff-Core/TEntityMetaLevelDependency.extension.st +++ b/src/Famix-Diff-Core/TEntityMetaLevelDependency.extension.st @@ -170,9 +170,9 @@ TEntityMetaLevelDependency >> renameMatch: otherEntity resolver: resolver [ (self isNamedEntity and: [ self name ~= otherEntity name ]) ifFalse: [ ^ false ]. "See comment in #identityMatch:resolver: to understand what we are doing here" - ^ [ self isRenamedOf: otherEntity resolver: resolver ] + ^ [ self isRenameOf: otherEntity resolver: resolver ] on: MessageNotUnderstood do: [ - self generateMethodNamed: #isRenamedOf:resolver: basedOnPragmaName: #rename. - self isRenamedOf: otherEntity resolver: resolver ] + self generateMethodNamed: #isRenameOf:resolver: basedOnPragmaName: #rename. + self isRenameOf: otherEntity resolver: resolver ] ] From d759fe9579e458f535a86882247c03ac9ec8d8a5 Mon Sep 17 00:00:00 2001 From: anquetil Date: Tue, 29 Oct 2024 18:01:24 +0100 Subject: [PATCH 11/12] Allowing diff on FamixTComments --- src/Famix-Diff-Core/FamixTComment.extension.st | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/Famix-Diff-Core/FamixTComment.extension.st b/src/Famix-Diff-Core/FamixTComment.extension.st index 302f36e..6dd7275 100644 --- a/src/Famix-Diff-Core/FamixTComment.extension.st +++ b/src/Famix-Diff-Core/FamixTComment.extension.st @@ -42,3 +42,8 @@ FamixTComment >> renameMatch: otherEntity resolver: resolver [ "See comment in #identityMatch:resolver: to understand what we are doing here" ^self isRenameOf: otherEntity resolver: resolver ] + +{ #category : #'*Famix-Diff-Core' } +FamixTComment >> shouldBeConsideredForDiff [ + ^ true +] From a7405e9864f8ef79b6ccc36718fb0cab028fbe08 Mon Sep 17 00:00:00 2001 From: anquetil Date: Tue, 29 Oct 2024 18:15:17 +0100 Subject: [PATCH 12/12] Corrected failing tests --- .../FamixDiffResultTest.class.st | 2 +- .../FamixDiffTest.class.st | 21 ++++++++++--------- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/src/Famix-Diff-Core-Tests/FamixDiffResultTest.class.st b/src/Famix-Diff-Core-Tests/FamixDiffResultTest.class.st index f9166c8..a56b863 100644 --- a/src/Famix-Diff-Core-Tests/FamixDiffResultTest.class.st +++ b/src/Famix-Diff-Core-Tests/FamixDiffResultTest.class.st @@ -60,7 +60,7 @@ FamixDiffResultTest >> testRemovals [ | removals | removals := result removals. - self assert: removals size equals: 11. + self assert: removals size equals: 12. removals do: [ :change | self assert: change isRemoval ]. self assert: removals class equals: result class diff --git a/src/Famix-Diff-Core-Tests/FamixDiffTest.class.st b/src/Famix-Diff-Core-Tests/FamixDiffTest.class.st index b43fbc8..efe7ef4 100644 --- a/src/Famix-Diff-Core-Tests/FamixDiffTest.class.st +++ b/src/Famix-Diff-Core-Tests/FamixDiffTest.class.st @@ -171,8 +171,8 @@ FamixDiffTest >> testDiffEntitiesAddP1 [ snapshot baseModel: MooseModel new. snapshot targetModel: (self createModelWith: #( #'Famix-Diff-TestResource-P1' )). self runDiff. - self assert: result entityChanges size equals: 7. - self assert: (result entityChanges select: [ :e | e isAddition ]) size equals: 7 "Smalltalk P1 A2 B2 + stubs: ProtoObject Object Kernel" + self assert: result entityChanges size equals: 9. + self assert: (result entityChanges select: [ :e | e isAddition ]) size equals: 9 "Smalltalk P1 A2 B2 + stubs: ProtoObject Object Kernel + 2 comments" ] { #category : #tests } @@ -182,8 +182,8 @@ FamixDiffTest >> testDiffEntitiesDelP1 [ snapshot targetModel: MooseModel new. self runDiff. - self assert: result entityChanges size equals: 7. - self assert: (result entityChanges select: [ :e | e isRemoval ]) size equals: 7 "Smalltalk P1 A2 B2 + stubs: ProtoObject Object Kernel" + self assert: result entityChanges size equals: 9. + self assert: (result entityChanges select: [ :e | e isRemoval ]) size equals: 9 "Smalltalk P1 A2 B2 + stubs: ProtoObject Object Kernel + 2 comments" ] { #category : #tests } @@ -193,8 +193,8 @@ FamixDiffTest >> testDiffEntitiesMatchP1 [ snapshot targetModel: (self createModelWith: #( #'Famix-Diff-TestResource-P1' )). self runDiff. - self assert: result entityChanges size equals: 7. "because in the old version result were duplicated" - self assert: (result entityChanges select: [ :e | e isMatch ]) asSet size equals: 7 + self assert: result entityChanges size equals: 9. + self assert: (result entityChanges select: [ :e | e isMatch ]) asSet size equals: 9 ] { #category : #tests } @@ -203,16 +203,17 @@ FamixDiffTest >> testDiffEntitiesP1P2P3 [ snapshot baseModel: (self createModelWith: #( #'Famix-Diff-TestResource-P2' #'Famix-Diff-TestResource-P3' )). snapshot targetModel: (self createModelWith: #( #'Famix-Diff-TestResource-P1' #'Famix-Diff-TestResource-P2' )). self runDiff. - self assert: result entityChanges size equals: 38. + self assert: result entityChanges size equals: 44. self assert: (result entityChanges select: [ :e | e isAddition ]) size equals: 3. "P2 A2diff B2diff" - self assert: (result entityChanges select: [ :e | e isRemoval ]) size equals: 7. "P4 A4diff A4diff.att1 A4diff.b3() B4diff + annotations" - self assert: (result entityChanges select: [ :e | e isMatch ]) size equals: 12 + 4 + 4 + 5 + 2 + 1. + self assert: (result entityChanges select: [ :e | e isRemoval ]) size equals: 8. "P4 A4diff A4diff.att1 A4diff.b3() B4diff + annotations + 1 comment" + self assert: (result entityChanges select: [ :e | e isMatch and: [ e baseEntity isKindOf: FamixStLocalVariable ] ]) size equals: 12. self assert: (result entityChanges select: [ :e | e isMatch and: [ e baseEntity isKindOf: FamixStAttribute ] ]) size equals: 4. "A3.att1 A3.att2 B3.att1 B3.att2" self assert: (result entityChanges select: [ :e | e isMatch and: [ e baseEntity isKindOf: FamixStMethod ] ]) size equals: 4. "A3.b2 A3.c3 B3.c3" self assert: (result entityChanges select: [ :e | e isMatch and: [ e baseEntity isKindOf: FamixStClass ] ]) size equals: 5. "A3 B3 C3 Object ProtoObject" self assert: (result entityChanges select: [ :e | e isMatch and: [ e baseEntity isKindOf: FamixStPackage ] ]) size equals: 2. "P3 Kernel" - self assert: (result entityChanges select: [ :e | e isMatch and: [ e baseEntity isKindOf: FamixStNamespace ] ]) size equals: 1 "Smalltalk" + self assert: (result entityChanges select: [ :e | e isMatch and: [ e baseEntity isKindOf: FamixStNamespace ] ]) size equals: 1. "Smalltalk" + self assert: (result entityChanges select: [ :e | e isMatch and: [ e baseEntity isKindOf: FamixStComment ] ]) size equals: 5 ] { #category : #'tests-run-entities' }