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 27 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
27 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
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
15 changes: 15 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,21 @@ task :rubocop do
system('rubocop --display-cop-names')
end

desc "Run generator for specefic exercise"
task :generate, [:exercise] do |_t, argumments|
system("./bin/generate --exercise #{argumments[:exercise]}")
end

desc "Run generator for all exercises"
task :generate_all do
system("./bin/generate --all")
end

desc "Verify templates for all exercises"
task :verify do
system("./bin/generate --verify")
end

namespace :test do
flags = ARGV.drop_while { |e| e != '--' }.drop(1).join(' ')

Expand Down
8 changes: 4 additions & 4 deletions bin/generate
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ def exercises
end

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

def initialize(message = MESSAGE)
super
end
end
Expand Down Expand Up @@ -47,7 +47,7 @@ parser.on('--verify', 'Verify all exercises') do
fail VerificationError unless current_code == generated_code
end
rescue VerificationError => e
$stderr.puts e.message % {exercise:}
stderr.puts e.message % {exercise:}
meatball133 marked this conversation as resolved.
Show resolved Hide resolved
end
end

Expand Down
7 changes: 3 additions & 4 deletions generatorv2/lib/generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

class Generator
include Utils
include NullDevice

def initialize(exercise = nil)
@first = true
Expand All @@ -20,15 +21,13 @@ def generate(result_path = "./exercises/practice/#{@exercise}/#{@exercise}_test.
additional_json(json)
json["cases"] = remove_tests(uuid, json)
status = proc { status }
camel_case = proc { |str| camel_case(str) }
underscore = proc { |str| underscore(str) }
template = ERB.new File.read("./exercises/practice/#{@exercise}/.meta/test_template.erb")

result = template.result(binding)

File.write(result_path, result)
cli = RuboCop::CLI.new
cli.run(['-x', "-c", ".rubocop.yml", "-o", "/dev/null", result_path])
RuboCop::CLI.new.
run(['-x', '-c', '.rubocop.yml', '-o', NullDevice.path, result_path])
end

def underscore(str)
Expand Down
6 changes: 6 additions & 0 deletions generatorv2/lib/utils.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
module NullDevice
def self.path
Gem.win_platform? ? 'NUL' : '/dev/null'
end
end

module Utils
def toml(path = "./exercises/practice/#{@exercise}/.meta/tests.toml")
raise "Toml not found: #{path}" unless File.exist?(path)
Expand Down