scripts/image-fixes/31-rename-class-changes.stRBNamespace>>renameClass:to:around:,
RBTransformationsTest>>testRenameClassTransform,
ReRenameClassCommandTest>>testRenameClassCommandSuccessThe method adds the rename change to the changes of the namespace and
keeps the old value of changes. Then the method runs the block and puts
the old value back. The method never makes the rename change the current
changes. The sibling method
perform:onlyWithChange: has the line changes := aCompositeRefactoryChange
at that place. Without the line, the method changes that the block records
are siblings of the rename change and not its parts.
ReRenameClassChange>>executeNotifying: gives the new class name only to
its parts. A sibling keeps the old name, and ReClassChange>>changeClass
answers nil for that name after the rename.
The repair adds the line changes := change.
Two tests of the image count the changes of a class rename at the top level of the model (11 and 7). The counts are the rename change and the method changes as its siblings, which is the defect. A first sweep with the repair showed the two tests ("Got 1 instead of 11", "Got 1 instead of 7"). The two tests now check that the model has one change, and that the rename change has the method changes as its parts (10 and 6).
| Test | Defect in | State | Cause |
|---|---|---|---|
ChanelTestCaseNameCleanerTest>>testRenameTestCaseEndingWithTestsUpdateReferences (package Chanel) |
image code | repaired | The method changes of a class rename kept the old class name. |
RBTransformationsTest>>testRenameClassTransform |
test | repaired | The expected count was the count of the defect. |
ReRenameClassCommandTest>>testRenameClassCommandSuccess |
test | repaired | The expected count was the count of the defect. |
No test of the image shows the defect. The test is in the package
jecisc/Chanel (row 13 of the package run): it failed on stock Cog and on
our VM with receiver of "includesSelector:" is nil, and it passes on the
two VMs with the repair.
Last full sweeps of 2026-11-17: iospharo (sweep14-new14) and stock Cog with the Cog changes (sweepcogp14-new10), with all image fixes. "Before" is the state of the test before the repairs. The Stock Cog column has a value only where the record measured stock Cog: "PASS 3 of 3 (repair run)" is the check of each repair on stock Cog v12.0.6 with the fix entry; "-" is not measured separately.
| Test | Before | State | iospharo VM | Patched Cog | Stock Cog |
|---|---|---|---|---|---|
ChanelTestCaseNameCleanerTest>>testRenameTestCaseEndingWithTestsUpdateReferences | repaired | not run | not run | - | |
RBTransformationsTest>>testRenameClassTransform | repaired | PASS | PASS | - | |
ReRenameClassCommandTest>>testRenameClassCommandSuccess | repaired | PASS | PASS | - |
Run the tests in a Pharo 14 image (build 791). Some of these tests are new: the entries file adds them, so file in the entries file first, then run them. These classes are not in the Pharo image but in a package (see the record): ChanelTestCaseNameCleanerTest.
"Run in a Playground of a Pharo 14 image (Do it and print each line)." ((ChanelTestCaseNameCleanerTest selector: #testRenameTestCaseEndingWithTestsUpdateReferences) run) printString. ((RBTransformationsTest selector: #testRenameClassTransform) run) printString. ((ReRenameClassCommandTest selector: #testRenameClassCommandSuccess) run) printString.
testRenameClassTransform | transformation class newClassName oldClassName | newClassName := #RBNewDummyClassName. oldClassName := RBClassToRename name asSymbol. transformation := ReRenameClassRefactoring rename: oldClassName to: newClassName. transformation generateChanges. self assert: transformation model changes changes size equals: 11. class := transformation model classNamed: newClassName. self assert: (class parseTreeForSelector: #method1) equals: (self parseMethod: 'method1 ^ self method2'). self deny: (transformation model includesClassNamed: oldClassName). class := transformation model classNamed: RBSubclassOfClassToRename name asSymbol. self assert: class superclass equals: (transformation model classNamed: 'RBNewDummyClassName' asSymbol). self assert: (class parseTreeForSelector: #symbolReference) equals: (self parseMethod: 'symbolReference ^ #RBNewDummyClassName'). self assert: (class parseTreeForSelector: #reference) equals: (self parseMethod: 'reference ^ RBNewDummyClassName new')
testRenameClassCommandSuccess | driver command context dialogMock | command := StRenameClassCommand new. context := StCommandContextMock new name: #ReClassToConvertTemporaryToInstanceVariable. command context: context. driver := command prepareDriver. dialogMock := StRequestDialogMock new. dialogMock response: 'NewClassNameForTest'. driver requestDialog: dialogMock. driver forTesting: true; runRefactoring. self assert: driver changes changes size equals: 7.
How to apply an entries file: file in 00-header.st and the entries file as one chunk (the iospharo script scripts/gen-image-fixes.py makes that chunk). Each entry checks for the defect first and prints FIXED, ADDED or SKIP. Download 00-header.st.
"Refactoring-Core: a rename of a class loses the changes of its methods (2026-11-17). Found by the package run: Chanel, ChanelTestCaseNameCleanerTest>>testRenameTestCaseEndingWithTestsUpdateReferences (MessageNotUnderstood: receiver of includesSelector: is nil, in ReAddMethodChange>>asUndoOperation). The same on stock Cog and on our VM. RBNamespace>>renameClass:to:around: adds the rename change to the changes of the namespace, keeps the old value of 'changes', runs the block, and puts the old value back. The method never makes the rename change the current 'changes', so the code that puts the old value back has no effect. The sibling method perform:onlyWithChange: has the line 'changes := aCompositeRefactoryChange' at that place. Without the line, the method changes that the block records (the methods of the class that refer to its own name) are siblings of the rename change and not its parts. ReRenameClassChange>>executeNotifying: gives the new class name only to its parts. A sibling keeps the old name, and ReClassChange>>changeClass answers nil for that name after the rename. The repair adds the line. The guard is the Pharo 14 form of the method with no such line. Two tests of the image count the changes of a class rename at the top level of the model: RBTransformationsTest>>testRenameClassTransform (11) and ReRenameClassCommandTest>>testRenameClassCommandSuccess (7). The counts are the rename change and the method changes as its siblings, which is the defect. ReRenameClassChange>>executeNotifying: runs the parts of the rename change with the new class name, so the parts are where the method changes belong. With the repair the model has one change, the rename change, and the method changes are its parts (10 and 6). The two tests now check the two numbers." fix value: #RBNamespace value: #renameClass:to:around: value: [ :source | (source includesSubstring: 'oldChanges := changes.') and: [ (source includesSubstring: 'changes := change.') not ] ] value: 'renameClass: aRBClass to: aSymbol around: aBlock | change value dict oldChanges | change := changeFactory renameClass: aRBClass to: aSymbol. changes addChange: change. oldChanges := changes. "The changes that the block records are parts of the rename change, as in perform:onlyWithChange:. The rename then gives them the new class name." changes := change. aBlock ensure: [ changes := oldChanges ]. self flushCaches. dict := (newClasses includesKey: aRBClass name) ifTrue: [ newClasses ] ifFalse: [ changedClasses ]. self markAsRemoved: aRBClass name. self unmarkAsRemoved: aSymbol. value := dict at: aRBClass name. dict removeKey: aRBClass name. dict at: aSymbol put: value. value first name: aSymbol. value last name: aSymbol. value first subclasses do: [ :each | each superclass: value first ]. value last subclasses do: [ :each | each superclass: value last ]. ^ change'. fix value: #RBTransformationsTest value: #testRenameClassTransform value: [ :source | source includesSubstring: 'transformation model changes changes size equals: 11.' ] value: ((RBTransformationsTest >> #testRenameClassTransform) sourceCode copyReplaceAll: 'self assert: transformation model changes changes size equals: 11.' with: '"The rename change is the one change of the model. The changes of the methods are its parts, so that the rename gives them the new class name." self assert: transformation model changes changes size equals: 1. self assert: transformation model changes changes first changes size equals: 10.'). fix value: #ReRenameClassCommandTest value: #testRenameClassCommandSuccess value: [ :source | source includesSubstring: 'driver changes changes size equals: 7.' ] value: ((ReRenameClassCommandTest >> #testRenameClassCommandSuccess) sourceCode copyReplaceAll: 'self assert: driver changes changes size equals: 7.' with: '"The rename change is the one change. The changes of the methods are its parts. (One read of the changes: ReInteractionDriver>>changes runs the transformation at each call.)" self assert: (driver changes changes collect: [ :each | each changes size ]) asArray equals: #( 6 ).').
State of 2026-11-20. Made from the test records of the iospharo project (a second Pharo VM). The fixes are proposals for review.