bin/rgot in rgot-0.0.5 vs bin/rgot in rgot-0.1.0
- old
+ new
@@ -1,43 +1,46 @@
#! /usr/bin/env ruby
require 'optparse'
require 'rgot'
-opts = {
- require_paths: []
-}
+opts = Rgot::M::Options.new
+require_paths = []
parser = OptionParser.new do |o|
o.on '-v', '--verbose', "log all tests" do |arg|
- opts[:verbose] = arg
+ Rgot.class_eval{ @chatty = arg }
end
+ o.on '--version', "show Rgot version" do |arg|
+ puts "Rgot v#{Rgot::VERSION}"
+ exit 0
+ end
o.on '--bench [regexp]', "benchmark" do |arg|
unless arg
raise Rgot::OptionError, "missing argument for flag --bench"
end
- opts[:bench] = arg
+ opts.bench = arg
end
o.on '--benchtime [sec]', "benchmark running time" do |arg|
- opts[:benchtime] = arg
+ opts.benchtime = arg
end
o.on '--timeout [sec]', "set timeout sec to testing" do |arg|
- opts[:timeout] = arg
+ opts.timeout = arg
end
- o.on '--cpu [count,...]', "set cpu counts of comma splited" do |arg|
- opts[:cpu] = arg
+ o.on '--cpu [count,...]', "set cpu counts of comma split" do |arg|
+ opts.cpu = arg
end
- o.on '--thread [count,...]', "set thread counts of comma splited" do |arg|
- opts[:thread] = arg
+ o.on '--thread [count,...]', "set thread counts of comma split" do |arg|
+ opts.thread = arg
end
o.on '--require [path]', "load some code before running" do |arg|
- opts[:require_paths] << arg
+ require_paths << arg
end
o.on '--load-path [path]', "Specify $LOAD_PATH directory" do |arg|
$LOAD_PATH.unshift(arg)
end
end
parser.parse!(ARGV)
-opts[:require_paths].each do |path|
+require_paths.each do |path|
require path
end
ARGV.each do |target|
if target
@@ -69,62 +72,65 @@
# exit 1
# end
code = 0
modules.each do |test_module|
- pid = fork {
- tests = []
- benchmarks = []
- examples = []
- main = nil
- methods = test_module.instance_methods.sort
- 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)
+ begin
+ pid = fork {
+ tests = []
+ benchmarks = []
+ examples = []
+ main = nil
+ methods = test_module.instance_methods.sort
+ 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 {
+ 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 sprintf(template, "FAIL", test_module, Rgot.now - duration)
+ end
+ when NilClass
+ # not raise, not exit
else
- # exit 1
+ # any exception
puts sprintf(template, "FAIL", test_module, Rgot.now - duration)
end
- when NilClass
- # not raise, not exit
+ }
+ 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
+ ensure
+ _, status = Process.waitpid2(pid)
+ unless status.success?
+ code = 1
end
- }
- _, status = Process.waitpid2(pid)
- unless status.success?
- code = 1
end
end
exit code