Pharo test defects

RGMCClassTest

State
Fixed (image fix)
Defect in
the Pharo image
Tests
1
Fix
image fix 20-RGMCClassTest.st
Upstream repository
pharo-project/pharo

Record

The test skipped itself on a 2018 FogBugz issue. With the skip removed it failed on both VMs for two reasons, both defects in the image (test and Ring-Monticello code). (1) RGMCTest>>testClass: compared the slots of the Ring definition with aClass instVarNames, which includes slots a trait provides. Monticello exports only the local slots (Class>>asClassDefinition uses localSlots), so the test now compares with localSlots, on the instance side and the class side. (2) MCClassDefinition>>ensureRingDefinitionIn: kept the '#' in the name of a plain variable when the class also has complex slots. Monticello writes such a variable as '#y', so ObservablePoint gave the slot name #'#y' and a class-side '#customExtent' gave #'#customExtent'. The method now strips '#' for both instance and class-side plain variables. The skip is removed from the test. Only the fixed image was run; the fix does not change VM behaviour.

Test Defect in State Cause
RGMCClassTest>>testClassesWithTraits image-code repaired Skip on an old issue; then the test compared the Ring slots with instVarNames (which includes trait slots) instead of localSlots; and MCClassDefinition>>ensureRingDefinitionIn: kept '#' in plain variable names of classes with complex slots.

Regression check: I ran these classes on our VM and on Cog, once on the base image and once on the fixed image. The pass counts are the same before and after on both VMs. RGMCClassTest went from 3 pass and 1 skip to 4 pass. MCClassDefinitionTest 13, MCStWriterTest 9, RGMonticelloTest 4, TraitMCDefinitionsTest 16 and MCSnapshotTest 5 all passed everywhere. RGMCTest has no test methods, so it printed no result lines. I did not run the full suite. I ran our VM only with the JIT setting that the "ours" runner selects.

Upstream note: Pharo: fix RGMCClassTest>>testClassesWithTraits and the Ring-Monticello slot names. Remove the skip for issue 22080. In RGMCTest>>testClass:, compare the Ring slots with the local slots of the class (aClass localSlots), because Monticello exports only the local slots and not the ones from traits. In MCClassDefinition>>ensureRingDefinitionIn:, strip the '#' from the name of a plain instance or class-side variable in a class with complex slots (MC writes such a variable as '#y'). Without this fix ObservablePoint gives the slot name #'#y'. Project: pharo (Ring-Monticello and Ring-Monticello-Tests).

Results

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.

TestBeforeStateiospharo VMPatched CogStock Cog
RGMCClassTest>>testClassesWithTraitsSKIPrepairedPASSPASSPASS 3 of 3 (repair run)

Test

Run the tests in a Pharo 14 image (build 791). Before the fix they skip, fail or carry the expected-failure mark.

