-
-
Notifications
You must be signed in to change notification settings - Fork 518
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
Impliment new template based generator #1730
base: main
Are you sure you want to change the base?
Conversation
This PR touches files which potentially affect the outcome of the tests of an exercise. This will cause all students' solutions to affected exercises to be re-tested. If this PR does not affect the result of the test (or, for example, adds an edge case that is not worth rerunning all tests for), please add the following to the merge-commit message which will stops student's tests from re-running. Please copy-paste to avoid typos.
For more information, refer to the documentation. If you are unsure whether to add the message or not, please ping |
@@ -0,0 +1,49 @@ | |||
require 'toml-rb' |
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.
What problems or solutions are we avoiding/gaining by using TOML as opposed to YAML (or even JSON)? This is the point at which TOML as a tool and dependency is being introduced, and its associated maintenance cost, so we should evaluate that. We should have a net positive effect by bringing this in.
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.
The test.toml
files are written in toml, using another file format isn't really an option since rewriting it would require parsing it.
I wrote a manual parser for the Crystal generator (but it is likely not as good of an implementation) because I couldn't find any good shards (library). This library should be fine, the toml specification isn't changing, but we could have our own solution.
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.
The goal is more or less with the toml files is that, if someone adds extra test cases or reimplements test cases for a certain exercise will that not affect the generation process until you sync the exercise. Meaning the ci won't fail in the majority of cases if not all exercises are synced.
bin/generate
Outdated
f = Tempfile.create | ||
Generator.new(exercise).generate(f.path) | ||
generated_code = f.read | ||
raise RuntimeError.new("The result generated for: #{exercise}, doesnt match the current file") if current_code != generated_code |
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.
raise RuntimeError.new("The result generated for: #{exercise}, doesnt match the current file") if current_code != generated_code | |
raise RuntimeError.new("The result generated for: #{exercise}, doesn't match the current file") unless current_code == generated_code |
Typographical error (missing apostrophe) and preference of "positive conditional statement".
Prefer using unless positive_conditional_statement
rather than if negative
, this can keep all (or at least most) of our conditional statements positive.
We should also consider if RuntimeError
is the best error here. It could be VerificationError
instead, which would be more specific.
We might also fail
instead of raise
for the communication that this is purposefully failed here, given the right conditions.
Since the generator grabs all the data from the canonical data, so does this enable new tests that won't automatically be merged in. | ||
Instead so does new tests have to be added to the toml file before they show up in the test file. | ||
|
||
If there is a test that isn't needed or something that doesn't fit Ruby you can remove it from the toml file. |
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.
If there is a test that isn't needed or something that doesn't fit Ruby you can remove it from the toml file. | |
If there is a test that isn't needed or something that doesn't fit Ruby you can remove it from the configuration file. |
In case we move from TOML to another type of configuration file, this reference will not need to change in the documentation.
…g as the normal creation. Other changes based on feedback
bin/generate
Outdated
end | ||
rescue VerificationError => e | ||
$stderr.puts e.message % {exercise:} |
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.
Be aware that this syntax is relatively new, and so we should ensure that the minimum Ruby version is set to allow for this "valueless hash" syntax.
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.
I mean it is tooling and we have set the ruby version to 3.3 so I think we dont have to have backwards compatibility.
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.
It means that it is backward compatible to 3.3.0, up to 3.3.6, currently. Locally I am running 3.3.6, and so the backward compatibility is there.
Co-authored-by: Victor Goff <[email protected]>
bin/generate
Outdated
parser = OptionParser.new | ||
|
||
parser.on('-v', '--version', 'Print the version') do | ||
puts '0.1.0' |
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.
Consider extracting this out to a version file for the generator. This will mean that we do not have to dig into the code to update the version.
generatorv2/README.md
Outdated
# This would break it since it is an extra space between UUID and `[` | ||
[ 1e22cceb-c5e4-4562-9afe-aef07ad1eaf4] | ||
``` | ||
|
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.
It may be worth writing a "validator" option for the genator. Perhaps even initiating the bundle install
command that is needed. If we know it has to happen we can provide the mechanism, avoiding mistakes from the users, even if it is seemingly "simple".
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.
I think, that shouldn't actually be an issue, unless it breaks against toml rules which I think it doesn't. The docs very some what of a copy paste from the Crystal docs (so it shouldn't be here). And that one has that issue,
generatorv2/README.md
Outdated
|
||
### The Test Generator | ||
|
||
If all the earlier steps are done so can you run the generator. |
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.
If all the earlier steps are done so can you run the generator. | |
If all the earlier steps are done you run the generator. |
|
||
The template file is written in [Embedded Ruby(ERB)][erb]. | ||
ERB enables you to write Ruby code inside of the template file. | ||
It also means that the templates can be highly customizable since you can write any Ruby code you want. |
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.
It also means that the templates can be highly customizable since you can write any Ruby code you want. | |
It also means that the templates can be highly customized allowing you to write any Ruby code you want or need. |
generatorv2/README.md
Outdated
The template is located under the `.meta` for each exercise. | ||
|
||
This template has to be manually written for each exercise. | ||
The goal although is to make it so that you only have to write the template once and then it will be able to be used to generate new tests. |
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.
The goal although is to make it so that you only have to write the template once and then it will be able to be used to generate new tests. | |
The goal is to make it so that you only have to write the template once and then it will be able to be used to generate new tests. |
generatorv2/README.md
Outdated
To run the generator so do you have to be in the root directory and run the following command: | ||
|
||
```shell | ||
bundle exec ./bin/generate -e <exercise_slug> |
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.
Either the line commented prior to this comment is incorrect, or this line is incorrect.
generatorv2/README.md
Outdated
|
||
Where `<exercise_slug>` is the same name as the slug name which is located in the `config.json` file. | ||
|
||
For more commands so can you run the following command: |
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.
For more commands so can you run the following command: | |
For more commands and options, you can see this by running the command: |
generatorv2/README.md
Outdated
|
||
The generator will give you errors and warnings if something is wrong. | ||
That includes if the exercise is not in the `config.json` file, if the exercise is not in the toml file, or if the template file is missing. | ||
Also if it has a problem getting the `canonical-data.json` file so will it give you an error. |
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.
Also if it has a problem getting the `canonical-data.json` file so will it give you an error. | |
It will also report an error if it can not read the `canonical-data.json` file. |
generatorv2/README.md
Outdated
The generator will give you errors and warnings if something is wrong. | ||
That includes if the exercise is not in the `config.json` file, if the exercise is not in the toml file, or if the template file is missing. | ||
Also if it has a problem getting the `canonical-data.json` file so will it give you an error. | ||
The generator also uses a formatter which will give you errors if the generated file is not formatted correctly. |
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.
The generator also uses a formatter which will give you errors if the generated file is not formatted correctly. | |
The generator will check that the generated file is formatted correctly, reporting an error if there is a problem. |
generatorv2/README.md
Outdated
That includes if the exercise is not in the `config.json` file, if the exercise is not in the toml file, or if the template file is missing. | ||
Also if it has a problem getting the `canonical-data.json` file so will it give you an error. | ||
The generator also uses a formatter which will give you errors if the generated file is not formatted correctly. | ||
The file will still be generated even if formatter gives errors, therefore can you check the file and see what is wrong and fix it in the template. |
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.
The file will still be generated even if formatter gives errors, therefore can you check the file and see what is wrong and fix it in the template. | |
The file will still be generated even if the formatter reports errors, so that you can check the file and see what is wrong and fix it in the template. |
No description provided.