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 28 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
77a991b
Impliment basic prototype as proof of concept
meatball133 Nov 9, 2024
039911c
Add ci and more tests
meatball133 Nov 9, 2024
8e3afbe
Update gemfile.lock to include toml-rb
meatball133 Nov 9, 2024
d278534
Merge branch 'main' into add-new-generator
meatball133 Nov 9, 2024
5c27b41
Fix rubocop and fix ci
meatball133 Nov 9, 2024
b1f131f
Format files
meatball133 Nov 9, 2024
7004988
EOL for every line in text file
kotp Nov 9, 2024
067df32
Generator now executable and changes based on feedback
meatball133 Nov 9, 2024
653f629
Fix interpreter name
kotp Nov 9, 2024
4960f96
Merge branch 'main' into add-new-generator
meatball133 Nov 11, 2024
39bf79b
Add missing name key in ci file
meatball133 Nov 11, 2024
7fb52c5
Fix execution path of ci scripts
meatball133 Nov 11, 2024
e1c69f4
Remove Crystal image refernce and fixes to ci
meatball133 Nov 11, 2024
79b00d1
Bump rubocop version and add missing actions checkout
meatball133 Nov 11, 2024
f806548
Test adding bundle install
meatball133 Nov 11, 2024
bbad039
Test uppdating gemfile
meatball133 Nov 11, 2024
b6d2e9e
Change to using `bundle exec`
meatball133 Nov 11, 2024
98d267d
Make the generate script use the same rubocop config as the repo
meatball133 Nov 11, 2024
68d4671
Test rollback to rubocop 1.50
meatball133 Nov 11, 2024
76504b5
Update readme to reflect recent changes
meatball133 Nov 11, 2024
00af4d0
Split utils methods into its own module
meatball133 Nov 15, 2024
492b44b
Breakout helper method and exception class
kotp Nov 16, 2024
f40f4c4
Verify now creates a file in exercise directory to get same formattin…
meatball133 Nov 17, 2024
769dee3
Changes based on feedback and add more tasks to rakefile
meatball133 Dec 5, 2024
754006b
Update bin/generate
meatball133 Dec 31, 2024
9932b77
Changes based on feedback
meatball133 Jan 1, 2025
adc9d0c
Update tests to reflect rename of `skip?`
meatball133 Jan 1, 2025
6e6bcb0
Update test names
meatball133 Jan 6, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 18 additions & 3 deletions bin/generate
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,21 @@ require 'optparse'
require 'tempfile'
require_relative '../generatorv2/lib/generator'

# Helper methods
def exercises
Dir.entries('./exercises/practice')
.select { |file| File.directory? File.join('./exercises/practice', file) }
end

class VerificationError < StandardError
def initialize(
message = "VerificationError: The result generated for %<exercise>s, doesn't match the current file"
)
super
end
end

# Parsing Code
parser = OptionParser.new

parser.on('-v', '--version', 'Print the version') do
Expand All @@ -14,7 +29,6 @@ parser.on('-h', '--help', 'Prints help') do
end

parser.on('-a', '--all', 'Generate all exercises') do
exercises = Dir.entries('./exercises/practice').select { |f| File.directory? File.join('./exercises/practice', f) }
exercises.each do |exercise|
if File.exist?("./exercises/practice/#{exercise}/.meta/test_template.erb")
Generator.new(exercise).generate
Expand All @@ -23,15 +37,16 @@ parser.on('-a', '--all', 'Generate all exercises') do
end

parser.on('--verify', 'Verify all exercises') do
exercises = Dir.entries('./exercises/practice').select { |f| File.directory? File.join('./exercises/practice', f) }
exercises.each do |exercise|
if File.exist?("./exercises/practice/#{exercise}/.meta/test_template.erb")
current_code = File.read("./exercises/practice/#{exercise}/#{exercise}_test.rb")
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
raise VerificationError unless current_code == generated_code
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.

end
end

Expand Down