|
1 |
| -require 'rubygems' |
2 |
| -require 'rubygems/package_task' |
3 |
| -require 'rake/testtask' |
| 1 | +require "rake/testtask" |
4 | 2 |
|
5 | 3 | ENV["REDIS_BRANCH"] ||= "unstable"
|
6 | 4 |
|
7 |
| -$:.unshift File.join(File.dirname(__FILE__), 'lib') |
8 |
| -require 'redis/version' |
9 |
| - |
10 | 5 | REDIS_DIR = File.expand_path(File.join("..", "test"), __FILE__)
|
11 | 6 | REDIS_CNF = File.join(REDIS_DIR, "test.conf")
|
12 | 7 | REDIS_PID = File.join(REDIS_DIR, "db", "redis.pid")
|
@@ -71,246 +66,3 @@ Rake::TestTask.new do |t|
|
71 | 66 | t.options = "-v" if $VERBOSE
|
72 | 67 | t.test_files = FileList["test/*_test.rb"]
|
73 | 68 | end
|
74 |
| - |
75 |
| -class Source |
76 |
| - |
77 |
| - MATCHER = "(?:\\s{%d}#[^\\n]*\\n)*^\\s{%d}def ([a-z_?]+)(?:\(.*?\))?\\n.*?^\\s{%d}end\\n\\n" |
78 |
| - |
79 |
| - def initialize(data, options = {}) |
80 |
| - @doc = parse(File.read(data), options) |
81 |
| - end |
82 |
| - |
83 |
| - def methods |
84 |
| - @doc.select do |d| |
85 |
| - d.is_a?(Method) |
86 |
| - end.map do |d| |
87 |
| - d.name |
88 |
| - end |
89 |
| - end |
90 |
| - |
91 |
| - def move(a, b) |
92 |
| - ao = @doc.find { |m| m.is_a?(Method) && m.name == a } |
93 |
| - bo = @doc.find { |m| m.is_a?(Method) && m.name == b } |
94 |
| - ai = @doc.index(ao) |
95 |
| - bi = @doc.index(bo) |
96 |
| - |
97 |
| - @doc.delete_at(ai) |
98 |
| - @doc.insert(bi, ao) |
99 |
| - |
100 |
| - nil |
101 |
| - end |
102 |
| - |
103 |
| - def to_s |
104 |
| - @doc.join |
105 |
| - end |
106 |
| - |
107 |
| - protected |
108 |
| - |
109 |
| - def parse(data, options = {}) |
110 |
| - re = Regexp.new(MATCHER % ([options[:indent]] * 3), Regexp::MULTILINE) |
111 |
| - tail = data.dup |
112 |
| - doc = [] |
113 |
| - |
114 |
| - while match = re.match(tail) |
115 |
| - doc << match.pre_match |
116 |
| - doc << Method.new(match) |
117 |
| - tail = match.post_match |
118 |
| - end |
119 |
| - |
120 |
| - doc << tail if tail |
121 |
| - doc |
122 |
| - end |
123 |
| - |
124 |
| - class Method |
125 |
| - |
126 |
| - def initialize(match) |
127 |
| - @match = match |
128 |
| - end |
129 |
| - |
130 |
| - def name |
131 |
| - @match[1] |
132 |
| - end |
133 |
| - |
134 |
| - def to_s |
135 |
| - @match[0] |
136 |
| - end |
137 |
| - end |
138 |
| -end |
139 |
| - |
140 |
| -namespace :commands do |
141 |
| - def redis_commands |
142 |
| - $redis_commands ||= doc.keys.map do |key| |
143 |
| - key.split(" ").first.downcase |
144 |
| - end.uniq |
145 |
| - end |
146 |
| - |
147 |
| - def doc |
148 |
| - $doc ||= begin |
149 |
| - require "open-uri" |
150 |
| - require "json" |
151 |
| - |
152 |
| - JSON.parse(open("https://github.com/antirez/redis-doc/raw/master/commands.json").read) |
153 |
| - end |
154 |
| - end |
155 |
| - |
156 |
| - task :order do |
157 |
| - require "json" |
158 |
| - |
159 |
| - reference = if File.exist?(".order") |
160 |
| - JSON.parse(File.read(".order")) |
161 |
| - else |
162 |
| - {} |
163 |
| - end |
164 |
| - |
165 |
| - buckets = {} |
166 |
| - doc.each do |k, v| |
167 |
| - buckets[v["group"]] ||= [] |
168 |
| - buckets[v["group"]] << k.split.first.downcase |
169 |
| - buckets[v["group"]].uniq! |
170 |
| - end |
171 |
| - |
172 |
| - result = (reference.keys + (buckets.keys - reference.keys)).map do |g| |
173 |
| - [g, reference[g] + (buckets[g] - reference[g])] |
174 |
| - end |
175 |
| - |
176 |
| - File.open(".order", "w") do |f| |
177 |
| - f.write(JSON.pretty_generate(Hash[result])) |
178 |
| - end |
179 |
| - end |
180 |
| - |
181 |
| - def reorder(file, options = {}) |
182 |
| - require "json" |
183 |
| - require "set" |
184 |
| - |
185 |
| - STDERR.puts "reordering #{file}..." |
186 |
| - |
187 |
| - reference = if File.exist?(".order") |
188 |
| - JSON.parse(File.read(".order")) |
189 |
| - else |
190 |
| - {} |
191 |
| - end |
192 |
| - |
193 |
| - dst = Source.new(file, options) |
194 |
| - |
195 |
| - src_methods = reference.map { |k, v| v }.flatten |
196 |
| - dst_methods = dst.methods |
197 |
| - |
198 |
| - src_set = Set.new(src_methods) |
199 |
| - dst_set = Set.new(dst_methods) |
200 |
| - |
201 |
| - intersection = src_set & dst_set |
202 |
| - intersection.delete("initialize") |
203 |
| - |
204 |
| - loop do |
205 |
| - src_methods = reference.map { |k, v| v }.flatten |
206 |
| - dst_methods = dst.methods |
207 |
| - |
208 |
| - src_methods = src_methods.select do |m| |
209 |
| - intersection.include?(m) |
210 |
| - end |
211 |
| - |
212 |
| - dst_methods = dst_methods.select do |m| |
213 |
| - intersection.include?(m) |
214 |
| - end |
215 |
| - |
216 |
| - if src_methods == dst_methods |
217 |
| - break |
218 |
| - end |
219 |
| - |
220 |
| - rv = yield(src_methods, dst_methods, dst) |
221 |
| - break if rv == false |
222 |
| - end |
223 |
| - |
224 |
| - File.open(file, "w") do |f| |
225 |
| - f.write(dst.to_s) |
226 |
| - end |
227 |
| - end |
228 |
| - |
229 |
| - task :reorder do |
230 |
| - blk = lambda do |src_methods, dst_methods, dst| |
231 |
| - src_methods.zip(dst_methods).each do |a, b| |
232 |
| - if a != b |
233 |
| - dst.move(a, b) |
234 |
| - break |
235 |
| - end |
236 |
| - end |
237 |
| - end |
238 |
| - |
239 |
| - reorder "lib/redis.rb", :indent => 2, &blk |
240 |
| - reorder "lib/redis/distributed.rb", :indent => 4, &blk |
241 |
| - end |
242 |
| - |
243 |
| - def missing(file, options = {}) |
244 |
| - src = Source.new(file, options) |
245 |
| - |
246 |
| - defined_methods = src.methods.map(&:downcase) |
247 |
| - required_methods = redis_commands.map(&:downcase) |
248 |
| - |
249 |
| - STDOUT.puts "missing in #{file}:" |
250 |
| - STDOUT.puts (required_methods - defined_methods).inspect |
251 |
| - end |
252 |
| - |
253 |
| - task :missing do |
254 |
| - missing "lib/redis.rb", :indent => 2 |
255 |
| - missing "lib/redis/distributed.rb", :indent => 4 |
256 |
| - end |
257 |
| - |
258 |
| - def document(file) |
259 |
| - source = File.read(file) |
260 |
| - |
261 |
| - doc.each do |name, command| |
262 |
| - source.sub!(/(?:^ *# .*\n)*(^ *#\n(^ *# .+?\n)*)*^( *)def #{name.downcase}(\(|$)/) do |
263 |
| - extra_comments, indent, extra_args = $1, $3, $4 |
264 |
| - comment = "#{indent}# #{command["summary"].strip}." |
265 |
| - |
266 |
| - IO.popen("par p#{2 + indent.size} 80", "r+") do |io| |
267 |
| - io.puts comment |
268 |
| - io.close_write |
269 |
| - comment = io.read |
270 |
| - end |
271 |
| - |
272 |
| - "#{comment}#{extra_comments}#{indent}def #{name.downcase}#{extra_args}" |
273 |
| - end |
274 |
| - end |
275 |
| - |
276 |
| - File.open(file, "w") { |f| f.write(source) } |
277 |
| - end |
278 |
| - |
279 |
| - task :doc do |
280 |
| - document "lib/redis.rb" |
281 |
| - document "lib/redis/distributed.rb" |
282 |
| - end |
283 |
| - |
284 |
| - task :verify do |
285 |
| - require "redis" |
286 |
| - require "stringio" |
287 |
| - |
288 |
| - require "./test/helper" |
289 |
| - |
290 |
| - OPTIONS[:logger] = Logger.new("./tmp/log") |
291 |
| - |
292 |
| - Rake::Task["test:ruby"].invoke |
293 |
| - |
294 |
| - redis = Redis.new |
295 |
| - |
296 |
| - report = ["Command", "\033[0mDefined?\033[0m", "\033[0mTested?\033[0m"] |
297 |
| - |
298 |
| - yes, no = "\033[1;32mYes\033[0m", "\033[1;31mNo\033[0m" |
299 |
| - |
300 |
| - log = File.read("./tmp/log") |
301 |
| - |
302 |
| - redis_commands.sort.each do |name, _| |
303 |
| - defined, tested = redis.respond_to?(name), log[">> #{name.upcase}"] |
304 |
| - |
305 |
| - next if defined && tested |
306 |
| - |
307 |
| - report << name |
308 |
| - report << (defined ? yes : no) |
309 |
| - report << (tested ? yes : no) |
310 |
| - end |
311 |
| - |
312 |
| - IO.popen("rs 0 3", "w") do |io| |
313 |
| - io.puts report.join("\n") |
314 |
| - end |
315 |
| - end |
316 |
| -end |
0 commit comments