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

Impliment new template based generator #1730

Open
wants to merge 23 commits into
base: main
Choose a base branch
from
Open

Conversation

meatball133
Copy link
Member

No description provided.

@meatball133 meatball133 added the x:rep/large Large amount of reputation label Nov 9, 2024
Copy link
Contributor

github-actions bot commented Nov 9, 2024

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.

[no important files changed]

For more information, refer to the documentation. If you are unsure whether to add the message or not, please ping @exercism/maintainers-admin in a comment. Thank you!

generatorv2/lib/generator.rb Outdated Show resolved Hide resolved
generatorv2/lib/generator.rb Outdated Show resolved Hide resolved
bin/generate.rb Outdated Show resolved Hide resolved
bin/generate Outdated Show resolved Hide resolved
@meatball133 meatball133 marked this pull request as ready for review November 11, 2024 13:09
@meatball133 meatball133 requested a review from a team November 15, 2024 18:30
@@ -0,0 +1,49 @@
require 'toml-rb'
Copy link
Member

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.

Copy link
Member Author

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.

Copy link
Member Author

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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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.

generatorv2/README.md Outdated Show resolved Hide resolved
generatorv2/README.md Outdated Show resolved Hide resolved
end
rescue VerificationError => e
$stderr.puts e.message % {exercise:}
Copy link
Member

@kotp kotp Nov 17, 2024

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.

Copy link
Member Author

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.

Copy link
Member

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
x:rep/large Large amount of reputation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants