lib/rgot/m.rb in rgot-0.1.5 vs lib/rgot/m.rb in rgot-0.2.0
- old
+ new
@@ -10,16 +10,12 @@
:timeout,
:cpu,
:thread,
); end
- # Ruby-2.0.0 wants default value of keyword_argument
- def initialize(tests: nil, benchmarks: nil, examples: nil, opts: Options.new)
- raise ArgumentError, "missing keyword: tests" unless tests
- raise ArgumentError, "missing keyword: benchmarks" unless benchmarks
- raise ArgumentError, "missing keyword: examples" unless examples
- cpu = opts.cpu || "#{Etc.respond_to?(:nprocessors) ? Etc.nprocessors : "1"}"
+ def initialize(tests:, benchmarks:, examples:, opts: Options.new)
+ cpu = opts.cpu || (Etc.respond_to?(:nprocessors) ? Etc.nprocessors : '1').to_s
@cpu_list = cpu.split(',').map { |i|
j = i.to_i
raise Rgot::OptionError, "invalid value #{i.inspect} for --cpu" unless 0 < j
j
}
@@ -36,14 +32,14 @@
def run
test_ok = false
example_ok = false
- Timeout.timeout(@opts.timeout.to_f) {
+ Timeout.timeout(@opts.timeout.to_f) do
test_ok = run_tests
example_ok = run_examples
- }
+ end
if !test_ok || !example_ok
puts "FAIL"
return 1
end
puts "PASS"
@@ -116,10 +112,10 @@
method.call
end
file = method.source_location[0]
r = ExampleParser.new(File.read(file))
r.parse
- e = r.examples.find{|e| e.name == example.name}
+ e = r.examples.find { |e| e.name == example.name }
duration = Rgot.now - start
if e && e.output.strip != out.strip
printf("--- FAIL: %s (%.2fs)\n", e.name, duration)
ok = false