Skip to content

Commit

Permalink
Changes based on feedback and add more tasks to rakefile
Browse files Browse the repository at this point in the history
  • Loading branch information
meatball133 committed Dec 5, 2024
1 parent f40f4c4 commit 769dee3
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 8 deletions.
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:}
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

0 comments on commit 769dee3

Please sign in to comment.