-
Notifications
You must be signed in to change notification settings - Fork 1
/
Rakefile
executable file
·159 lines (132 loc) · 3.64 KB
/
Rakefile
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
#!/usr/bin/env ruby
# -*- ruby -*-
require 'rake/clean'
SRC_DIR = 'src'
PROB_DIR = 'koans'
DOWNLOAD_DIR = 'download'
SRC_FILES = FileList["#{SRC_DIR}/*"]
KOAN_FILES = SRC_FILES.pathmap("#{PROB_DIR}/%f")
ZIP_FILE = "#{DOWNLOAD_DIR}/rubykoans.zip"
CLEAN.include("**/*.rbc")
module Koans
extend Rake::DSL if defined?(Rake::DSL)
# Remove solution info from source
# __(a,b) => __
# _n_(number) => __
# # __ =>
def Koans.remove_solution(line)
line = line.gsub(/\b____\([^\)]+\)/, "____")
line = line.gsub(/\b___\([^\)]+\)/, "___")
line = line.gsub(/\b__\([^\)]+\)/, "__")
line = line.gsub(/\b_n_\([^\)]+\)/, "_n_")
line = line.gsub(%r(/\#\{__\}/), "/__/")
line = line.gsub(/\s*#\s*__\s*$/, '')
line
end
def Koans.make_koan_file(infile, outfile)
if infile =~ /neo/
cp infile, outfile
else
open(infile) do |ins|
open(outfile, "w") do |outs|
state = :copy
ins.each do |line|
state = :skip if line =~ /^ *#--/
case state
when :copy
outs.puts remove_solution(line)
else
# do nothing
end
state = :copy if line =~ /^ *#\+\+/
end
end
end
end
end
end
module RubyImpls
# Calculate the list of relevant Ruby implementations.
def self.find_ruby_impls
rubys = `rvm list`.gsub(/=>/,'').split(/\n/).map { |x| x.strip }.reject { |x| x.empty? || x =~ /^rvm/ }.sort
expected.map { |impl|
last = rubys.grep(Regexp.new(Regexp.quote(impl))).last
last ? last.split.first : nil
}.compact
end
# Return a (cached) list of relevant Ruby implementations.
def self.list
@list ||= find_ruby_impls
end
# List of expected ruby implementations.
def self.expected
%w(ruby-1.8.7 ruby-1.9.2 jruby ree)
end
end
task :default => :walk_the_path
task :walk_the_path do
cd PROB_DIR
ruby 'path_to_enlightenment.rb'
end
directory DOWNLOAD_DIR
directory PROB_DIR
desc "(re)Build zip file"
task :zip => [:clobber_zip, :package]
task :clobber_zip do
rm ZIP_FILE
end
file ZIP_FILE => KOAN_FILES + [DOWNLOAD_DIR] do
sh "zip #{ZIP_FILE} #{PROB_DIR}/*"
end
desc "Create packaged files for distribution"
task :package => [ZIP_FILE]
desc "Upload the package files to the web server"
task :upload => [ZIP_FILE] do
sh "scp #{ZIP_FILE} linode:sites/onestepback.org/download"
end
desc "Generate the Koans from the source files from scratch."
task :regen => [:clobber_koans, :gen]
desc "Generate the Koans from the changed source files."
task :gen => KOAN_FILES + [PROB_DIR + "/README.rdoc"]
task :clobber_koans do
rm_r PROB_DIR
end
file PROB_DIR + "/README.rdoc" => "README.rdoc" do |t|
cp "README.rdoc", t.name
end
SRC_FILES.each do |koan_src|
file koan_src.pathmap("#{PROB_DIR}/%f") => [PROB_DIR, koan_src] do |t|
Koans.make_koan_file koan_src, t.name
end
end
task :run do
puts 'koans'
Dir.chdir("${SRC_DIR}") do
puts "in #{Dir.pwd}"
sh "ruby path_to_enlightenment.rb"
end
end
desc "Pre-checkin tests (=> run_all)"
task :cruise => :run_all
desc "Run the completed koans againts a list of relevant Ruby Implementations"
task :run_all do
results = []
RubyImpls.list.each do |impl|
puts "=" * 40
puts "On Ruby #{impl}"
sh ". rvm #{impl}; rake run"
results << [impl, "RAN"]
puts
end
puts "=" * 40
puts "Summary:"
puts
results.each do |impl, res|
puts "#{impl} => RAN"
end
puts
RubyImpls.expected.each do |requested_impl|
impl_pattern = Regexp.new(Regexp.quote(requested_impl))
puts "No Results for #{requested_impl}" unless results.detect { |x| x.first =~ impl_pattern }
end
end