Permalink
Browse files

Autorun uses Turn's runner classes.

  • Loading branch information...
1 parent 4e659c8 commit 21ae2bc9d4a654d32d21b3debdee2004bb432ce6 @trans trans committed Aug 6, 2011
File renamed without changes.
@@ -1,7 +1,9 @@
require 'minitest/unit'
require 'turn'
-MiniTest::Unit.use_natural_language_case_names = true
+Turn.config do |c|
+ c.natural = true
+end
class SampleCase1 < MiniTest::Unit::TestCase
def test_sample_pass1
@@ -15,7 +17,7 @@ def test_sample_fail1
assert_equal(1,2)
end
def test_sample_fail2
- assert_include(1,[])
+ assert_includes(1,[])
end
def test_sample_error1
@@ -2,162 +2,7 @@
require 'minitest/spec'
#require 'rubygems'
require 'turn/colorize'
+require 'turn/controller'
+require 'turn/runners/minirunner'
-class MiniTest::Unit
- PADDING_SIZE = 4
-
- @@use_natural_language_case_names = false
- def self.use_natural_language_case_names=(boolean)
- @use_natural_language_case_names = boolean
- end
-
- def self.use_natural_language_case_names?
- @use_natural_language_case_names
- end
-
-
- def run(args = [])
- @verbose = true
- options = args.getopts("n:t", "name:", "trace")
- filter = if name = options["n"] || options["name"]
- if name =~ /\/(.*)\//
- Regexp.new($1)
- elsif MiniTest::Unit.use_natural_language_case_names?
- # Turn 'sample error1' into 'test_sample_error1'
- name[0..4] == "test_" ? name.gsub(" ", "_") : "test_" + name.gsub(" ", "_")
- else
- name
- end
- else
- /./ # anything - ^test_ already filtered by #tests
- end
-
- @trace = options['t'] || options['trace']
-
- @@out.puts "Loaded suite #{$0.sub(/\.rb$/, '')}\nStarted"
-
- start = Time.now
- run_test_suites filter
-
- @@out.puts
- @@out.puts "Finished in #{'%.6f' % (Time.now - start)} seconds."
-
- @@out.puts
-
- @@out.print "%d tests, " % test_count
- @@out.print "%d assertions, " % assertion_count
- @@out.print Turn::Colorize.fail("%d failures, " % failures)
- @@out.print Turn::Colorize.error("%d errors, " % errors)
- @@out.puts Turn::Colorize.skip("%d skips" % skips)
-
- return failures + errors if @test_count > 0 # or return nil...
- end
-
- # Overwrite #run_test_suites so that it prints out reports
- # as errors are generated.
- def run_test_suites(filter = /./)
- @test_count, @assertion_count = 0, 0
- old_sync, @@out.sync = @@out.sync, true if @@out.respond_to? :sync=
- TestCase.test_suites.each do |suite|
- test_cases = suite.test_methods.grep(filter)
- if test_cases.size > 0
- @@out.print "\n#{suite}:\n"
- end
-
- test_cases.each do |test|
- inst = suite.new test
- inst._assertions = 0
-
- t = Time.now
-
- @broken = nil
-
- @@out.print(case run_testcase(inst, self)
- when :pass
- @broken = false
- Turn::Colorize.pass(pad_with_size "PASS")
- when :error
- @broken = true
- Turn::Colorize.error(pad_with_size "ERROR")
- when :fail
- @broken = true
- Turn::Colorize.fail(pad_with_size "FAIL")
- when :skip
- @broken = false
- Turn::Colorize.skip(pad_with_size "SKIP")
- end)
-
-
- @@out.print MiniTest::Unit.use_natural_language_case_names? ?
- " #{test.gsub("test_", "").gsub(/_/, " ")}" : " #{test}"
- @@out.print " (%.2fs) " % (Time.now - t)
-
- if @broken
- @@out.puts
-
- report = @report.last
- @@out.puts pad(report[:message], 10)
-
- trace = MiniTest::filter_backtrace(report[:exception].backtrace)
- if @trace
- @@out.print trace.map{|t| pad(t, 10) }.join("\n")
- else
- @@out.print pad(trace.first, 10)
- end
-
- @@out.puts
- end
-
- @@out.puts
- @test_count += 1
- @assertion_count += inst._assertions
- end
- end
- @@out.sync = old_sync if @@out.respond_to? :sync=
- [@test_count, @assertion_count]
- end
-
- def pad(str, size=PADDING_SIZE)
- " " * size + str
- end
-
- def pad_with_size(str)
- pad("%5s" % str)
- end
-
- # Overwrite #puke method so that is stores a hash
- # with :message and :exception keys.
- def puke(klass, meth, e)
- result = nil
- msg = case e
- when MiniTest::Skip
- @skips += 1
- result = :skip
- e.message
- when MiniTest::Assertion
- @failures += 1
- result = :fail
- e.message
- else
- @errors += 1
- result = :error
- "#{e.class}: #{e.message}\n"
- end
-
- @report << {:message => msg, :exception => e}
- result
- end
-
-private
- # A wrapper over MiniTest::Unit::TestCase.run() that returns
- # :pass whenever the test succeeds (i.e. run() returns "" or ".")
- def run_testcase(testcase, runner)
- original_result = testcase.run(runner)
- if original_result == "" || original_result == "."
- :pass
- else
- original_result
- end
- end
-end
-
+MiniTest::Unit.runner = Turn::MiniRunner.new
@@ -0,0 +1,163 @@
+require 'minitest/unit'
+require 'minitest/spec'
+#require 'rubygems'
+require 'turn/colorize'
+
+class MiniTest::Unit
+ PADDING_SIZE = 4
+
+ @@use_natural_language_case_names = false
+ def self.use_natural_language_case_names=(boolean)
+ @use_natural_language_case_names = boolean
+ end
+
+ def self.use_natural_language_case_names?
+ @use_natural_language_case_names
+ end
+
+
+ def run(args = [])
+ @verbose = true
+ options = args.getopts("n:t", "name:", "trace")
+ filter = if name = options["n"] || options["name"]
+ if name =~ /\/(.*)\//
+ Regexp.new($1)
+ elsif MiniTest::Unit.use_natural_language_case_names?
+ # Turn 'sample error1' into 'test_sample_error1'
+ name[0..4] == "test_" ? name.gsub(" ", "_") : "test_" + name.gsub(" ", "_")
+ else
+ name
+ end
+ else
+ /./ # anything - ^test_ already filtered by #tests
+ end
+
+ @trace = options['t'] || options['trace']
+
+ @@out.puts "Loaded suite #{$0.sub(/\.rb$/, '')}\nStarted"
+
+ start = Time.now
+ run_test_suites filter
+
+ @@out.puts
+ @@out.puts "Finished in #{'%.6f' % (Time.now - start)} seconds."
+
+ @@out.puts
+
+ @@out.print "%d tests, " % test_count
+ @@out.print "%d assertions, " % assertion_count
+ @@out.print Turn::Colorize.fail("%d failures, " % failures)
+ @@out.print Turn::Colorize.error("%d errors, " % errors)
+ @@out.puts Turn::Colorize.skip("%d skips" % skips)
+
+ return failures + errors if @test_count > 0 # or return nil...
+ end
+
+ # Overwrite #run_test_suites so that it prints out reports
+ # as errors are generated.
+ def run_test_suites(filter = /./)
+ @test_count, @assertion_count = 0, 0
+ old_sync, @@out.sync = @@out.sync, true if @@out.respond_to? :sync=
+ TestCase.test_suites.each do |suite|
+ test_cases = suite.test_methods.grep(filter)
+ if test_cases.size > 0
+ @@out.print "\n#{suite}:\n"
+ end
+
+ test_cases.each do |test|
+ inst = suite.new test
+ inst._assertions = 0
+
+ t = Time.now
+
+ @broken = nil
+
+ @@out.print(case run_testcase(inst, self)
+ when :pass
+ @broken = false
+ Turn::Colorize.pass(pad_with_size "PASS")
+ when :error
+ @broken = true
+ Turn::Colorize.error(pad_with_size "ERROR")
+ when :fail
+ @broken = true
+ Turn::Colorize.fail(pad_with_size "FAIL")
+ when :skip
+ @broken = false
+ Turn::Colorize.skip(pad_with_size "SKIP")
+ end)
+
+
+ @@out.print MiniTest::Unit.use_natural_language_case_names? ?
+ " #{test.gsub("test_", "").gsub(/_/, " ")}" : " #{test}"
+ @@out.print " (%.2fs) " % (Time.now - t)
+
+ if @broken
+ @@out.puts
+
+ report = @report.last
+ @@out.puts pad(report[:message], 10)
+
+ trace = MiniTest::filter_backtrace(report[:exception].backtrace)
+ if @trace
+ @@out.print trace.map{|t| pad(t, 10) }.join("\n")
+ else
+ @@out.print pad(trace.first, 10)
+ end
+
+ @@out.puts
+ end
+
+ @@out.puts
+ @test_count += 1
+ @assertion_count += inst._assertions
+ end
+ end
+ @@out.sync = old_sync if @@out.respond_to? :sync=
+ [@test_count, @assertion_count]
+ end
+
+ def pad(str, size=PADDING_SIZE)
+ " " * size + str
+ end
+
+ def pad_with_size(str)
+ pad("%5s" % str)
+ end
+
+ # Overwrite #puke method so that is stores a hash
+ # with :message and :exception keys.
+ def puke(klass, meth, e)
+ result = nil
+ msg = case e
+ when MiniTest::Skip
+ @skips += 1
+ result = :skip
+ e.message
+ when MiniTest::Assertion
+ @failures += 1
+ result = :fail
+ e.message
+ else
+ @errors += 1
+ result = :error
+ "#{e.class}: #{e.message}\n"
+ end
+
+ @report << {:message => msg, :exception => e}
+ result
+ end
+
+private
+ # A wrapper over MiniTest::Unit::TestCase.run() that returns
+ # :pass whenever the test succeeds (i.e. run() returns "" or ".")
+ def run_testcase(testcase, runner)
+ original_result = testcase.run(runner)
+ if original_result == "" || original_result == "."
+ :pass
+ else
+ original_result
+ end
+ end
+end
+
Oops, something went wrong.

0 comments on commit 21ae2bc

Please sign in to comment.