Skip to content

Commit

Permalink
Fix exercise test generator (#583)
Browse files Browse the repository at this point in the history
* fix Exercism Exercise generator to make it working again

* changed protocol name for initialize method

* Update test generation command in contributing doc
  • Loading branch information
Bajger authored Sep 8, 2023
1 parent b429bc1 commit a09213c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 20 deletions.
35 changes: 16 additions & 19 deletions dev/src/ExercismDev/ExercismExerciseGenerator.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -73,25 +73,14 @@ ExercismExerciseGenerator class >> writeLegacyPackageBaselineNames [

{ #category : #internal }
ExercismExerciseGenerator >> compile: src for: aClass selector: aSelector protocol: aName [
| cm aContext |

"aClass compile: src classified: (Protocol name: 'setup') notifying: self."

aContext := CompilationContext new
interactive: false;
"forSyntaxHighlighting: true;"
"logged: false;"
yourself.

cm := OpalCompiler new
compilationContext: aContext;
options: #( + #optionEmbeddSources );
class: aClass;
compile: src.

"compiles method even with undeclared globals (solution class)"
aClass compile: src.

"categorize compiled method to proper protocol"
aClass
addAndClassifySelector: aSelector
withMethod: cm
withMethod: (aClass compiledMethodAt: aSelector)
inProtocol: aName
]

Expand Down Expand Up @@ -187,12 +176,12 @@ ExercismExerciseGenerator >> generateExerciseFrom: aFileSystemReference [
(Smalltalk hasClassNamed: testName) ifTrue: [ ^self log: 'already exists (skipping)' for: testName ].

testDescription := (aFileSystemReference / 'description.md') contents.
testMetaData := (aFileSystemReference / 'metadata.yml') contents.
testMetaData := (aFileSystemReference / 'metadata.toml') contents.
testSpecification := [ (aFileSystemReference / 'canonical-data.json') contents]
on: FileDoesNotExistException do: [ ^self log:'has no specification (skipping)' for: testName ].

testJson := STONJSON fromString: testSpecification.
versionString := testJson at: 'version'.
versionString := testJson at: 'version' ifAbsent: ['Not specified'].

testMetaData := (WriteStream on: '') nextPutAll: testMetaData;
nextPutAll: ('exercise: "{1}"' format: {testRoot}); cr;
Expand Down Expand Up @@ -368,6 +357,14 @@ ExercismExerciseGenerator >> generateTestVariableAccessors: testVariable in: aCl

]

{ #category : #initialization }
ExercismExerciseGenerator >> initialize [

super initialize.
"reset number of generated test classes"
self numberGenerated: 0.
]

{ #category : #generation }
ExercismExerciseGenerator >> isErrorAssertion: testResults [
testResults isDictionary ifFalse: [ ^false ].
Expand All @@ -385,7 +382,7 @@ ExercismExerciseGenerator >> keywordFor: key withPrefix: aSelectorPrefix [
{ #category : #internal }
ExercismExerciseGenerator >> log: stringMsg for: testNameString [

self crLog: testNameString, ' ', stringMsg
self traceCr: testNameString, ' ', stringMsg
]

{ #category : #accessing }
Expand Down
2 changes: 1 addition & 1 deletion docs/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ __From problem repository__
- If you want to start completely new Practise exercise (step 1a.), you can use problem specification repository and generate test class for given exercise by running:
`ExercismExerciseGenerator generateFrom: <path-to-problem-specifications/exercises>` - this will generate test classes for all exercises in problem specifications repository in `ExerciseWIP` package.
> __Note__: You can use menu item in Pharo image for achieving same (World menu -> Exercism -> Generate test cases).
- More specifically, you can generate test class for specific exercise by: `ExercismExerciseGenerator generateExerciseFrom: <path-to-problem-specifications/exercises/slug-name>`.
- More specifically, you can generate test class for specific exercise by: `ExercismExerciseGenerator generateExerciseFrom: '<path-to-problem-specifications/exercises/slug-name>' asFileReference`.
Result of previous statement will be new `<SlugNameTest>` (a subclass of ExercismTest) test class with generated test methods in `ExerciseWIP` package.

Expand Down

0 comments on commit a09213c

Please sign in to comment.