Skip to content

Commit

Permalink
Fix-create-exercise (#1284)
Browse files Browse the repository at this point in the history
* Add basic version of script

* Create template dir

* More fix
  • Loading branch information
ErikSchierboom authored Oct 20, 2024
1 parent dc84d51 commit 1459e07
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 22 deletions.
24 changes: 3 additions & 21 deletions .github/ISSUE_TEMPLATE/new_exercise.md
Original file line number Diff line number Diff line change
@@ -1,22 +1,4 @@
There is a new exercise, [EXERCISE-NAME](https://github.com/exercism/problem-specifications/blob/master/exercises/EXERCISE-NAME/description.md), which data can be found here: https://github.com/exercism/problem-specifications/tree/master/exercises/EXERCISE-NAME
There is a new exercise, [EXERCISE-NAME](https://github.com/exercism/problem-specifications/blob/main/exercises/EXERCISE-NAME/description.md), which data can be found here: https://github.com/exercism/problem-specifications/tree/main/exercises/EXERCISE-NAME

To implement the `EXERCISE-NAME` exercise, first run the `./add-practice-exercise EXERCISE-NAME` script that will create and update the files required for the new exercise. After this script has run, it will have done the following:

- Added a new entry for the exercise to the [config.json](https://github.com/exercism/fsharp/blob/master/config.json) file.
- Add a default generator to the [generator/Generators.fs] file, which is used to automatically convert the [canonical data](https://github.com/exercism/problem-specifications/blob/master/exercises/EXERCISE-NAME/canonical-data.json) to a test file. For more information on how this works, check the [generators docs](https://github.com/exercism/fsharp/blob/master/docs/GENERATORS.md).
- Created the [`exercises/EXERCISE-NAME`] directory, which contains the following exercise-specific files:

- A project file.
- A test file.
- A stub implementation file.
- An example implementation file.
- A `README.md` file describing the exercise.

Once these files have been created, what's left for you is to:

- Verify the tests in the test file. As the test suite is automatically generated based on the canonical data, any customizations should be done by updating the generator in the [generator/Generators.fs] file and then regenerating the test suite using `./generate-tests.ps1 EXERCISE-NAME`.
- Modify the stub implementation file to have it compile succesfully together with the test file. This means adding stubs for the functions required in the test suite. For an example, see the [two-fer stub implementation file](https://github.com/exercism/fsharp/blob/master/exercises/two-fer/TwoFer.fs))
- Modify the example implementation file to have it pass all the tests. You can verify this by running `./test.ps1 EXERCISE-NAME` from the root directory.
- Update the exercise's entry in the `config.json` file: adding topics, setting the difficulty and indicating if it is a core exercise, or else specifying which exercise unlocks it.

Once all these steps have been completed, the final step is to open a pull request :)
To implement the `EXERCISE-NAME` exercise, first run the `./add-practice-exercise EXERCISE-NAME` script.
This will create the exercise's files and output what remains to be done.
18 changes: 17 additions & 1 deletion add-practice-exercise.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,25 @@ $proj.Project.ItemGroup[0].Compile[1].Include = "${exerciseName}Tests.fs"
$proj.Save($project)

# Add and run generator (this will update the tests file)
Add-Content -Path generators/Generators.fs -Value @"
$generator = "generators/Generators.fs"
Add-Content -Path $generator -Value @"
type ${exerciseName}() =
inherit ExerciseGenerator()
"@
& dotnet run --project generators --exercise $Exercise

# Output the next steps
$files = Get-Content "exercises/practice/${Exercise}/.meta/config.json" | ConvertFrom-Json | Select-Object -ExpandProperty files
Write-Output @"
Your next steps are:
- Check the test suite in $($files.test | Join-String -Separator ",")
- If the tests need changes, update the '${exerciseName}' class in the '${generator}' file
and then run: 'dotnet run --project generators --exercise ${Exercise}'
- Any test cases you don't implement, mark them in 'exercises/practice/${slug}/.meta/tests.toml' with "include = false"
- Create the example solution in $($files.example | Join-String -Separator ",")
- Verify the example solution passes the tests by running 'bin/verify-exercises ${slug}'
- Create the stub solution in $($files.solution | Join-String -Separator ",")
- Update the 'difficulty' value for the exercise's entry in the 'config.json' file in the repo's root
- Validate CI using 'bin/configlet lint' and 'bin/configlet fmt'
"@

0 comments on commit 1459e07

Please sign in to comment.