Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Autorun uses Turn's runner classes.

  • Loading branch information...
commit 21ae2bc9d4a654d32d21b3debdee2004bb432ce6 1 parent 4e659c8
@trans trans authored
View
0  README.rdoc → README.md
File renamed without changes
View
6 demo/test_autorun_minitest.rb
@@ -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
View
161 lib/turn/autorun/minitest.rb
@@ -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
View
163 lib/turn/autorun/minitest0.rb
@@ -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
+
View
118 lib/turn/autorun/testunit.rb
@@ -1,116 +1,8 @@
-require 'test/unit/ui/console/testrunner'
+#require 'test/unit/ui/console/testrunner'
require 'turn/colorize'
+require 'turn/controller'
+require 'turn/runners/testrunner'
-module ::Test::Unit
-module UI
-module Console
- class TestRunner
- include Turn::Colorize
-
- # 1.x of test/unut used @io, where as 2.x uses @output.
- def turn_out
- @turn_out ||= (@io || @output)
- end
-
- alias :t_attach_to_mediator :attach_to_mediator
- def attach_to_mediator
- @mediator.add_listener(TestRunnerMediator::STARTED, &method(:t_started))
- @mediator.add_listener(TestRunnerMediator::FINISHED, &method(:t_finished))
- @mediator.add_listener(TestCase::STARTED, &method(:t_test_started))
- @mediator.add_listener(TestCase::FINISHED, &method(:t_test_finished))
- @mediator.add_listener(TestResult::FAULT, &method(:t_fault))
- turn_out.sync = true
- @t_cur_file, @t_fault = nil
- end
-
- def t_started( result )
- @t_result = result
- end
-
- def t_finished( elapsed_time )
- failure = @t_result.failure_count
- error = @t_result.error_count
- total = @t_result.run_count
- pass = total - failure - error
-
- bar = '=' * 78
- if COLORIZE
- bar = if pass == total then ::ANSI::Code.green{bar}
- else ::ANSI::Code.red{bar} end
- end
-
- turn_out.puts bar
- turn_out.puts " pass: %d, fail: %d, error: %d" % [pass, failure, error]
- turn_out.puts " total: %d tests with %d assertions in #{elapsed_time} seconds" % [total, @t_result.assertion_count]
- turn_out.puts bar
- end
-
- def t_test_started( name )
- method, file = name.scan(%r/^([^\(]+)\(([^\)]+)\)/o).flatten!
- if @t_cur_file != file
- @t_cur_file = file
- file = COLORIZE ? ::ANSI::Code.yellow{file} : file
- turn_out.puts file
- end
- turn_out.print " %-69s" % method
- end
-
- def t_test_finished( name )
- turn_out.puts " #{PASS}" unless @t_fault
- @t_fault = false
- end
-
- def t_fault( fault )
- @t_fault = true
- msg = "\t"
-
- case fault
- when ::Test::Unit::Error
- turn_out.puts ERROR
- msg << fault.to_s.split("\n")[2..-1].join("\n\t")
- when ::Test::Unit::Failure
- test_name = underscore(fault.test_name.match(/\((.*)\)/)[1])
- better_location = fault.location.detect{|line|line.include?(test_name)} || fault.location[0]
- turn_out.puts " #{FAIL}"
- msg << better_location.to_s << "\n\t"
- msg << fault.message.gsub("\n","\n\t")
- end
-
- msg = ::ANSI::Code.magenta{msg} if COLORIZE
- turn_out.puts msg
- end
-
- private
-
- # Taken from ActiveSupport::Inflector
- def underscore(camel_cased_word)
- word = camel_cased_word.to_s.dup
- word.gsub!(/::/, '/')
- word.gsub!(/([A-Z]+)([A-Z][a-z])/,'\1_\2')
- word.gsub!(/([a-z\d])([A-Z])/,'\1_\2')
- word.tr!("-", "_")
- word.downcase!
- word
- end
-
- def setup_mediator
- @mediator = create_mediator(@suite)
- suite_name = @suite.to_s
- if ( @suite.kind_of?(Module) )
- suite_name = @suite.name
- end
- msg = rails? ? "\n" : "Loaded suite #{suite_name}" #always same in rails so scrap it
- output(msg)
- end
-
- def rails?
- $:.to_s.include? "rails"
- end
-
-
- end
-end
+Test::Unit::AutoRunner::RUNNERS[:console] = proc do |r|
+ Turn::TestRunner
end
-end
-
-# EOF
View
116 lib/turn/autorun/testunit0.rb
@@ -0,0 +1,116 @@
+require 'test/unit/ui/console/testrunner'
+require 'turn/colorize'
+
+module ::Test::Unit
+module UI
+module Console
+ class TestRunner
+ include Turn::Colorize
+
+ # 1.x of test/unut used @io, where as 2.x uses @output.
+ def turn_out
+ @turn_out ||= (@io || @output)
+ end
+
+ alias :t_attach_to_mediator :attach_to_mediator
+ def attach_to_mediator
+ @mediator.add_listener(TestRunnerMediator::STARTED, &method(:t_started))
+ @mediator.add_listener(TestRunnerMediator::FINISHED, &method(:t_finished))
+ @mediator.add_listener(TestCase::STARTED, &method(:t_test_started))
+ @mediator.add_listener(TestCase::FINISHED, &method(:t_test_finished))
+ @mediator.add_listener(TestResult::FAULT, &method(:t_fault))
+ turn_out.sync = true
+ @t_cur_file, @t_fault = nil
+ end
+
+ def t_started( result )
+ @t_result = result
+ end
+
+ def t_finished( elapsed_time )
+ failure = @t_result.failure_count
+ error = @t_result.error_count
+ total = @t_result.run_count
+ pass = total - failure - error
+
+ bar = '=' * 78
+ if COLORIZE
+ bar = if pass == total then ::ANSI::Code.green{bar}
+ else ::ANSI::Code.red{bar} end
+ end
+
+ turn_out.puts bar
+ turn_out.puts " pass: %d, fail: %d, error: %d" % [pass, failure, error]
+ turn_out.puts " total: %d tests with %d assertions in #{elapsed_time} seconds" % [total, @t_result.assertion_count]
+ turn_out.puts bar
+ end
+
+ def t_test_started( name )
+ method, file = name.scan(%r/^([^\(]+)\(([^\)]+)\)/o).flatten!
+ if @t_cur_file != file
+ @t_cur_file = file
+ file = COLORIZE ? ::ANSI::Code.yellow{file} : file
+ turn_out.puts file
+ end
+ turn_out.print " %-69s" % method
+ end
+
+ def t_test_finished( name )
+ turn_out.puts " #{PASS}" unless @t_fault
+ @t_fault = false
+ end
+
+ def t_fault( fault )
+ @t_fault = true
+ msg = "\t"
+
+ case fault
+ when ::Test::Unit::Error
+ turn_out.puts ERROR
+ msg << fault.to_s.split("\n")[2..-1].join("\n\t")
+ when ::Test::Unit::Failure
+ test_name = underscore(fault.test_name.match(/\((.*)\)/)[1])
+ better_location = fault.location.detect{|line|line.include?(test_name)} || fault.location[0]
+ turn_out.puts " #{FAIL}"
+ msg << better_location.to_s << "\n\t"
+ msg << fault.message.gsub("\n","\n\t")
+ end
+
+ msg = ::ANSI::Code.magenta{msg} if COLORIZE
+ turn_out.puts msg
+ end
+
+ private
+
+ # Taken from ActiveSupport::Inflector
+ def underscore(camel_cased_word)
+ word = camel_cased_word.to_s.dup
+ word.gsub!(/::/, '/')
+ word.gsub!(/([A-Z]+)([A-Z][a-z])/,'\1_\2')
+ word.gsub!(/([a-z\d])([A-Z])/,'\1_\2')
+ word.tr!("-", "_")
+ word.downcase!
+ word
+ end
+
+ def setup_mediator
+ @mediator = create_mediator(@suite)
+ suite_name = @suite.to_s
+ if ( @suite.kind_of?(Module) )
+ suite_name = @suite.name
+ end
+ msg = rails? ? "\n" : "Loaded suite #{suite_name}" #always same in rails so scrap it
+ output(msg)
+ end
+
+ def rails?
+ $:.to_s.include? "rails"
+ end
+
+
+ end
+end
+end
+end
+
+# EOF
View
4 lib/turn/command.rb
@@ -214,7 +214,7 @@ def main(*argv)
tests = ARGV.empty? ? nil : ARGV.dup
- controller = Turn::Controller.new do |c|
+ config = Turn::Configuration.new do |c|
c.live = live
c.log = log
c.loadpath = loadpath
@@ -228,6 +228,8 @@ def main(*argv)
c.trace = trace
end
+ controller = Turn::Controller.new(config)
+
result = controller.start
if result
View
103 lib/turn/controller.rb
@@ -6,12 +6,19 @@ module Turn
require 'turn/components/case.rb'
require 'turn/components/method.rb'
- # = Controller
+ # Configure Turn
+ def self.config(&block)
+ @config ||= Configuration.new
+ block.call(@config) if block
+ @config
+ end
+
+ #
#
#--
# TODO: Add support to test run loggging.
#++
- class Controller
+ class Configuration
# List of if file names or glob pattern of tests to run.
attr_accessor :tests
@@ -54,8 +61,12 @@ class Controller
# Enable full backtrace
attr_accessor :trace
+ # Use natural language case names.
+ attr_accessor :natural
+
def verbose? ; @verbose ; end
def live? ; @live ; end
+ def natural? ; @natural ; end
private
@@ -66,15 +77,19 @@ def initialize
#
def initialize_defaults
- @loadpath ||= ['lib']
- @tests ||= ["test/**/{test,}*{,test}.rb"]
- @exclude ||= []
- @requires ||= []
- @live ||= false
- @log ||= true
- #@format ||= nil
+ @loadpath ||= ['lib']
+ @tests ||= ["test/**/{test,}*{,test}.rb"]
+ @exclude ||= []
+ @requires ||= []
+ @live ||= false
+ @log ||= true
+ #@format ||= nil
#@runner ||= RUBY_VERSION >= "1.9" ? MiniRunner : TestRunner
- @pattern ||= /.*/
+ @matchcase ||= nil
+ @pattern ||= /.*/
+ @natural ||= false
+
+ @files = nil # reset files just in case
end
# Collect test configuation.
@@ -137,59 +152,86 @@ def files
ex = ex.flatten.reject{ |f| File.directory?(f) }
(fs - ex).uniq.map{ |f| File.expand_path(f) }
- )
+ ).flatten
end
- def start
- @files = nil # reset files just in case
-
- if files.empty?
- $stderr.puts "No tests."
- return
- end
-
- testrun = runner.new(self)
-
- testrun.start
+ # TODO: Better name ?
+ def suite_name
+ files.map{ |path| File.dirname(path).sub(Dir.pwd+'/','') }.uniq.join(',')
end
# Select reporter based on output mode.
def reporter
@reporter ||= (
+ opts = { :trace=>trace, :natural=>natural? }
case format
when :marshal
require 'turn/reporters/marshal_reporter'
- Turn::MarshalReporter.new($stdout)
+ Turn::MarshalReporter.new($stdout, opts)
when :progress
require 'turn/reporters/progress_reporter'
- Turn::ProgressReporter.new($stdout)
+ Turn::ProgressReporter.new($stdout, opts)
when :dotted
require 'turn/reporters/dot_reporter'
- Turn::DotReporter.new($stdout, :trace => @trace)
+ Turn::DotReporter.new($stdout, opts)
when :pretty
require 'turn/reporters/pretty_reporter'
- Turn::PrettyReporter.new($stdout, :trace => @trace)
+ Turn::PrettyReporter.new($stdout, opts)
when :cue
require 'turn/reporters/cue_reporter'
- Turn::CueReporter.new($stdout)
+ Turn::CueReporter.new($stdout, opts)
else
require 'turn/reporters/outline_reporter'
- Turn::OutlineReporter.new($stdout, :trace => @trace)
+ Turn::OutlineReporter.new($stdout, opts)
end
)
end
+ end
+
+ # = Controller
+ #
+ class Controller
+
+ #
+ def initialize(config=Turn.config)
+ @config = config
+ end
+
+ #
+ attr :config
+
+ #
+ def start
+ if config.files.empty?
+ $stderr.puts "No tests."
+ return
+ end
+
+ setup
+
+ testrun = runner.new
+ testrun.start
+ end
+
+ #
+ def setup
+ config.loadpath.each{ |path| $: << path } unless live?
+ config.requires.each{ |path| require(path) }
+ config.files.each{ |path| require(path) }
+ end
+
# # Insatance of Runner, selected based on format and runmode.
def runner
@runner ||= (
- case framework
+ case config.framework
when :minitest
require 'turn/runners/minirunner'
else
require 'turn/runners/testrunner'
end
- case runmode
+ case config.runmode
when :marshal
if framework == :minitest
Turn::MiniRunner
@@ -215,4 +257,3 @@ def runner
end
end
-
View
5 lib/turn/reporter.rb
@@ -19,8 +19,9 @@ class Reporter
attr :io
def initialize(io, opts={})
- @io = io || $stdout
- @trace = opts[:trace]
+ @io = io || $stdout
+ @trace = opts[:trace]
+ @natural = opts[:natural]
end
# These methods are called in the process of running the tests.
View
9 lib/turn/reporters/outline_reporter.rb
@@ -33,7 +33,14 @@ def start_test(test)
# @file = test.file
# io.puts(test.file)
#end
- io.print " %-69s" % test.name
+
+ name = if @natural
+ " #{test.name.gsub("test_", "").gsub(/_/, " ")}"
+ else
+ " #{test.name}"
+ end
+
+ io.print " %-69s" % name
@stdout.rewind
@stderr.rewind
View
70 lib/turn/runners/minirunner.rb
@@ -9,40 +9,13 @@
module Turn
- # = MiniTest TestRunner
+ # Turn's MiniTest test runner class.
#
class MiniRunner < ::MiniTest::Unit
- # Override initialize to take controller argument.
- def initialize(controller)
- @turn_controller = controller
-
- controller.loadpath.each{ |path| $: << path } unless controller.live?
- controller.requires.each{ |path| require(path) }
-
- [controller.files].flatten.each{ |path| require(path) }
-
- files = [controller.files].flatten
- files.each{ |path| require(path) }
-
- # TODO: Better name ?
- @turn_suite_name = files.map{ |path| File.dirname(path).sub(Dir.pwd+'/','') }.uniq.join(',')
-
- #sub_suites = []
- #ObjectSpace.each_object(Class) do |klass|
- # if(Test::Unit::TestCase > klass)
- # sub_suites << klass.suite
- # end
- #end
- #suite = Test::Unit::TestSuite.new('') # FIXME: Name?
- #sub_suites.sort_by{|s|s.name}.each{|s| suite << s}
-
- #suite.tests.each do |c|
- # pattern = controller.pattern
- # c.tests.reject! { |t| pattern !~ t.method_name }
- #end
-
- @turn_logger = controller.reporter
+ #
+ def initialize
+ @turn_config = Turn.config
super()
@@ -51,6 +24,11 @@ def initialize(controller)
@@out = ::StringIO.new
end
+ #
+ def turn_reporter
+ @turn_config.reporter
+ end
+
# Turn calls this method to start the test run.
def start(args=[])
# minitest changed #run in 6023c879cf3d5169953e on April 6th, 2011
@@ -64,18 +42,18 @@ def start(args=[])
# Override #_run_suite to setup Turn.
def _run_suites suites, type
- @turn_suite = Turn::TestSuite.new(@turn_suite_name)
+ @turn_suite = Turn::TestSuite.new(@turn_config.suite_name)
@turn_suite.size = ::MiniTest::Unit::TestCase.test_suites.size
- @turn_logger.start_suite(@turn_suite)
+ turn_reporter.start_suite(@turn_suite)
- if @turn_controller.matchcase
- suites = suites.select{ |suite| @turn_controller.matchcase =~ suite.name }
+ if @turn_config.matchcase
+ suites = suites.select{ |suite| @turn_config.matchcase =~ suite.name }
end
result = suites.map { |suite| _run_suite(suite, type) }
- @turn_logger.finish_suite(@turn_suite)
+ turn_reporter.finish_suite(@turn_suite)
return result
end
@@ -85,20 +63,20 @@ def _run_suite suite, type
# suites are cases in minitest
@turn_case = @turn_suite.new_case(suite.name)
- filter = @turn_controller.pattern || /./
+ filter = @turn_config.pattern || /./
suite.send("#{type}_methods").grep(filter).each do |test|
@turn_case.new_test(test)
end
- @turn_logger.start_case(@turn_case)
+ turn_reporter.start_case(@turn_case)
header = "#{type}_suite_header"
puts send(header, suite) if respond_to? header
assertions = @turn_case.tests.map do |test|
@turn_test = test
- @turn_logger.start_test(@turn_test)
+ turn_reporter.start_test(@turn_test)
inst = suite.new(test.name) #method
inst._assertions = 0
@@ -106,17 +84,17 @@ def _run_suite suite, type
result = inst.run self
if result == "."
- @turn_logger.pass
+ turn_reporter.pass
end
- @turn_logger.finish_test(@turn_test)
+ turn_reporter.finish_test(@turn_test)
inst._assertions
end
@turn_case.count_assertions = assertions.inject(0) { |sum, n| sum + n }
- @turn_logger.finish_case(@turn_case)
+ turn_reporter.finish_case(@turn_case)
return assertions.size, assertions.inject(0) { |sum, n| sum + n }
end
@@ -126,17 +104,18 @@ def puke(klass, meth, err)
case err
when MiniTest::Skip
@turn_test.skip!
- @turn_logger.skip #(e)
+ turn_reporter.skip #(e)
when MiniTest::Assertion
@turn_test.fail!(err)
- @turn_logger.fail(err)
+ turn_reporter.fail(err)
else
@turn_test.error!(err)
- @turn_logger.error(err)
+ turn_reporter.error(err)
end
super(klass, meth, err)
end
+=begin
# To maintain compatibility with old versions of MiniTest.
#
# Hey, Ryan Davis wrote this code!
@@ -166,6 +145,7 @@ def run(args=[])
end
end
+=end
end
View
27 lib/turn/runners/testrunner.rb
@@ -14,22 +14,20 @@ class Test::Unit::Failure
module Turn
- # = TestUnit TestRunner
+ # Turn's Test::Unit console test runner.
#
class TestRunner < ::Test::Unit::UI::Console::TestRunner
- def initialize(controller)
- output_level = 2 # 2-NORMAL 3-VERBOSE
+ #
+ def initialize(suite, output_level, stdout=$stdout)
+ turn_config = Turn.config
- controller.loadpath.each{ |path| $: << path } unless controller.live?
- controller.requires.each{ |path| require(path) }
+ #output_level = 2 # 2-NORMAL 3-VERBOSE
- files = [controller.files].flatten
- files.each{ |path| require(path) }
-
- # TODO: Better name ?
- name = files.map{ |path| File.dirname(path).sub(Dir.pwd+'/','') }.uniq.join(',')
+ name = turn_config.suite_name
+ # TODO: instead of building up a new suite, filter the suite
+ # passed into initialize.
sub_suites = []
ObjectSpace.each_object(Class) do |klass|
if(Test::Unit::TestCase > klass)
@@ -38,8 +36,8 @@ def initialize(controller)
end
suite = Test::Unit::TestSuite.new(name)
- matchcase = controller.matchcase
- pattern = controller.pattern
+ matchcase = turn_config.matchcase
+ pattern = turn_config.pattern
if matchcase
sub_suites = sub_suites.select{|s| matchcase =~ s.name}
@@ -50,9 +48,9 @@ def initialize(controller)
c.tests.reject!{ |t| pattern !~ t.method_name }
end
- @t_reporter = controller.reporter
+ @t_reporter = turn_config.reporter
- super(suite, output_level, $stdout)
+ super(suite, output_level, stdout)
end
# Is this needed?
@@ -168,4 +166,3 @@ def setup_mediator
end#class TestRunner
end#module Turn
-
Please sign in to comment.
Something went wrong with that request. Please try again.