Skip to content

Commit

Permalink
Added hook to read and set existing hint, if already exists, so it is…
Browse files Browse the repository at this point in the history
… not overwritten by 'TBD' in re-generation of exercise.
  • Loading branch information
Bajger committed Feb 25, 2025
1 parent a686096 commit 46b3e66
Show file tree
Hide file tree
Showing 19 changed files with 227 additions and 152 deletions.
34 changes: 32 additions & 2 deletions dev/src/ExercismDev/ExercismExerciseGenerator.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ Class {
#instVars : [
'numberGenerated',
'exerciseDirReference',
'existingHint',
'testJson',
'regenerateExisting'
],
Expand Down Expand Up @@ -159,6 +160,18 @@ ExercismExerciseGenerator >> exerciseVariableName [
^ self testNameCamelCased asValidSelector asString
]

{ #category : 'accessing' }
ExercismExerciseGenerator >> existingHint [

^ existingHint ifNil: [ 'TBD' ] ifNotNil: [ existingHint ]
]

{ #category : 'accessing' }
ExercismExerciseGenerator >> existingHint: aString [

existingHint := aString
]

{ #category : 'generation' }
ExercismExerciseGenerator >> generateExerciseCommentFor: testClass [
| comment |
Expand All @@ -168,7 +181,7 @@ ExercismExerciseGenerator >> generateExerciseCommentFor: testClass [
<< '# ' << self testNameCamelCased; cr; cr;
<< self testDescription; cr;
<< '## Hint'; cr; cr;
<< 'TBD'; cr
<< self existingHint; cr
].
"write comment to test class"
testClass comment: comment.
Expand All @@ -190,7 +203,10 @@ ExercismExerciseGenerator >> generateExerciseFrom: aFileSystemReference [

self canOverwriteExisting
ifFalse: [ ^self log: 'exercise test class already exists (skipping).' for: self testClassName ].


"before generating test class, read existing hint, in case of re-generation"
self setupHintFromExistingTestClass.

testClass := self generateTestClass.
self generateSetupFor: testClass.
self generateTestMethodsFor: testClass.
Expand Down Expand Up @@ -403,6 +419,20 @@ ExercismExerciseGenerator >> regenerateExistingExercisesFrom: filePathReference
format: {self numberGenerated})
]

{ #category : 'generation' }
ExercismExerciseGenerator >> setupHintFromExistingTestClass [

|existingClass|

"reset existing hint"
self existingHint: nil.

"do not setup anything, if class do not exist"
existingClass := self class environment at: self testClassName asSymbol ifAbsent: [^ self].

existingClass exercise hintText ifNotEmpty: [:aText | self existingHint: aText ]
]

{ #category : 'internal' }
ExercismExerciseGenerator >> testClassName [

Expand Down
4 changes: 2 additions & 2 deletions dev/src/ExercismTests/DiskStore.extension.st
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Extension { #name : #DiskStore }
Extension { #name : 'DiskStore' }

{ #category : #'*ExercismTests' }
{ #category : '*ExercismTests' }
DiskStore class >> currentFileSystem: fileSystem during: aBlock [
| backupFileSystem |
backupFileSystem := self currentFileSystem.
Expand Down
28 changes: 15 additions & 13 deletions dev/src/ExercismTests/ExercismConfigGeneratorTest.class.st
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
Class {
#name : #ExercismConfigGeneratorTest,
#superclass : #TestCase,
#category : #'ExercismTests-UnitTests'
#name : 'ExercismConfigGeneratorTest',
#superclass : 'TestCase',
#category : 'ExercismTests-UnitTests',
#package : 'ExercismTests',
#tag : 'UnitTests'
}

{ #category : #'set up' }
{ #category : 'set up' }
ExercismConfigGeneratorTest >> modifyHelloWorldDataAtJsonNode: exercisesJsonNode [

|helloWorldJson|
Expand All @@ -13,7 +15,7 @@ ExercismConfigGeneratorTest >> modifyHelloWorldDataAtJsonNode: exercisesJsonNode
helloWorldJson at: 'name' put: 'Hello World 2'.
]

{ #category : #'set up' }
{ #category : 'set up' }
ExercismConfigGeneratorTest >> rewriteAlteredConfigJson: jsonDict atFile: cfgFile [

|outPutJsonString|
Expand All @@ -28,7 +30,7 @@ ExercismConfigGeneratorTest >> rewriteAlteredConfigJson: jsonDict atFile: cfgFil

]

{ #category : #tests }
{ #category : 'tests' }
ExercismConfigGeneratorTest >> testGenerateConfigFrom [

|dirReference cfgFile jsonDict|
Expand All @@ -45,7 +47,7 @@ ExercismConfigGeneratorTest >> testGenerateConfigFrom [

]

{ #category : #tests }
{ #category : 'tests' }
ExercismConfigGeneratorTest >> testGenerateConfigHeader [

|dirReference cfgFile jsonDict|
Expand Down Expand Up @@ -74,7 +76,7 @@ ExercismConfigGeneratorTest >> testGenerateConfigHeader [
self assert: ((jsonDict at: 'test_runner') at: 'average_run_time') equals: 1.
]

{ #category : #tests }
{ #category : 'tests' }
ExercismConfigGeneratorTest >> testGenerateConfigKeyFeatures [

|dirReference cfgFile jsonDict|
Expand All @@ -90,7 +92,7 @@ ExercismConfigGeneratorTest >> testGenerateConfigKeyFeatures [
)
]

{ #category : #tests }
{ #category : 'tests' }
ExercismConfigGeneratorTest >> testGenerateConfigPractiseExercises [

|dirReference jsonDict practiceExercises|
Expand All @@ -110,7 +112,7 @@ ExercismConfigGeneratorTest >> testGenerateConfigPractiseExercises [
self assert: ((practiceExercises first at: #slug) < (practiceExercises second at: #slug)).
]

{ #category : #tests }
{ #category : 'tests' }
ExercismConfigGeneratorTest >> testGenerateConfigTags [

|dirReference cfgFile jsonDict|
Expand Down Expand Up @@ -140,7 +142,7 @@ ExercismConfigGeneratorTest >> testGenerateConfigTags [

]

{ #category : #tests }
{ #category : 'tests' }
ExercismConfigGeneratorTest >> testUpdateConfigFromFor [

|dirReference cfgFile jsonDict hwExericeJson|
Expand All @@ -165,7 +167,7 @@ ExercismConfigGeneratorTest >> testUpdateConfigFromFor [

]

{ #category : #tests }
{ #category : 'tests' }
ExercismConfigGeneratorTest >> testUpdateConfigFromForExerciseDoNotExist [

|dirReference cfgFile |
Expand All @@ -181,7 +183,7 @@ ExercismConfigGeneratorTest >> testUpdateConfigFromForExerciseDoNotExist [
self assert: ex messageText equals: 'Could not find exercise: random-slug343' ].
]

{ #category : #tests }
{ #category : 'tests' }
ExercismConfigGeneratorTest >> testUpdateConfigFromForNewExercise [

|dirReference cfgFile jsonDict alteredCollection|
Expand Down
12 changes: 7 additions & 5 deletions dev/src/ExercismTests/ExercismDownloadCommandTest.class.st
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
Class {
#name : #ExercismDownloadCommandTest,
#superclass : #TestCase,
#category : #'ExercismTests-UnitTests'
#name : 'ExercismDownloadCommandTest',
#superclass : 'TestCase',
#category : 'ExercismTests-UnitTests',
#package : 'ExercismTests',
#tag : 'UnitTests'
}

{ #category : #running }
{ #category : 'running' }
ExercismDownloadCommandTest >> tearDown [
"all known mock mutations should be recovered"
ExercismExercise recoverFromGHMutation.
TonelReader recoverFromGHMutation.
super tearDown
]

{ #category : #tests }
{ #category : 'tests' }
ExercismDownloadCommandTest >> testExecuteDownloading [

| cmd exercise solutionData mockHttpClient mockReader baseUrl sourceCode |
Expand Down
39 changes: 27 additions & 12 deletions dev/src/ExercismTests/ExercismExerciseGeneratorTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@
An ExercismExerciseGeneratorTest is a test class for testing the behavior of ExercismExerciseGenerator
"
Class {
#name : #ExercismExerciseGeneratorTest,
#superclass : #TestCase,
#category : #'ExercismTests-UnitTests'
#name : 'ExercismExerciseGeneratorTest',
#superclass : 'TestCase',
#category : 'ExercismTests-UnitTests',
#package : 'ExercismTests',
#tag : 'UnitTests'
}

{ #category : #setup }
{ #category : 'setup' }
ExercismExerciseGeneratorTest >> canonicalTestSampleJson [
^
'{
Expand Down Expand Up @@ -58,7 +60,7 @@ ExercismExerciseGeneratorTest >> canonicalTestSampleJson [
'
]

{ #category : #setup }
{ #category : 'setup' }
ExercismExerciseGeneratorTest >> createMockExerciseDirectory [
|memFileRef exerciseDir |
memFileRef := FileSystem memory root.
Expand All @@ -80,13 +82,13 @@ ExercismExerciseGeneratorTest >> createMockExerciseDirectory [
^ exerciseDir
]

{ #category : #setup }
{ #category : 'setup' }
ExercismExerciseGeneratorTest >> mockClassName [

^ ('mock-exercise' kebabAsCamelCase, 'Test') asSymbol
]

{ #category : #running }
{ #category : 'running' }
ExercismExerciseGeneratorTest >> tearDown [
"remove mock class if exists"
(self class environment hasClassNamed: self mockClassName) ifTrue: [
Expand All @@ -95,7 +97,7 @@ ExercismExerciseGeneratorTest >> tearDown [
super tearDown
]

{ #category : #tests }
{ #category : 'tests' }
ExercismExerciseGeneratorTest >> testAsValidKeywordOnString [

self assert: '1Direction' asValidKeyword equals: 'and1Direction'.
Expand All @@ -106,7 +108,7 @@ ExercismExerciseGeneratorTest >> testAsValidKeywordOnString [
self assert: 'is <= 5' asValidKeyword equals: 'isLessThanOrEqualTo5'
]

{ #category : #tests }
{ #category : 'tests' }
ExercismExerciseGeneratorTest >> testExerciseVariableName [
|generator|
"set directory reference with canonical description with tests of given exercise"
Expand All @@ -116,7 +118,7 @@ ExercismExerciseGeneratorTest >> testExerciseVariableName [
self assert: generator exerciseVariableName equals: 'mockExercise'.
]

{ #category : #tests }
{ #category : 'tests' }
ExercismExerciseGeneratorTest >> testGenerateExerciseFrom [
|aPackage aClass testSelectors classSelectors|
"run generator"
Expand Down Expand Up @@ -154,7 +156,7 @@ ExercismExerciseGeneratorTest >> testGenerateExerciseFrom [

]

{ #category : #tests }
{ #category : 'tests' }
ExercismExerciseGeneratorTest >> testHasValidTestDecriptions [
|generator|
"set directory reference with canonical description with tests of given exercise"
Expand All @@ -168,7 +170,7 @@ ExercismExerciseGeneratorTest >> testHasValidTestDecriptions [
self deny: generator hasValidTestDecriptions.
]

{ #category : #tests }
{ #category : 'tests' }
ExercismExerciseGeneratorTest >> testPackageNameForTestClass [
|generator|
"set directory reference with canonical description with tests of given exercise"
Expand All @@ -183,3 +185,16 @@ ExercismExerciseGeneratorTest >> testPackageNameForTestClass [
generator regenerateExisting: true.
self assert: generator packageNameForTestClass equals: 'Exercise@MockExercise'.
]

{ #category : 'tests' }
ExercismExerciseGeneratorTest >> testSetupHintFromExistingTestClass [

|generator|
generator := ExercismExerciseGenerator new exerciseDirReference: 'two-fer' asFileReference.
generator setupHintFromExistingTestClass.
self deny: generator existingHint equals: 'TBD'.

generator exerciseDirReference: 'mock-exercise' asFileReference.
generator setupHintFromExistingTestClass.
self assert: generator existingHint equals: 'TBD'.
]
Loading

0 comments on commit 46b3e66

Please sign in to comment.