Skip to content
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

Improve exercise generator #1797

Merged
merged 6 commits into from
Nov 23, 2023
Merged

Improve exercise generator #1797

merged 6 commits into from
Nov 23, 2023

Conversation

senekor
Copy link
Contributor

@senekor senekor commented Nov 22, 2023

  • Add a clap-based CLI
    All user-input can now be entered upfront with cli flags
    or later by being prompted for it interactively.

  • Limit output of rustfmt passed onto user
    (There are usually many duplicates when generating test cases.)

  • Handle absence of canonical data
    (e.g. for custom exercises) not from problem-specifications)

piggyback:

  • Make exercise difficulty in track config type-safe

When the generator was created, it lived in the same crate as other
rust code unrelated to exercise generation. Therefore, a split between
library and executable was natural. (also naming the executable,
instead of a simple main.rs)

Now that exercise generation has its own crate, the split between
library and executable doesn't make sense anymore.
The difficulty of an exercise was until now represented as a `u8`,
even though it was only allowed to be 1, 4, 7, or 10.
By representing the difficulty as an enum, which de-/serializes to
and from an integer as expected, we have full type safety and can
get rid of the tests. If there was an invalid difficulty in the config,
the test which deserializes the entire config would fail already.
For example for custom exercises which do not come from
problem-specifications.
Usually when rustfmt fails, it is because the tera template produces
invalid syntax. For generated test cases, this usually means all test
cases are invalid, so there are a lot of practically identical errors.
@senekor
Copy link
Contributor Author

senekor commented Nov 22, 2023

Apart from a few internal refactorings I'm quite happy about, the main win here for me is the fact that one can run

just update-exercise --slug accumulate

to synchronize an exercise without any further interactive prompts.

Until now, one would always be prompted for the exercise slug interactively. When I'm tweaking an exercise's test template, I run the generator very often and it can get tedious to enter the slug interactively every time.

@senekor senekor merged commit ff92b1c into main Nov 23, 2023
11 checks passed
@senekor senekor deleted the better-generator branch November 23, 2023 08:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants