bin/rgot in rgot-0.1.5 vs bin/rgot in rgot-0.2.0
- old
+ new
@@ -4,11 +4,11 @@
opts = Rgot::M::Options.new
require_paths = []
parser = OptionParser.new do |o|
o.on '-v', '--verbose', "log all tests" do |arg|
- Rgot.class_eval{ @chatty = arg }
+ Rgot.class_eval { @chatty = arg }
end
o.on '--version', "show Rgot version" do |arg|
puts "rgot #{Rgot::VERSION} (ruby #{RUBY_VERSION})"
exit 0
end
@@ -40,93 +40,94 @@
parser.parse!(ARGV)
require_paths.each do |path|
require path
end
+testing_files = []
+
if ARGV.empty?
Dir.glob("./**/*_test.rb") do |i|
- require i
+ testing_files << i
end
else
ARGV.each do |target|
if File.file?(target)
- require File.expand_path(target)
+ testing_files << File.expand_path(target)
elsif File.directory?(target)
Dir.glob("./#{target}/**/*_test.rb") do |i|
- require i
+ testing_files << i
end
else
puts target
end
end
end
-modules = Object.constants.select { |c|
- next if c == :FileTest
- /.*Test\z/ =~ c
-}.map{ |c|
- Object.const_get(c)
-}
-
-# if 1 != modules.length
-# puts "can not load module. found #{modules.join(', ')}"
-# exit 1
-# end
-
code = 0
-modules.each do |test_module|
+testing_files.each do |testing_file|
begin
- pid = fork {
- tests = []
- benchmarks = []
- examples = []
- main = nil
- methods = test_module.instance_methods
- methods.grep(/\Atest_/).each do |m|
- if m == :test_main && main.nil?
- main = Rgot::InternalTest.new(test_module, m)
- else
- tests << Rgot::InternalTest.new(test_module, m)
+ pid = fork do
+ require testing_file
+
+ modules = Object.constants.select { |c|
+ next if c == :FileTest
+ /.*Test\z/ =~ c
+ }.map { |c|
+ Object.const_get(c)
+ }
+
+ modules.each do |test_module|
+ tests = []
+ benchmarks = []
+ examples = []
+ main = nil
+ methods = test_module.instance_methods
+ methods.grep(/\Atest_/).each do |m|
+ if m == :test_main && main.nil?
+ main = Rgot::InternalTest.new(test_module, m)
+ else
+ tests << Rgot::InternalTest.new(test_module, m)
+ end
end
- end
- methods.grep(/\Abenchmark_/).each do |m|
- benchmarks << Rgot::InternalBenchmark.new(test_module, m)
- end
+ methods.grep(/\Abenchmark_/).each do |m|
+ benchmarks << Rgot::InternalBenchmark.new(test_module, m)
+ end
- methods.grep(/\Aexample_?/).each do |m|
- examples << Rgot::InternalExample.new(test_module, m)
- end
+ methods.grep(/\Aexample_?/).each do |m|
+ examples << Rgot::InternalExample.new(test_module, m)
+ end
- duration = Rgot.now
- at_exit {
- template = "%s\t%s\t%.3fs"
+ duration = Rgot.now
+ at_exit do
+ template = "%s\t%s\t%.3fs"
- case $!
- when SystemExit
- if $!.success?
- # exit 0
- puts sprintf(template, "ok ", test_module, Rgot.now - duration)
+ case $!
+ when SystemExit
+ if $!.success?
+ # exit 0
+ puts sprintf(template, "ok ", test_module, Rgot.now - duration)
+ else
+ # exit 1
+ puts "exit status #{$!.status}"
+ puts sprintf(template, "FAIL", test_module, Rgot.now - duration)
+ end
+ when NilClass
+ # not raise, not exit
else
- # exit 1
- puts "exit status #{$!.status}"
+ # any exception
puts sprintf(template, "FAIL", test_module, Rgot.now - duration)
end
- when NilClass
- # not raise, not exit
+ end
+ m = Rgot::M.new(tests: tests, benchmarks: benchmarks, examples: examples, opts: opts)
+ if main
+ main.module.extend main.module
+ main.module.instance_method(main.name).bind(main.module).call(m)
else
- # any exception
- puts sprintf(template, "FAIL", test_module, Rgot.now - duration)
+ exit m.run
end
- }
- m = Rgot::M.new(tests: tests, benchmarks: benchmarks, examples: examples, opts: opts)
- if main
- main.module.extend main.module
- main.module.instance_method(main.name).bind(main.module).call(m)
- else
- exit m.run
end
- }
+ end
ensure
_, status = Process.waitpid2(pid)
unless status.success?
code = 1
end