-
Notifications
You must be signed in to change notification settings - Fork 2
Developer docs #11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Developer docs #11
Changes from all commits
85ba15a
96c8cb7
466957d
54c5e4d
aa24d84
f2d91a4
365ff5d
3a5f68e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -4,14 +4,92 @@ | |||||
|
|
||||||
| Exercism exercises in ReScript. | ||||||
|
|
||||||
| ## Installation | ||||||
|
|
||||||
| Track exercises target [Rescript] 12.2.0 using the [ReScript Test][ReScriptTest] testing framework on [Node.js] 22+. If you're contributing to the track, you will also need [make](https://www.gnu.org/software/make/). | ||||||
|
|
||||||
| ### Setting up the development environment | ||||||
|
|
||||||
| Run the following commands from inside the project root directory to install the required tools: | ||||||
|
|
||||||
| ```shell | ||||||
| npm install | ||||||
| git submodule update --init --recursive # add/update a local copy of the problem-specification submodule | ||||||
| ``` | ||||||
|
|
||||||
| To automate the creation of practice exercise tests, our track tooling consumes data from the the [problem specifications][exercism-problem-specifications-link] submodule. Because these specifications serve as the canonical source for all Exercism tracks, any upstream updates ensure our test cases remain consistent with the global exercise standard. | ||||||
|
|
||||||
| If you have format on save enabled for JSON files, it is recommended to disable this feature. Alternatively save JSON files with `Ctrl+K s` to save without applying formatting rules. | ||||||
|
|
||||||
| ### Running the development environment | ||||||
|
|
||||||
| Open up two terminals. By running the commands below, files will compile on save and re-run the test suite. | ||||||
|
|
||||||
| ```shell | ||||||
| # Terminal 1 | ||||||
| npm run res:start | ||||||
|
|
||||||
| # Terminal 2 | ||||||
| npm run test | ||||||
| ``` | ||||||
|
|
||||||
| ## Coding Style | ||||||
|
|
||||||
| Use `PascalCase.res` for Reason implementation file names. | ||||||
| A ReScript interface file (`.resi`) should be included with every exercise to help the user get started. | ||||||
|
|
||||||
| Run `make format` on your code before pushing. | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we make this a CI step? Format any new or updated code within a PR and error out if it doesn't match what was submited? |
||||||
|
|
||||||
| If you are using VS Code, install the official [ReScript VS Code extension](https://marketplace.visualstudio.com/items?itemName=chenglou92.rescript-vscode) for syntax highlighting and code formatting. | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are there extensions for other editors as well? We're soft endorsing VS Code otherwise by mentioning this especially in a code style section. That's fine, but we should cover our bases if possible. |
||||||
|
|
||||||
| ## Adding Exercises | ||||||
|
|
||||||
| Documentation on contributing to Exercism can be found [here][exercism-contributing-docs-link]. | ||||||
|
|
||||||
| New practice exercises can be added via: | ||||||
|
|
||||||
| ```shell | ||||||
| bin/add-practice-exercise <exercise-slug> | ||||||
|
|
||||||
| # Optionally, you can also specify the exercise's difficulty (via `-d`) and/or author's GitHub username (via `-a`): | ||||||
| bin/add-practice-exercise -a foobar -d 3 <exercise-slug> | ||||||
| ``` | ||||||
|
|
||||||
| Now complete the following steps: | ||||||
|
|
||||||
| - `config.json` - ensure that the new exercise data is correctly placed in order of difficulty and then alphabetically within that difficulty rating. | ||||||
| - implement exercise test cases, detailed in the [testing](#testing) section below. | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should be clear here that they need to make a template file first for the test generator to run. They then need to run the generator, making sure it runs a compilable ReScriptTest suite. Tests may need to be excluded from the tests.toml as well so that should be done as well. However, test generator may need to be rerun after you start working on the example solution and find a test for make sense for ReScript. Therefore we should mention or link out about the toml and how to skip a test there. Most of that is in the below section but it should be inlined here or introduced beforehand. Perhaps we break this into task-related sections: Generating Tests?Do this... Updating An Existing Exercise?Do this... Adding A New Exercise?Do this... |
||||||
| - `exercises/practice/<exercise-slug>/.meta/<exercise-name>.res` - write an example of code here that will pass all test cases. This does not need to be the finest example of how to complete this exercise, but it must pass all the test cases. Update the interface file with the exposed function signatures in the `.resi` file. | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Update which interface file? This list switches between file paths and steps. I think each list element should be an action and then you mention the files affected. |
||||||
| - `exercises/practice/<exercise-slug>/wrc/<exercise-name>.res` - create an exercise stub here which returns `panic("'<function-name>' has not been implemented")`. Update the interface file with the function signatures, so that the student has a reference to what names and types are used. | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
|
||||||
| ## Testing | ||||||
|
|
||||||
| To test all exercises, run `./bin/verify-exercises`. | ||||||
| This command will iterate over all exercises and check to see if their exemplar/example implementation passes all the tests. | ||||||
| Tests are written using [rescript-test](https://bloodyowl.github.io/rescript-test/). There is a test templating system in place to reduce the amount of work needed by a developer. Follow these steps when writing tests: | ||||||
|
|
||||||
| - `exercises/practice/<exercise-slug>/.meta/tests.toml` - if any of these test cases are not relevant to the language, add `ignore = true` on a newline below the description | ||||||
| - `exercises/practice/<exercise-slug>/.meta/testTemplate.js` - edit this file to allow the test generator to automatically create test files. | ||||||
| - you must write your comparator functions - https://bloodyowl.github.io/rescript-test/assertions. | ||||||
| - common assertions with comparator functions are located at `test_generator/assertions.js`. Pass the required ones into the `assertionFunctions` array. | ||||||
| - edit the `template` function so that it will generate the test cases. The `c` variable refers to a test case in `problem-specifications/exercises/<exercise-slug>/canonical-data.json`. Look at other exercise test templates for inspiration. | ||||||
|
|
||||||
| To test a single exercise, run `./bin/verify-exercises <exercise-slug>`. | ||||||
| Run all exercise tests: | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should highlight first how to verify a single exercise and then all exercises in case someone just wants to verify the exercise being added passes. |
||||||
|
|
||||||
| ```shell | ||||||
| make test | ||||||
| ``` | ||||||
|
|
||||||
| This command will iterate over all exercises and check to see if their example implementation passes all the tests. | ||||||
|
|
||||||
| To test that all exercises will pass in the CI/CD environment, run: | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||||||
|
|
||||||
| ```shell | ||||||
| ./bin/verify-exercises | ||||||
|
|
||||||
| # test a single exercise: | ||||||
| ./bin/verify-exercises <exercise-slug> | ||||||
| ``` | ||||||
|
|
||||||
| ### Using Docker | ||||||
| <!-- ### Using Docker | ||||||
|
|
||||||
| If your track has a working [test runner](https://exercism.org/docs/building/tooling/test-runners), the `./bin/verify-exercises-in-docker` script can also be used to test all exercises. | ||||||
| This script pulls (_downloads_) the test runner's [Docker image](https://exercism.org/docs/building/tooling/test-runners/docker) and then uses Docker to run that image to test an exercise. | ||||||
|
|
@@ -21,49 +99,56 @@ The main benefit of this approach is that it best mimics how exercises are teste | |||||
| Another benefit is that you don't have to install track-specific dependencies (e.g. an SDK) locally, you just need Docker installed. | ||||||
| ``` | ||||||
|
|
||||||
| To test a single exercise, run `./bin/verify-exercises-in-docker <exercise-slug>`. | ||||||
| To test a single exercise, run `./bin/verify-exercises-in-docker <exercise-slug>`. --> | ||||||
|
|
||||||
| ### Linting | ||||||
| ## Linting & Formatting | ||||||
|
|
||||||
| [`configlet`](https://exercism.org/docs/building/configlet) is an Exercism-wide tool for working with tracks. You can download it by running: | ||||||
|
|
||||||
| ```shell | ||||||
| $ ./bin/fetch-configlet | ||||||
| ./bin/fetch-configlet | ||||||
| ``` | ||||||
|
|
||||||
| Run its [`lint` command](https://exercism.org/docs/building/configlet/lint) to verify if exercises have the required files and if config files are correct: | ||||||
| Run the [`lint` command][configlet-link-link] to verify if exercises have the required files and if config files are correct. Address any issues before pushing your changes: | ||||||
|
|
||||||
| ```shell | ||||||
| $ ./bin/configlet lint | ||||||
|
|
||||||
| The lint command is under development. | ||||||
| Please re-run this command regularly to see if your track passes the latest linting rules. | ||||||
|
|
||||||
| Basic linting finished successfully: | ||||||
| - config.json exists and is valid JSON | ||||||
| - config.json has these valid fields: | ||||||
| language, slug, active, blurb, version, status, online_editor, key_features, tags | ||||||
| - Every concept has the required .md files | ||||||
| - Every concept has a valid links.json file | ||||||
| - Every concept has a valid .meta/config.json file | ||||||
| - Every concept exercise has the required .md files | ||||||
| - Every concept exercise has a valid .meta/config.json file | ||||||
| - Every practice exercise has the required .md files | ||||||
| - Every practice exercise has a valid .meta/config.json file | ||||||
| - Required track docs are present | ||||||
| - Required shared exercise docs are present | ||||||
| ./bin/configlet lint | ||||||
| ``` | ||||||
|
|
||||||
| ## Adding exercises | ||||||
|
|
||||||
| New (practice) exercises can be added via: | ||||||
| Run the [`fmt` command][configlet-fmt-link] to verify if exercises and configuration files are formatted correctly. Address any issues before pushing your changes: | ||||||
|
|
||||||
| ```shell | ||||||
| bin/add-practice-exercise <exercise-slug> | ||||||
| ``` | ||||||
| ./bin/configlet fmt | ||||||
|
|
||||||
| Optionally, you can also specify the exercise's difficulty (via `-d`) and/or author's GitHub username (via `-a`): | ||||||
| # check a single exercise | ||||||
| ./bin/configlet fmt -e <exercise-slug> | ||||||
|
|
||||||
| ```shell | ||||||
| bin/add-practice-exercise -a foobar -d 3 <exercise-slug> | ||||||
| # auto format files | ||||||
| ./bin/configlet fmt -u | ||||||
| ``` | ||||||
|
|
||||||
| If you are auto formatting files, only commit the files relevant to your pull request. | ||||||
|
|
||||||
| ## Pull Requests | ||||||
|
|
||||||
| Familiarise yourself with the Exercism [documentation][exercism-pr-docs-link] on pull requests. | ||||||
|
|
||||||
| Make sure your work is commited on a new branch. When you are ready to submit your changes, push your changes to your forked repository and open a pull request on the language track [repository]. | ||||||
|
|
||||||
| More details on how to create pull requests from a fork can be found [here][github-fork-pr-link]. | ||||||
|
|
||||||
| ## Feedback | ||||||
|
|
||||||
| If you find this documentation is inaccurate or incomplete, or can be improved in any way, please don't hesitate to raise an [issue][issue-link] or submit a pull request. | ||||||
|
|
||||||
| [ReScript]: https://rescript-lang.org/ | ||||||
| [ReScriptTest]: https://bloodyowl.github.io/rescript-test/ | ||||||
| [Node.js]: https://nodejs.org/ | ||||||
| [repository]: https://github.com/exercism/rescript | ||||||
| [issue-link]: https://github.com/exercism/rescript/issues | ||||||
| [configlet-lint-link]: https://exercism.org/docs/building/configlet/lint | ||||||
| [configlet-fmt-link]: https://exercism.org/docs/building/configlet/fmt | ||||||
| [github-fork-pr-link]: https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/proposing-changes-to-your-work-with-pull-requests/creating-a-pull-request-from-a-fork | ||||||
| [exercism-pr-docs-link]: https://exercism.org/docs/building/github/contributors-pull-request-guide | ||||||
| [exercism-contributing-docs-link]: https://exercism.org/docs/building | ||||||
| [exercism-problem-specifications-link]: https://github.com/exercism/problem-specifications | ||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We also need to provide the stub file. It'd probably be useful to showcase an example of one so it's clear that we don't want the completely empty stub that
configlet createwould gives us.We should link to what an interface file is. We should highlight that this needs to be added manually since
configlet createwon't create an empty one for us.