lib/rgot/m.rb in rgot-0.1.4 vs lib/rgot/m.rb in rgot-0.1.5
- old
+ new
@@ -1,7 +1,8 @@
require 'stringio'
require 'etc'
+require 'timeout'
module Rgot
class M
class Options < Struct.new(
:bench,
@@ -43,11 +44,11 @@
}
if !test_ok || !example_ok
puts "FAIL"
return 1
end
- puts "PASS" if Rgot.verbose?
+ puts "PASS"
run_benchmarks
0
end
private
@@ -55,11 +56,11 @@
def run_tests
ok = true
@tests.each do |test|
t = T.new(test.module, test.name.to_sym)
if Rgot.verbose?
- puts "=== RUN #{test.name}"
+ puts "=== RUN #{test.name}"
end
t.run
t.report
if t.failed?
ok = false
@@ -103,26 +104,33 @@
def run_examples
ok = true
@examples.each do |example|
if Rgot.verbose?
- puts "=== RUN #{example.name}"
+ puts "=== RUN #{example.name}"
end
+
+ start = Rgot.now
example.module.extend(example.module)
method = example.module.instance_method(example.name).bind(example.module)
out, err = capture do
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}
+
+ duration = Rgot.now - start
if e && e.output.strip != out.strip
+ printf("--- FAIL: %s (%.2fs)\n", e.name, duration)
ok = false
puts "got:"
puts out.strip
puts "want:"
puts e.output.strip
+ elsif Rgot.verbose?
+ printf("--- PASS: %s (%.2fs)\n", e.name, duration)
end
end
ok
end