Skip to content

Commit 443c5ef

Browse files
Simplify add practice exercise
1 parent 988df1e commit 443c5ef

File tree

4 files changed

+82
-69
lines changed

4 files changed

+82
-69
lines changed

.github/ISSUE_TEMPLATE/new_exercise.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
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
22

3-
To implement the `EXERCISE-NAME` exercise, first run the `./add-new-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:
3+
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:
44

55
- Added a new entry for the exercise to the [config.json](https://github.com/exercism/csharp/blob/master/config.json) file.
66
- Created a default generator in the [generator/Generators/Exercise] directory, 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/csharp/blob/master/docs/GENERATORS.md).

README.md

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,15 @@ Exercism exercises in C#
88

99
Please see the [contributing guide](https://exercism.org/docs/building)
1010

11-
### Adding a new exercise
11+
### Adding a new practice exercise
1212

13-
To add a new exercise, run the `bin/add-new-exercise.ps1` PowerShell script:
13+
To add a new exercise, run the `bin/add-practice-exercise.ps1` PowerShell script:
1414

1515
```shell
16-
pwsh bin/add-new-exercise.ps1 bob
16+
pwsh bin/add-practice-exercise.ps1 bob
1717
```
1818

19-
This will create all the necessary files and tests for you.
20-
Then you just need to implement the `Example.cs` file and to check if the generated tests make sense.
21-
Parameters and examples for running the script can be found in the script file.
19+
This will add the exercise's files and output what remains to be done.
2220

2321
## Support
2422

bin/add-new-exercise.ps1

Lines changed: 0 additions & 62 deletions
This file was deleted.

bin/add-practice-exercise.ps1

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
<#
2+
.SYNOPSIS
3+
Add a new exercise.
4+
.DESCRIPTION
5+
Add the files need to add a new exercise.
6+
.PARAMETER Exercise
7+
The slug of the exercise to add.
8+
.PARAMETER Author
9+
The author of the exercise.
10+
.PARAMETER Difficulty
11+
The difficulty of the exercise on a scale from 1 to 10 (optional, default: 1).
12+
.EXAMPLE
13+
The example below will add the "acronym" exercise
14+
PS C:\> ./bin/add-practice-exercise.ps1 acronym
15+
#>
16+
17+
[CmdletBinding(SupportsShouldProcess)]
18+
param (
19+
[Parameter(Position = 0, Mandatory = $true)][string]$Exercise,
20+
[Parameter(Mandatory = $true)][string]$Author,
21+
[Parameter()][int]$Difficulty = 1
22+
)
23+
24+
$ErrorActionPreference = "Stop"
25+
$PSNativeCommandUseErrorActionPreference = $true
26+
27+
# Use configlet to create the exercise
28+
& bin/fetch-configlet
29+
& bin/configlet create --practice-exercise $Exercise --difficulty $Difficulty --author $Author
30+
31+
# Create project
32+
$exerciseName = (Get-Culture).TextInfo.ToTitleCase($Exercise).Replace("-", "")
33+
$exerciseDir = "exercises/practice/${Exercise}"
34+
$project = "${exerciseDir}/${ExerciseName}.csproj"
35+
& dotnet new xunit --force -lang "C#" --target-framework-override net8.0 -o $exerciseDir -n $ExerciseName
36+
& dotnet sln exercises/Exercises.sln add $project
37+
38+
# Update project packages
39+
& dotnet remove $project package coverlet.collector
40+
& dotnet add $project package Exercism.Tests --version 0.1.0-beta1
41+
& dotnet add $project package xunit.runner.visualstudio --version 2.4.3
42+
& dotnet add $project package xunit --version 2.4.1
43+
& dotnet add $project package Microsoft.NET.Test.Sdk --version 16.8.3
44+
45+
# Remove and update files
46+
Remove-Item -Path "${exerciseDir}/UnitTest1.cs"
47+
(Get-Content -Path ".editorconfig") -Replace "\[\*\.cs\]", "[${exerciseName}.cs]" | Set-Content -Path "${exerciseDir}/.editorconfig"
48+
49+
# Add and run generator (this will update the tests file)
50+
$generator = "generators/Exercises/Generators/${ExerciseName}.cs"
51+
Add-Content -Path $generator -Value @"
52+
using System;
53+
54+
using Exercism.CSharp.Output;
55+
56+
namespace Exercism.CSharp.Exercises.Generators;
57+
58+
internal class ${exerciseName} : ExerciseGenerator
59+
{
60+
}
61+
"@
62+
& dotnet run --project generators --exercise $Exercise
63+
64+
# Output the next steps
65+
$files = Get-Content "exercises/practice/${Exercise}/.meta/config.json" | ConvertFrom-Json | Select-Object -ExpandProperty files
66+
Write-Output @"
67+
Your next steps are:
68+
- Check the test suite in $($files.test | Join-String -Separator ",")
69+
- If the tests need changes, update the '${exerciseName}' class in the '${generator}' file
70+
and then run: 'dotnet run --project generators --exercise ${Exercise}'
71+
- Any test cases you don't implement, mark them in 'exercises/practice/${slug}/.meta/tests.toml' with "include = false"
72+
- Create the example solution in $($files.example | Join-String -Separator ",")
73+
- Verify the example solution passes the tests by running 'bin/verify-exercises ${slug}'
74+
- Create the stub solution in $($files.solution | Join-String -Separator ",")
75+
- Update the 'difficulty' value for the exercise's entry in the 'config.json' file in the repo's root
76+
- Validate CI using 'bin/configlet lint' and 'bin/configlet fmt'
77+
"@

0 commit comments

Comments
 (0)