Pharo test defects

ClapHelloTest

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

Record

The test was a placeholder: self skip: 'should probably fail or obey the latest flag'. The previous repair pinned 'shout wins', which the reviewer rejected. This repair takes the reviewer's Option A and repairs the code under test. ClapCommandLineExamples>>shouting and >>whispering used hasFlag:, which cannot tell which flag came last, so voice: always preferred shouting. The Clap match keeps the flags in command line order (ClapCompositeMatch>>children is an OrderedCollection, and ClapCompositeMatch>>flags selects from it in order). A new method ClapCommandLineExamples>>latestVoiceFlag returns the identifier of the last of #shout and #whisper in the last subcommand's flags, and shouting and whispering compare against it. The test now asserts '(hello, world)' for '--shout --whisper', and a new test testHelloBothWhisperingAndShouting asserts 'HELLO, WORLD!' for '--whisper --shout'. Single-flag behaviour is unchanged. No assertion is weakened, and no claim is made that 'shout wins' is the contract.

Test Defect in State Cause
ClapHelloTest>>testHelloBothShoutingAndWhispering image-code repaired The example command could not honour the latest flag because shouting and whispering used hasFlag:, which loses the order of the flags. The test author's own comment asked for failure or obeying the latest flag.

Regression check: Ran all 22 test classes of the Clap-Tests package (ClapApplicationTest through SaveCliCommandTest), plus HermesClapCommandTest and SaveCliCommandTest, on our VM and on Cog, each with the fix image and the base image. The pass counts are identical with and without the fix for every class except ClapHelloTest, which goes from 7 PASS + 1 SKIP to 9 PASS on both VMs. ClapParameterizedTest (7 ERROR) and ClapParameterTest (4 ERROR) produce the same errors on both VMs with and without the fix; I did not investigate them, they are outside this cluster. ClapPharoCommandsTest printed no RT lines in any of the four runs; I did not investigate that, and the class has no test methods of its own that I checked. ClapCommandLineExamples is also used by ClapHelloWorldTest and ClapApplicationTest, which pass 6 of 6 before and after on both VMs.

Upstream note: Title: Clap hello example: the latest of --shout and --whisper wins. Description (Pharo, package Clap-Examples and Clap-Tests): ClapCommandLineExamples>>shouting and >>whispering used hasFlag:, so --shout --whisper always shouted, and ClapHelloTest>>testHelloBothShoutingAndWhispering was skipped with 'should probably fail or obey the latest flag'. The flags of a ClapCompositeMatch are kept in command line order, so a new method latestVoiceFlag finds the last of #shout and #whisper. The skipped test now asserts the whispering output, and a new test covers the opposite order. This is a proposal for the owner to review; it has not been sent anywhere.

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
ClapHelloTest>>testHelloBothShoutingAndWhisperingSKIPrepairedPASSPASSPASS 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)."
((ClapHelloTest selector: #testHelloBothShoutingAndWhispering) run) printString.

Source of the tests before the fix

ClapHelloTest>>testHelloBothShoutingAndWhispering before the fix (Pharo 14 build 791)
testHelloBothShoutingAndWhispering
	context := ClapCommandLineExamples hello activateWith: #('hello' '--shout' '--whisper').
	
	self skip: 'should probably fail or obey the latest flag'

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-ClapHelloTest.st (download)
"ClapHelloTest>>testHelloBothShoutingAndWhispering: the author left self skip: should probably fail or obey the latest flag.  Repair: obey the latest flag.  The Clap match keeps the flags in
 command line order (ClapCompositeMatch children is an OrderedCollection, ClapCompositeMatch>>flags
 selects from it in order), so ClapCommandLineExamples can see which of --shout and --whisper came
 last.  The test keeps its intent: it now asserts the whispering form for --shout --whisper.
 A second test covers the opposite order."
add value: #ClapCommandLineExamples value: #latestVoiceFlag value: 'accessing'
	value: 'latestVoiceFlag
	"The voice flag given last on the command line wins: --shout --whisper whispers, --whisper --shout shouts."
	^ (self context lastSubcommand flags collect: [ :each | each specification identifier ])
		reverse
		detect: [ :id | id = #shout or: [ id = #whisper ] ]
		ifNone: [ nil ]'.
fix value: #ClapCommandLineExamples value: #shouting
	value: [ :src | src includesSubstring: 'hasFlag: #shout' ]
	value: 'shouting
	^ self latestVoiceFlag == #shout'.
fix value: #ClapCommandLineExamples value: #whispering
	value: [ :src | src includesSubstring: 'hasFlag: #whisper' ]
	value: 'whispering
	^ self latestVoiceFlag == #whisper'.
fix value: #ClapHelloTest value: #testHelloBothShoutingAndWhispering
	value: [ :src | src includesSubstring: 'self skip:' ]
	value: 'testHelloBothShoutingAndWhispering
	context := ClapCommandLineExamples hello activateWith: #(''hello'' ''--shout'' ''--whisper'').
	self assertSuccess.
	self
		assert: self outputString
		equals: ''(hello, world)'' , self lineEnding'.
add value: #ClapHelloTest value: #testHelloBothWhisperingAndShouting value: 'tests'
	value: 'testHelloBothWhisperingAndShouting
	context := ClapCommandLineExamples hello activateWith: #(''hello'' ''--whisper'' ''--shout'').
	self assertSuccess.
	self
		assert: self outputString
		equals: ''HELLO, WORLD'' , 33 asCharacter asString , self lineEnding'.

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