-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenerate
executable file
·58 lines (41 loc) · 1.14 KB
/
generate
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#!/usr/bin/env ruby
require 'fileutils'
PROJECTS_DIR = File.dirname(__FILE__)
def write_solution(project_dir)
solution = File.join(project_dir, 'solution')
File.open(solution, 'w') { |io| io << "\#!/usr/bin/env ruby" }
FileUtils.chmod(0755, solution)
end
def write_rakefile(project_dir)
rakefile = <<-EOF
require 'rake'
require 'rake/testtask'
Rake::TestTask.new(:default) { |t| t.pattern = 'test_solution.rb' }
EOF
File.open(File.join(project_dir, 'Rakefile'), 'w') { |io| io << rakefile }
end
def write_test(project_dir)
test = <<-'EOF';
require 'test/unit'
class TestSolution < Test::Unit::TestCase
INPUT =
OUTPUT =
SOLUTION = File.join(File.dirname(__FILE__), "solution")
def test_solution
results = `#{SOLUTION} #{INPUT}`.chomp
raise "error!" unless $?.success?
assert_equal(results.to_i, OUTPUT)
end
end
EOF
File.open(File.join(project_dir, 'test_solution.rb'), 'w') do |io|
io << test
end
end
project = ARGV
project_dir = File.join(PROJECTS_DIR, project)
FileUtils.mkdir_p(project_dir)
write_solution(project_dir)
write_rakefile(project_dir)
write_test(project_dir)
puts "Project created: #{project}"