igal / rubychecker

Checks a Ruby interpreter against a suite o,f tests, using a Ruby script

This URL has Read+Write access

rubychecker / rubychecker.rb
52faf3c1 » Igal Koshevoy 2008-07-03 Added ruby version, rubyche... 1 #!/usr/bin/env ruby
2
5fff911c » Igal Koshevoy 2008-07-04 Fixed handling of unknown o... 3 # = RubyChecker - Runs checks on a Ruby interpreter
4 #
5 # == USAGE
6 #
e71dc942 » Igal Koshevoy 2008-07-04 Forked code for Ruby-only v... 7 # rubychecker.rb [options] [suite or suites to run]
5fff911c » Igal Koshevoy 2008-07-04 Fixed handling of unknown o... 8 #
9 # == OPTIONS
10 #
11 # * -t TAG
12 # A tag to include in the filenames of the reports, e.g., a tag of
13 # "p111" may create report files like "rspec_1.1.4_with_p111.log"
14 # * -v
15 # Displays version information and exits.
16 # * -h
17 # Displays this help information and exits.
b301a3cd » Igal Koshevoy 2008-07-04 Abstracted test suites into... 18 # * -F
19 # Don't freshen existing checkouts (skip git pull, svn update, etc).
5fff911c » Igal Koshevoy 2008-07-04 Fixed handling of unknown o... 20 # * -f
21 # Freshens existing checkouts (git pull, svn update, etc).
22 # * -p
23 # Prepares dependencies and exits without running checks.
b301a3cd » Igal Koshevoy 2008-07-04 Abstracted test suites into... 24 # * -n
25 # Dry-run, display commands to execute but don't run them.
5fff911c » Igal Koshevoy 2008-07-04 Fixed handling of unknown o... 26 #
b301a3cd » Igal Koshevoy 2008-07-04 Abstracted test suites into... 27 # == BASIC EXAMPLES
5fff911c » Igal Koshevoy 2008-07-04 Fixed handling of unknown o... 28 #
29 # # Runs test suites against the "ruby" interpreter in your current
30 # # shell's PATH and records them to the "reports" directory:
31 # ./rubychecker.rb
32 #
b301a3cd » Igal Koshevoy 2008-07-04 Abstracted test suites into... 33 # # Run only the test suite for rspec:
34 # ./rubychecker.rb rspec
35 #
36 # # Run only the test suite for rails version 2.1.0 and record the results
37 # # into a report with the tag "p265" in the filenames:
38 # ./rubychecker.rb -t p265 rails=2.1.0
39 #
5fff911c » Igal Koshevoy 2008-07-04 Fixed handling of unknown o... 40 # == COMPLEX EXAMPLE
41 #
42 # # Download, compile and check a Ruby interpreter from SVN:
43 #
44 # rubysvn=$PWD/cache/ruby
45 # rubytmp=$PWD/tmp/ruby
46 # export PATH=$rubytmp/bin:$PATH
47 # mkdir -p cache
48 # svn co http://svn.ruby-lang.org/repos/ruby/branches/ruby_1_8_6 $rubysvn
49 # pushd $rubysvn
50 # autoconf
51 # ./configure --prefix=$rubytmp && make && make install
52 # popd
53 # ./rubychecker.rb -t svn186
54 #
55 # == DEPENDENCIES:
56 # * ruby
57 # * ruby headers
58 # * complete build environment, e.g., gcc, make, etc
59 # * grep
60 # * git
61 # * svn
62 # * unzip
63 # * MySQL headers
64 # * SQLite3 headers
65 # * MySQL server
66 # You'll need to login as DBA and run:
67 # CREATE DATABASE activerecord_unittest;
68 # CREATE DATABASE activerecord_unittest2;
69 # CREATE DATABASE actionwebservice_unittest;
70 # CREATE USER 'rails'@'localhost' IDENTIFIED BY PASSWORD '';
71 # GRANT ALL ON activerecord_unittest.* TO 'rails'@'localhost';
72 # GRANT ALL ON activerecord_unittest2.* TO 'rails'@'localhost';
73 # GRANT ALL ON actionwebservice_unittest.* TO 'rails'@'localhost';
74 # FLUSH PRIVILEGES;
75 #
76 # == WHAT DOESN'T WORK YET:
77 #
78 # * Any OS other than UNIX
79 # * Any Ruby interpreter other than MRI 1.8
80 #
81 # == SOURCE CODE:
82 #
e71dc942 » Igal Koshevoy 2008-07-04 Forked code for Ruby-only v... 83 # http://github.com/igal/rubychecker
5fff911c » Igal Koshevoy 2008-07-04 Fixed handling of unknown o... 84 #
85 # == ISSUE TRACKER:
86 #
87 # http://code.google.com/p/rubychecker
88 #
89 # == LICENSE:
90 #
91 # This program is provided under the same license as Ruby:
92 # http://www.ruby-lang.org/en/LICENSE.txt
93
52faf3c1 » Igal Koshevoy 2008-07-03 Added ruby version, rubyche... 94 require 'fileutils'
95 require 'open-uri'
b301a3cd » Igal Koshevoy 2008-07-04 Abstracted test suites into... 96 require 'pathname'
97 require 'set'
52faf3c1 » Igal Koshevoy 2008-07-03 Added ruby version, rubyche... 98 require 'uri'
99
100 class RubyChecker
b301a3cd » Igal Koshevoy 2008-07-04 Abstracted test suites into... 101 # Version of RubyChecker.
102 VERSION = "r2"
52faf3c1 » Igal Koshevoy 2008-07-03 Added ruby version, rubyche... 103
b301a3cd » Igal Koshevoy 2008-07-04 Abstracted test suites into... 104 # Source URLs for dependencies.
52faf3c1 » Igal Koshevoy 2008-07-03 Added ruby version, rubyche... 105 SOURCES = {
106 :rails => "git://github.com/rails/rails.git",
107 :rspec => "git://github.com/dchelimsky/rspec.git",
108 :rubyspec => "git://github.com/rubyspec/rubyspec.git",
109 :rubygems => "http://rubyforge.org/frs/download.php/38647/rubygems-1.2.0.zip",
110 }
111
b301a3cd » Igal Koshevoy 2008-07-04 Abstracted test suites into... 112 # Gems to install.
52faf3c1 » Igal Koshevoy 2008-07-03 Added ruby version, rubyche... 113 GEMS = %w(
114 diff-lcs
115 heckle
116 hpricot
117 mocha
118 mspec
119 mysql
120 rake
121 rcov
122 sqlite3-ruby
123 syntax
124 )
125
b301a3cd » Igal Koshevoy 2008-07-04 Abstracted test suites into... 126 # Base working directory.
52faf3c1 » Igal Koshevoy 2008-07-03 Added ruby version, rubyche... 127 attr_accessor :base_dir
b301a3cd » Igal Koshevoy 2008-07-04 Abstracted test suites into... 128 # Directory with cached downloads.
52faf3c1 » Igal Koshevoy 2008-07-03 Added ruby version, rubyche... 129 attr_accessor :cache_dir
b301a3cd » Igal Koshevoy 2008-07-04 Abstracted test suites into... 130 # Directory with reports.
52faf3c1 » Igal Koshevoy 2008-07-03 Added ruby version, rubyche... 131 attr_accessor :reports_dir
b301a3cd » Igal Koshevoy 2008-07-04 Abstracted test suites into... 132 # Directory with gems.
52faf3c1 » Igal Koshevoy 2008-07-03 Added ruby version, rubyche... 133 attr_accessor :gems_dir
b301a3cd » Igal Koshevoy 2008-07-04 Abstracted test suites into... 134
135 # Pathname instance for base_dir.
136 attr_accessor :base_path
137 # Pathname instance for cache_dir.
138 attr_accessor :cache_path
139 # Pathname instance for reports_dir.
140 attr_accessor :reports_path
141 # Pathname instance for gems_dir.
142 attr_accessor :gems_path
143
144 # String to tag report filenames with, e.g., "p265".
52faf3c1 » Igal Koshevoy 2008-07-03 Added ruby version, rubyche... 145 attr_accessor :tag
b301a3cd » Igal Koshevoy 2008-07-04 Abstracted test suites into... 146 # Freshen the checked-out files? Defaults to true.
52faf3c1 » Igal Koshevoy 2008-07-03 Added ruby version, rubyche... 147 attr_accessor :freshen
b301a3cd » Igal Koshevoy 2008-07-04 Abstracted test suites into... 148 # Display commands without running them? Defaults to false.
149 attr_accessor :dryrun
52faf3c1 » Igal Koshevoy 2008-07-03 Added ruby version, rubyche... 150
b301a3cd » Igal Koshevoy 2008-07-04 Abstracted test suites into... 151 # Instantiate a new RubyChecker object.
152 #
153 # Options:
154 # * :base_dir => Base working directory to use. Defaults to current directory.
155 # * :tag => String to tag report filenames with, e.g., "p265". Defaults to "current".
156 # * :freshen => Freshen the checked-out files? Defaults to true.
157 # * :dryrun => Display commands without running them? Defaults to false.
52faf3c1 » Igal Koshevoy 2008-07-03 Added ruby version, rubyche... 158 def initialize(opts={})
b301a3cd » Igal Koshevoy 2008-07-04 Abstracted test suites into... 159 @base_dir = File.expand_path(opts[:base_dir] || Dir.pwd)
160 @reports_dir = File.expand_path(File.join(@base_dir, "reports"))
161 @cache_dir = File.expand_path(File.join(@base_dir, "cache"))
162 @gems_dir = File.expand_path(File.join(@cache_dir, "gems"))
163
164 @base_path = Pathname.new(@base_dir)
165 @reports_path = Pathname.new(@reports_dir)
166 @cache_path = Pathname.new(@cache_dir)
167 @gems_path = Pathname.new(@gems_dir)
52faf3c1 » Igal Koshevoy 2008-07-03 Added ruby version, rubyche... 168
b301a3cd » Igal Koshevoy 2008-07-04 Abstracted test suites into... 169 @tag = opts[:tag] || "current"
170 @freshen = opts[:freshen] != false
171 @dryrun = opts[:dryrun] == true || false
52faf3c1 » Igal Koshevoy 2008-07-03 Added ruby version, rubyche... 172 end
173
174 #---[ prepare ]---------------------------------------------------------
175
b301a3cd » Igal Koshevoy 2008-07-04 Abstracted test suites into... 176 # Prepare the environment, by checking out the sources, installing the
177 # RubyGems application, and installing the Gem libraries.
52faf3c1 » Igal Koshevoy 2008-07-03 Added ruby version, rubyche... 178 def prepare
179 prepare_sources
180 prepare_rubygems
181 prepare_gems
182 end
183
b301a3cd » Igal Koshevoy 2008-07-04 Abstracted test suites into... 184 # Prepare directories, by creating them if necessary.
52faf3c1 » Igal Koshevoy 2008-07-03 Added ruby version, rubyche... 185 def prepare_dirs
186 [@reports_dir, @cache_dir, @gems_dir].each do |dir|
187 Dir.mkdir(dir) unless File.directory?(dir)
188 end
189 end
190
b301a3cd » Igal Koshevoy 2008-07-04 Abstracted test suites into... 191 # Prepare sources, download them if necessary.
52faf3c1 » Igal Koshevoy 2008-07-03 Added ruby version, rubyche... 192 def prepare_sources
193 SOURCES.each_pair do |suite, url|
b301a3cd » Igal Koshevoy 2008-07-04 Abstracted test suites into... 194 prepare_source_for(url, @freshen)
52faf3c1 » Igal Koshevoy 2008-07-03 Added ruby version, rubyche... 195 end
196 end
197
b301a3cd » Igal Koshevoy 2008-07-04 Abstracted test suites into... 198 # Download or freshen a download from +url+.
199 def prepare_source_for(url, freshen=true)
52faf3c1 » Igal Koshevoy 2008-07-03 Added ruby version, rubyche... 200 self.prepare_dirs
201 FileUtils.cd(@cache_dir) do
202 uri = URI.parse(url)
203 case uri.scheme
204 when "git"
205 name = File.basename(url, ".git")
206 if File.directory?(name)
b301a3cd » Igal Koshevoy 2008-07-04 Abstracted test suites into... 207 if freshen
52faf3c1 » Igal Koshevoy 2008-07-03 Added ruby version, rubyche... 208 FileUtils.cd(name) do
b301a3cd » Igal Koshevoy 2008-07-04 Abstracted test suites into... 209 run "git checkout -f master"
210 run "git pull --rebase origin master"
211 run "git fetch --tags"
52faf3c1 » Igal Koshevoy 2008-07-03 Added ruby version, rubyche... 212 end
213 end
214 else
b301a3cd » Igal Koshevoy 2008-07-04 Abstracted test suites into... 215 run "git clone #{url}"
52faf3c1 » Igal Koshevoy 2008-07-03 Added ruby version, rubyche... 216 end
217 when "http", "ftp"
218 name = File.basename(url)
219 unless File.exist?(name)
220 File.open(name, "w+") do |writer|
221 open(url) do |reader|
222 writer.write(reader.read)
223 end
224 end
225 end
226 else
227 raise ArgumentError, "Unknown revision control scheme: #{uri.scheme}"
228 end
229 end
230 end
231
b301a3cd » Igal Koshevoy 2008-07-04 Abstracted test suites into... 232 # Prepare RubyGems application, install it if necessary.
233 #
234 # NOTE: This method sets the PATH to provide access to the installed Gem
235 # libraries, so it must be called before the checks run.
52faf3c1 » Igal Koshevoy 2008-07-03 Added ruby version, rubyche... 236 def prepare_rubygems
237 begin
238 require "rubygems"
b301a3cd » Igal Koshevoy 2008-07-04 Abstracted test suites into... 239 # RubyGems is installed
52faf3c1 » Igal Koshevoy 2008-07-03 Added ruby version, rubyche... 240 rescue LoadError
241 # RubyGems needs to be installed
242 FileUtils.cd(@cache_dir) do
243 archive = File.basename(SOURCES[:rubygems])
244 dir = File.basename(archive, ".zip")
245 FileUtils.rm_rf(dir) if File.directory?(dir)
246 # TODO consider using rubyzip?
b301a3cd » Igal Koshevoy 2008-07-04 Abstracted test suites into... 247 run "unzip #{archive}", true
52faf3c1 » Igal Koshevoy 2008-07-03 Added ruby version, rubyche... 248 FileUtils.cd(dir) do
b301a3cd » Igal Koshevoy 2008-07-04 Abstracted test suites into... 249 run "ruby 'setup.rb' --no-ri --no-rdoc", true
52faf3c1 » Igal Koshevoy 2008-07-03 Added ruby version, rubyche... 250 end
251 end
252 end
3de2e7e2 » Igal Koshevoy 2008-07-04 Fixed bug in PATH, it wasn'... 253 ENV["PATH"] = "#{`gem env path`.strip}/bin:#{ENV['PATH']}"
52faf3c1 » Igal Koshevoy 2008-07-03 Added ruby version, rubyche... 254 end
255
b301a3cd » Igal Koshevoy 2008-07-04 Abstracted test suites into... 256 # Prepare Gem libraries, install them if necessary.
257 def prepare_gems(gems=GEMS)
52faf3c1 » Igal Koshevoy 2008-07-03 Added ruby version, rubyche... 258 FileUtils.cd(@gems_dir) do
259 listing = `gem list --local`
b301a3cd » Igal Koshevoy 2008-07-04 Abstracted test suites into... 260 missing = gems.reject{|package| listing.match(/^#{package}\s/)}
261 run "gem install #{missing.join(' ')} --no-ri --no-rdoc", true if missing.size > 0
52faf3c1 » Igal Koshevoy 2008-07-03 Added ruby version, rubyche... 262 end
263 end
264
265 #---[ check ]-----------------------------------------------------------
266
b301a3cd » Igal Koshevoy 2008-07-04 Abstracted test suites into... 267 # Check the +targets+ by running their test suites.
268 #
269 # Arguments:
270 # * targets => String, Tuples, or Array of Strings that are either a word
271 # like "rspec" which represent a test suite's title, or a compound word
272 # like "rspec=1.1.4" which represents a test suite's title and variant.
52faf3c1 » Igal Koshevoy 2008-07-03 Added ruby version, rubyche... 273 def check(*targets)
274 targets.flatten!
b301a3cd » Igal Koshevoy 2008-07-04 Abstracted test suites into... 275
276 suites = Set.new
277
278 if targets.size == 0
279 suites += Suite.suites
280 else
281 targets.each do |target|
282 title, variant = target.split("=")
283 matches = Suite.suites_for(title, variant)
284 if matches.size == 0
285 raise ArgumentError, "Unknown suite: #{target}"
286 else
287 suites += matches
288 end
52faf3c1 » Igal Koshevoy 2008-07-03 Added ruby version, rubyche... 289 end
290 end
291
b301a3cd » Igal Koshevoy 2008-07-04 Abstracted test suites into... 292 suites.each do |suite|
293 suite.new(self).invoke
52faf3c1 » Igal Koshevoy 2008-07-03 Added ruby version, rubyche... 294 end
295 end
296
b301a3cd » Igal Koshevoy 2008-07-04 Abstracted test suites into... 297 #---[ reporting ]-------------------------------------------------------
298
299 # Run the +command+. Displays the command alwasy, but only executes it if
300 # @dryrun is false. If +fatal+ is true, a non-zero exit value from a system
301 # call will cause the program to exit.
302 def run(command, fatal=false)
303 current_path = Pathname.new(Dir.pwd)
304 base2current = current_path.relative_path_from(@base_path)
305 current2reports = @reports_path.relative_path_from(current_path)
306 displayable = "(cd #{base2current} && #{command.gsub(/#{@reports_dir}/, current2reports.to_s)})"
307
308 puts(displayable)
309 unless self.dryrun
310 system(command)
311 if fatal && $?.exitstatus != 0
312 puts "ERROR RUNNING: #{displayable}"
313 exit $?.exitstatus
314 end
52faf3c1 » Igal Koshevoy 2008-07-03 Added ruby version, rubyche... 315 end
316 end
317
b301a3cd » Igal Koshevoy 2008-07-04 Abstracted test suites into... 318 # Create a report file from the results of running the +command+ for the test
319 # suite with the +title+ and +variant+.
320 def create_report_for(command, title, variant)
321 self.run("#{command} 2>&1 | tee #{self.report_filename_for(title, variant)}")
322 end
323
324 # Append to an existing report file the results of running the +command+ for
325 # the test suite with the +title+ and +variant+.
326 def append_report_for(command, title, variant)
327 self.run("#{command} 2>&1 | tee -a #{self.report_filename_for(title, variant)}")
328 end
329
330 # Remove the report for the test suite with the +title+ and +variant.
331 def remove_report_for(title, variant)
332 report = self.report_filename_for(title, variant)
333 File.delete(report) if File.exist?(report)
334 end
335
336 # Return a report filename for the test suite +title+ and +variant+. If the
337 # +variant+ is nil, it's not included in the filename.
338 def report_filename_for(title, variant=nil)
339 return File.join(@reports_dir, "#{title}#{variant ? '_'+variant.to_s : ''}_with_#{@tag}.log")
340 end
341
342 #---[ suite ]-----------------------------------------------------------
343
344 # A test suite hierarchy.
345 class Suite
346 class << self
347 # Set of test suites, as Suite::Base subclasses.
348 attr_accessor :suites
349 end
350 self.suites = Set.new
351
352 # Return an array of test suite titles.
353 def self.suite_titles
354 self.suites.map{|suite| suite.title}
355 end
356
357 # Return an array of suites matching the +title+ and optional +variant+.
358 def self.suites_for(title, variant=nil)
359 self.suites.select{|suite| suite.title == title && (variant ? suite.variant == variant : true)}
360 end
361
362 # Common base for all Suite subclasses.
363 class Base
364 def self.inherited(subclass)
365 # Add this test suite to the registry.
366 Suite.suites << subclass
367
368 subclass.module_eval do
369 class << self
370 # String title of test suite, e.g., "RSpec"
371 attr_accessor :title
372
373 # String variant of test suite, e.g., "1.1.4"
374 attr_accessor :variant
375 end
376
377 # RubyChecker instance
378 attr_accessor :checker
52faf3c1 » Igal Koshevoy 2008-07-03 Added ruby version, rubyche... 379 end
380 end
381
b301a3cd » Igal Koshevoy 2008-07-04 Abstracted test suites into... 382 # Instantiate a new suite subclass using the +checker+ instance.
383 def initialize(checker)
384 self.checker = checker
385 end
386
387 # Invoke the test suite.
388 def invoke
389 raise NotImplementedError, "Author of subclass forgot to implement #invoke"
390 end
391
392 # Return this Suite's title, e.g., "RSpec".
393 def title
394 self.class.title
395 end
396
397 # Return this Suite's variant, e.g., "1.1.4".
398 def variant
399 self.class.variant
400 end
401
402 # Run the +command+ and create a report from its results.
403 def create_report_for(command)
404 checker.create_report_for(command, self.title, self.variant)
405 end
406
407 # Run the +command+ and append its results to a report.
408 def append_report_for(command)
409 checker.append_report_for(command, self.title, self.variant)
410 end
411
412 # Remove an report, if it exists.
413 def remove_report
414 checker.remove_report_for(self.title, self.variant)
415 end
416
417 # Run a +command+.
418 def run(command)
419 checker.run(command)
420 end
421 end
422
423 #---[ suites ]----------------------------------------------------------
424
425 class RubySpec < Base # :nodoc:
426 self.title = "rubyspec"
427 self.variant = "master"
428
429 def invoke
430 FileUtils.cd(File.join(checker.cache_dir, self.title, "1.8")) do
431 create_report_for("mspec .")
432 end
433 end
434 end
435
436 class RSpec < Base # :nodoc:
437 self.title = "rspec"
438 self.variant = "1.1.4"
439
440 def invoke
441 FileUtils.cd(File.join(checker.cache_dir, self.title)) do
442 run "git checkout -f #{self.variant}"
443 create_report_for("rake spec")
444 end
445 end
446 end
447
448 class Rails126 < Base # :nodoc:
449 self.title = "rails"
450 self.variant = "1.2.6"
451
452 def invoke
453 FileUtils.cd(File.join(checker.cache_dir, self.title)) do
454 run "git checkout -f v#{self.variant}"
455 remove_report
456 Dir["*"].select{|path| File.directory?(path)}.each do |dir|
457 FileUtils.cd(dir) do
458 if dir.match(/actionwebservice/)
459 append_report_for("rake build_database")
460 end
461 append_report_for("rake test")
462 end
463 end
52faf3c1 » Igal Koshevoy 2008-07-03 Added ruby version, rubyche... 464 end
465 end
466 end
467
b301a3cd » Igal Koshevoy 2008-07-04 Abstracted test suites into... 468 class Rails202 < Base # :nodoc:
469 self.title = "rails"
470 self.variant = "2.0.2"
52faf3c1 » Igal Koshevoy 2008-07-03 Added ruby version, rubyche... 471
b301a3cd » Igal Koshevoy 2008-07-04 Abstracted test suites into... 472 def invoke
473 FileUtils.cd(File.join(checker.cache_dir, self.title)) do
474 run "git checkout -f v#{self.variant}"
475 create_report_for("rake test")
476 end
477 end
478 end
479
480 class Rails210 < Base # :nodoc:
481 self.title = "rails"
482 self.variant = "2.1.0"
483
484 def invoke
485 FileUtils.cd(File.join(checker.cache_dir, self.title)) do
486 run "git checkout -f v#{self.variant}"
487 create_report_for("rake test")
488 end
489 end
490 end
52faf3c1 » Igal Koshevoy 2008-07-03 Added ruby version, rubyche... 491 end
b301a3cd » Igal Koshevoy 2008-07-04 Abstracted test suites into... 492
52faf3c1 » Igal Koshevoy 2008-07-03 Added ruby version, rubyche... 493 end
494
b301a3cd » Igal Koshevoy 2008-07-04 Abstracted test suites into... 495 #===[ main ]============================================================
496
52faf3c1 » Igal Koshevoy 2008-07-03 Added ruby version, rubyche... 497 if __FILE__ == $0
5fff911c » Igal Koshevoy 2008-07-04 Fixed handling of unknown o... 498 require 'getoptlong'
499 require 'rdoc/usage'
500
b301a3cd » Igal Koshevoy 2008-07-04 Abstracted test suites into... 501 checker = RubyChecker.new
52faf3c1 » Igal Koshevoy 2008-07-03 Added ruby version, rubyche... 502 targets = []
5e05fad1 » Igal Koshevoy 2008-07-04 Fixed --freshen option, it ... 503 prepare_only = false
52faf3c1 » Igal Koshevoy 2008-07-03 Added ruby version, rubyche... 504
5e05fad1 » Igal Koshevoy 2008-07-04 Fixed --freshen option, it ... 505 opts = GetoptLong.new(*[
b301a3cd » Igal Koshevoy 2008-07-04 Abstracted test suites into... 506 ['--dryrun', '-n', GetoptLong::NO_ARGUMENT],
507 ['--freshen', '-f', GetoptLong::NO_ARGUMENT],
508 ['--help', '-h', GetoptLong::NO_ARGUMENT],
509 ['--prepare', '-p', GetoptLong::NO_ARGUMENT],
510 ['--skip-freshen', '-F', GetoptLong::NO_ARGUMENT],
511 ['--tag', '-t', GetoptLong::OPTIONAL_ARGUMENT],
512 ['--version', '-v', GetoptLong::NO_ARGUMENT]
5e05fad1 » Igal Koshevoy 2008-07-04 Fixed --freshen option, it ... 513 ])
52faf3c1 » Igal Koshevoy 2008-07-03 Added ruby version, rubyche... 514
5fff911c » Igal Koshevoy 2008-07-04 Fixed handling of unknown o... 515 begin
516 opts.each do |opt, arg|
517 case opt
b301a3cd » Igal Koshevoy 2008-07-04 Abstracted test suites into... 518 when '--dryrun'
519 checker.dryrun = true
5fff911c » Igal Koshevoy 2008-07-04 Fixed handling of unknown o... 520 when '--freshen'
b301a3cd » Igal Koshevoy 2008-07-04 Abstracted test suites into... 521 checker.freshen = true
5fff911c » Igal Koshevoy 2008-07-04 Fixed handling of unknown o... 522 when '--help'
523 RDoc::usage
524 when '--prepare'
525 prepare_only = true
b301a3cd » Igal Koshevoy 2008-07-04 Abstracted test suites into... 526 when '--skip-freshen'
527 checker.freshen = false
5fff911c » Igal Koshevoy 2008-07-04 Fixed handling of unknown o... 528 when '--tag'
b301a3cd » Igal Koshevoy 2008-07-04 Abstracted test suites into... 529 checker.tag = arg
5fff911c » Igal Koshevoy 2008-07-04 Fixed handling of unknown o... 530 when '--version'
531 puts "rubychecker #{RubyChecker::VERSION}"
532 exit 0
533 end
52faf3c1 » Igal Koshevoy 2008-07-03 Added ruby version, rubyche... 534 end
5fff911c » Igal Koshevoy 2008-07-04 Fixed handling of unknown o... 535 rescue GetoptLong::InvalidOption => e
536 # Error is displayed automatically
537 exit 7
52faf3c1 » Igal Koshevoy 2008-07-03 Added ruby version, rubyche... 538 end
539
540 targets.concat(ARGV)
541
e71dc942 » Igal Koshevoy 2008-07-04 Forked code for Ruby-only v... 542 if targets.first == "README.txt"
543 system "'#{__FILE__}' --help > README.txt"
544 exit 0
545 end
546
b301a3cd » Igal Koshevoy 2008-07-04 Abstracted test suites into... 547 checker.prepare
548 checker.check(*targets) unless prepare_only
52faf3c1 » Igal Koshevoy 2008-07-03 Added ruby version, rubyche... 549 end