"Run in a Playground of a Pharo 14 image (Do it and print each line)."
((RGMCClassTest selector: #testClassesWithTraits) run) printString.

Source of the tests before the fix

RGMCClassTest>>testClassesWithTraits before the fix (Pharo 14 build 791)
testClassesWithTraits

	"classes without special slots"

	self skip.
	"skip because of https://pharo.fogbugz.com/f/cases/22080/Monticello-wrongly-resolves-names-for-instance-variables-in-classes-that-contain-slots"

	Smalltalk allClasses
		select: [ :each | each isTrait not and: [each traits notEmpty or: [ each class traits notEmpty ]] ]
		thenDo: [ :each | self testClass: each ]

Fix

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.

20-RGMCClassTest.st (download)
fix value: #RGMCClassTest value: #testClassesWithTraits value: [ :s | s includesSubstring: 'self skip' ] value: 'testClassesWithTraits

	"classes with traits"

	Smalltalk allClasses
		select: [ :each | each isTrait not and: [each traits notEmpty or: [ each class traits notEmpty ]] ]
		thenDo: [ :each | self testClass: each ]'.

"The MC class definition stores only the slots a class defines itself (localSlots); slots that
 a trait provides are not part of it.  The test compared with instVarNames, which includes the
 slots from traits.  Compare with the local slots, as asClassDefinition exports them."
fix value: #RGMCTest value: #testClass: value: [ :s | s includesSubstring: 'equals: aClass instVarNames' ] value: 'testClass: aClass

	| mcDef def env|
	mcDef := 	aClass asClassDefinition.
	def := mcDef asRGDefinition.
	env := def environment.

	self assert: def name equals: aClass name.
	aClass superclass ifNotNil: [ "ProtoObject & co."
		self assert: def superclass name equals: aClass superclass name.].
	self assert: def category equals: aClass category.
	self assert: def layout class equals: (self layoutClassesMapping at: aClass classLayout class).

	def layout isPointerLayout ifTrue: [
		"Monticello keeps only the slots the class defines itself, not the ones from its traits"
		self assert: (def layout slots collect: [:each | each name]) asArray equals: (aClass localSlots collect: [:each | each name]) asArray.].
	self assert: (def metaclass layout slots collect: [:each | each name]) asArray equals: (aClass class localSlots collect: [:each | each name]) asArray.
	self assert: (def classVariables collect: [:each | each name]) equals: aClass classVarNames.
	self assert: (def sharedPoolNames asArray) equals: aClass sharedPoolNames asArray.

	"Monticello class definition still use only class categories, packages are unresolved"
	self assert: (def hasUnresolved: #package).
	self assert: (def hasResolved: #traitComposition).
	self compareTraitComposition: aClass traitComposition with: def traitComposition.
	self compareTraitComposition: aClass class traitComposition with: def metaclass traitComposition'.

"In a class with complex slots Monticello exports a plain variable as #y; the Ring definition kept the # in the slot name, for instance and class-side variables."
fix value: #MCClassDefinition value: #ensureRingDefinitionIn: value: [ :s | (s includesSubstring: 'RGInstanceVariableSlot named: each name parent: def layout') ] value: 'ensureRingDefinitionIn: anRGEnvironment

	^ anRGEnvironment backend definitionFor: self ifAbsentRegister: [
		| def metaclassDef |
		def := anRGEnvironment ensureClassNamed: self className asSymbol.
		metaclassDef := anRGEnvironment ensureClassNamed: (self className, '' class'') asSymbol.
		def metaclass: metaclassDef.
		def traitComposition: (self traitCompositionFrom: self traitComposition parent: def).
		metaclassDef traitComposition: (self traitCompositionFrom: self classTraitComposition parent: metaclassDef).
		(self superclassName = #nil)
			ifTrue: [ def superclass: def ]
			ifFalse: [ def superclass: (anRGEnvironment ensureClassNamed: superclassName ) ].
		def category: self category.
		def layout: (self ring2LayoutType parent: def).
		metaclassDef layout: (RGFixedLayout parent: metaclassDef).
		def comment: (
			(RGComment parent: def)
				content: self comment;
				author: (self authorForStamp: self commentStamp);
				time: (self timeForStamp: self commentStamp);
				yourself).
		self variables do: [ :each |
			(each class type = #instance) ifTrue: [
				(each name includes: $>)
					ifFalse: [ def layout addSlot: (RGInstanceVariableSlot named: (each name copyWithout: $#) trimBoth parent: def layout)]
					ifTrue: [
						| unknownSlot |
						unknownSlot := RGUnknownSlot named: ((each name copyUpTo: $=) copyWithout: $#) trimBoth parent: def layout.
						unknownSlot expression: (each name copyAfter: $>) trimBoth.
						def layout addSlot: unknownSlot]].
			(each class type = #class) ifTrue: [
				def addClassVariable: (RGClassVariable named: each name parent: def)].
			(each class type = #classInstance) ifTrue: [
				metaclassDef layout addSlot: (RGInstanceVariableSlot named: (each name copyWithout: $#) trimBoth parent: metaclassDef layout)].
			(each class type = #pool) ifTrue: [
				def addSharedPool: (RGPoolVariable named: each name parent: def)]. ].
		def]'.

State of 2026-11-20. Made from the test records of the iospharo project (a second Pharo VM). The fixes are proposals for review.