Browse files

Turn is now MiniTest only.

  • Loading branch information...
1 parent b7447f2 commit a18059211ff4b41499e314bf10e61be0f52ca255 @trans trans committed Jan 28, 2012
View
0 license/GPLv2.txt → LICENSE-GPL2.txt
File renamed without changes.
View
0 license/MIT-LICENSE.txt → LICENSE-MIT.txt
File renamed without changes.
View
0 license/RUBY-LICENSE.txt → LICENSE-RUBY.txt
File renamed without changes.
View
0 NOTICE.txt → LICENSE.txt
File renamed without changes.
View
13 lib/turn.rb
@@ -1,4 +1,6 @@
-module Turn; end
+#
+module Turn
+end
require 'fileutils'
@@ -10,9 +12,8 @@ module Turn; end
require 'turn/controller'
require 'turn/minitest'
-# TODO: Remove this in turn.rb for v1.0.
-if ENV['autorun']
- warn "Use `require 'turn/autorun'` instead of `require 'turn'` for future versions."
- MiniTest::Unit.autorun
-end
+#if ENV['autorun']
+# warn "Use `require 'turn/autorun'` instead of `require 'turn'` for future versions."
+# MiniTest::Unit.autorun
+#end
View
1 lib/turn/autorun.rb
@@ -1,4 +1,3 @@
require 'turn'
-
MiniTest::Unit.autorun
View
3 lib/turn/autorun/minitest.rb
@@ -1,3 +0,0 @@
-require 'turn/minitest'
-MiniTest::Unit.autorun
-
View
8 lib/turn/autorun/testunit.rb
@@ -1,8 +0,0 @@
-require 'turn/testunit'
-
-Test::Unit::AutoRunner::RUNNERS[:console] = proc do |r|
- Turn::TestRunner
-end
-
-Test::Unit.run = true
-
View
116 lib/turn/autorun/testunit0.rb
@@ -1,116 +0,0 @@
-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
2 lib/turn/autorun/minitest0.rb → lib/turn/autorun0.rb
@@ -1,3 +1,5 @@
+# DEPRECATED
+
require 'minitest/unit'
require 'minitest/spec'
#require 'rubygems'
View
26 lib/turn/controller.rb
@@ -35,32 +35,32 @@ def setup
# Insatance of Runner, selected based on format and runmode.
def runner
@runner ||= (
- case config.framework
- when :minitest
+ #case config.framework
+ #when :minitest
require 'turn/runners/minirunner'
- else
- require 'turn/runners/testrunner'
- end
+ #else
+ # require 'turn/runners/testrunner'
+ #end
case config.runmode
when :marshal
- if config.framework == :minitest
+ #if config.framework == :minitest
Turn::MiniRunner
- else
- Turn::TestRunner
- end
+ #else
+ # Turn::TestRunner
+ #end
when :solo
require 'turn/runners/solorunner'
Turn::SoloRunner
when :cross
require 'turn/runners/crossrunner'
Turn::CrossRunner
else
- if config.framework == :minitest
+ #if config.framework == :minitest
Turn::MiniRunner
- else
- Turn::TestRunner
- end
+ #else
+ # Turn::TestRunner
+ #end
end
)
end
View
5 lib/turn/minitest.rb
@@ -1,4 +1,7 @@
-require 'turn'
+#require 'turn'
+
+# make sure latest verison is used, rather than ruby's built-in
+begin; gem 'minitest'; rescue Exception; end
# we save the developer the trouble of having to load these (TODO: should we?)
require 'minitest/unit'
View
11 lib/turn/reporter.rb
@@ -113,11 +113,12 @@ def naturalized_name(test)
#
def ticktock
- s0 = Time.now - @time
- s = s0.truncate
- f = ((s0 - s) * 100000).to_i
- h, s = s.divmod(60)
- m, s = s.divmod(60)
+ t = Time.now - @time
+ h, t = t.divmod(60)
+ m, t = t.divmod(60)
+ s = t.truncate
+ f = ((t - s) * 1000).to_i
+
"%01d:%02d:%02d:%03d" % [h,m,s,f]
end
end
View
18 lib/turn/reporters/outline_reporter.rb
@@ -3,7 +3,7 @@
module Turn
- # = Outline Reporter (Turn's Original)
+ # Outline Reporter is Turn's Original.
#
#--
# TODO: Should we fit reporter output to width of console?
@@ -21,9 +21,13 @@ def start_suite(suite)
@stdout = StringIO.new
@stderr = StringIO.new
#files = suite.collect{ |s| s.file }.join(' ')
- io.puts "LOADED SUITE #{suite.name}"
- io.puts "SEED #{suite.seed}" if suite.seed
- #io.puts "Started"
+ puts '=' * 78
+ if suite.seed
+ io.puts "SUITE #{suite.name} (SEED #{suite.seed})"
+ else
+ io.puts "SUITE #{suite.name}"
+ end
+ puts '=' * 78
end
#
@@ -38,11 +42,7 @@ def start_test(test)
# io.puts(test.file)
#end
- name = if @natural
- " #{test.name.gsub("test_", "").gsub(/_/, " ")}"
- else
- " #{test.name}"
- end
+ name = naturalized_name(test)
io.print " %-57s" % name
View
2 lib/turn/reporters/progress_reporter.rb
@@ -53,7 +53,7 @@ def finish_suite(suite)
def post_report(suite)
tally = test_tally(suite)
- width = suite.collect{ |tr| tr.name.size }.max
+ width = suite.collect{ |tr| tr.name.to_s.size }.max
headers = [ 'TESTCASE ', ' TESTS ', 'ASSERTIONS', ' FAILURES ', ' ERRORS ' ]
io.puts "\n\n%-#{width}s %10s %10s %10s %10s\n" % headers
View
5 lib/turn/runners/minirunner.rb
@@ -40,8 +40,11 @@ def start(args=[])
# Override #_run_suite to setup Turn.
def _run_suites suites, type
+ # Someone want to explain to me why these are fucking here?
+ suites = suites - [MiniTest::Spec, Test::Unit::TestCase]
+
@turn_suite = Turn::TestSuite.new(@turn_config.suite_name)
- @turn_suite.size = ::MiniTest::Unit::TestCase.test_suites.size # why not just `suites.size` ?
+ @turn_suite.size = suites.size #::MiniTest::Unit::TestCase.test_suites.size
@turn_suite.seed = ::MiniTest::Unit.runner.options[:seed]
turn_reporter.start_suite(@turn_suite)
View
168 lib/turn/runners/testrunner.rb
@@ -1,168 +0,0 @@
-#require 'test/unit'; Test::Unit.run = false
-require 'test/unit/ui/console/testrunner'
-
-#require 'turn/colorize'
-#require 'turn/components/suite.rb'
-#require 'turn/components/case.rb'
-#require 'turn/components/method.rb'
-#require 'turn/reporters/outline_reporter.rb'
-#require 'turn/reporters/progress_reporter.rb'
-
-class Test::Unit::Failure
- alias_method :backtrace, :location
-end
-
-module Turn
-
- # Turn's Test::Unit console test runner.
- #
- class TestRunner < ::Test::Unit::UI::Console::TestRunner
-
- #
- def initialize(suite, output_level, stdout=$stdout)
- turn_config = Turn.config
-
- #output_level = 2 # 2-NORMAL 3-VERBOSE
-
- 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)
- sub_suites << klass.suite
- end
- end
- suite = Test::Unit::TestSuite.new(name)
-
- matchcase = turn_config.matchcase
- pattern = turn_config.pattern
-
- if matchcase
- sub_suites = sub_suites.select{|s| matchcase =~ s.name}
- end
- sub_suites.sort_by{|s|s.name}.each{|s| suite << s}
-
- suite.tests.each do |c|
- c.tests.reject!{ |t| pattern !~ t.method_name }
- end
-
- @t_reporter = turn_config.reporter
-
- super(suite, output_level, stdout)
- end
-
- # Is this needed?
- alias :t_attach_to_mediator :attach_to_mediator
-
- def attach_to_mediator
- @mediator.add_listener(::Test::Unit::UI::TestRunnerMediator::STARTED, &method(:t_started))
- @mediator.add_listener(::Test::Unit::UI::TestRunnerMediator::FINISHED, &method(:t_finished))
- @mediator.add_listener(::Test::Unit::TestSuite::STARTED, &method(:t_case_started))
- @mediator.add_listener(::Test::Unit::TestSuite::FINISHED, &method(:t_case_finished))
- @mediator.add_listener(::Test::Unit::TestCase::STARTED, &method(:t_test_started))
- @mediator.add_listener(::Test::Unit::TestCase::FINISHED, &method(:t_test_finished))
- @mediator.add_listener(::Test::Unit::TestResult::FAULT, &method(:t_fault))
-
- @io.sync = true
-
- @t_result = nil
- @t_fault = nil
-
- @not_first_case = nil
-
- @t_previous_run_count = 0
- @t_previous_error_count = 0
- @t_previous_failure_count = 0
- @t_previous_assertion_count = 0
- end
-
- def t_started(result)
- @t_suite = Turn::TestSuite.new(@suite.name)
- @t_suite.size = @suite.size
- @t_result = result
- @t_reporter.start_suite(@t_suite)
- end
-
- def t_case_started(name)
- # Err.. why is testunit running this on the suite?
- (@not_first_case = true; return) unless @not_first_case
- @t_case = @t_suite.new_case(name)
- @t_reporter.start_case(@t_case)
- end
-
- def t_test_started(name)
- methname, tcase = name.scan(%r/^([^\(]+)\(([^\)]+)\)/o).flatten!
- @t_test = @t_case.new_test(methname)
- #@t_test.file = tcase
- #@t_test.name = method
- @t_reporter.start_test(@t_test)
- end
-
- def t_fault(fault)
- case fault
- when ::Test::Unit::Error
- #msg = ""
- #msg << fault.to_s.split("\n")[2..-1].join("\n")
- @t_test.error!(fault.exception)
- @t_reporter.error(fault.exception)
- when ::Test::Unit::Failure
- #msg = ""
- #msg << fault.location[0] << "\n"
- #msg << fault.message #.gsub("\n","\n")
- @t_test.fail!(fault)
- @t_reporter.fail(fault)
- end
- end
-
- def t_test_finished(name)
- @t_reporter.pass if @t_test.pass?
- @t_reporter.finish_test(@t_test)
- end
-
- def t_case_finished(name)
- # Err.. why is testunit running this on the suite?
- return if name=='' # FIXME skip suite call
-
- #t = @t_result.run_count - @t_previous_run_count
- #f = @t_result.failure_count - @t_previous_failure_count
- #e = @t_result.error_count - @t_previous_error_count
- a = @t_result.assertion_count - @t_previous_assertion_count
- #@t_case.counts(t,a,f,e)
-
- @t_case.count_assertions = a
-
- #@t_previous_run_count = @t_result.run_count.to_i
- #@t_previous_failure_count = @t_result.failure_count.to_i
- #@t_previous_error_count = @t_result.error_count.to_i
- @t_previous_assertion_count = @t_result.assertion_count.to_i
-
- @t_reporter.finish_case(@t_case)
- end
-
- def t_finished(elapsed_time)
- #@t_suite.count_tests = @t_result.run_count
- #@t_suite.count_failures = @t_result.failure_count
- #@t_suite.count_errors = @t_result.error_count
- #@t_suite.count_passes = @t_result.run_count - @t_result.failure_count - @t_result.error_count
- @t_suite.count_assertions = @t_result.assertion_count
-
- @t_reporter.finish_suite(@t_suite)
- end
-
- # This is copied verbatim from test/unit/ui/console/testrunner.rb.
- # It is here for one simple reason: to supress testunits output of
- # "Loaded Suite".
- def setup_mediator
- @mediator = create_mediator(@suite)
- suite_name = @suite.to_s
- if ( @suite.kind_of?(Module) )
- suite_name = @suite.name
- end
- #output("Loaded suite #{suite_name}")
- end
-
- end#class TestRunner
-
-end#module Turn
View
7 lib/turn/testunit.rb
@@ -1,7 +0,0 @@
-require 'turn'
-
-require 'turn/runners/testrunner'
-
-# need to turn this off unless autorun mode
-Test::Unit.run = false
-
View
2 test/helper.rb
@@ -44,7 +44,7 @@ class TestTest < #{framework}::Unit::TestCase
#
def save_test(text, name=nil)
file = File.join('tmp', name || 'test.rb')
- FileUtils.mkdir_p('tmp')
+ FileUtils.mkdir_p('tmp') unless File.directory?('tmp')
File.open(file, 'w'){ |f| f << text }
return file
end
View
40 test/test_framework.rb
@@ -42,47 +42,47 @@ def $stdout.tty?
::RbConfig::CONFIG['host_os'], ENV['ANSICON'] = host_os, ansicon
end
- def test_ruby19_minitest_force
- setup_test('MiniTest')
- result = turn '--minitest tmp/test.rb'
- assert result.index('PASS')
- end
+ #def test_ruby19_minitest_force
+ # setup_test('MiniTest')
+ # result = turn '--minitest tmp/test.rb'
+ # assert result.index('PASS')
+ #end
def test_ruby19_minitest_required
setup_test('MiniTest', 'minitest/unit')
result = turn 'tmp/test.rb'
assert result.index('PASS')
end
- def test_ruby19_minitest_required_force
- setup_test('MiniTest', 'minitest/unit')
- result = turn '--minitest tmp/test.rb'
- assert result.index('PASS')
- end
+ #def test_ruby19_minitest_required_force
+ # setup_test('MiniTest', 'minitest/unit')
+ # result = turn '--minitest tmp/test.rb'
+ # assert result.index('PASS')
+ #end
def test_ruby19_minitest_mocking
setup_test('Test')
result = turn 'tmp/test.rb'
assert result.index('PASS')
end
- def test_ruby19_minitest_mocking_force
- setup_test('Test')
- result = turn '--minitest tmp/test.rb'
- assert result.index('PASS')
- end
+ #def test_ruby19_minitest_mocking_force
+ # setup_test('Test')
+ # result = turn '--minitest tmp/test.rb'
+ # assert result.index('PASS')
+ #end
def test_ruby19_minitest_mocking_required
setup_test('Test', 'minitest/unit')
result = turn 'tmp/test.rb'
assert result.index('PASS')
end
- def test_ruby19_minitest_mocking_required_force
- setup_test('Test', 'minitest/unit')
- result = turn '--minitest tmp/test.rb'
- assert result.index('PASS')
- end
+ #def test_ruby19_minitest_mocking_required_force
+ # setup_test('Test', 'minitest/unit')
+ # result = turn '--minitest tmp/test.rb'
+ # assert result.index('PASS')
+ #end
# Ruby 1.9 users must remove ++require 'test/unit'++ from their tests.
#def test_ruby19_testunit_required
View
26 test/test_runners.rb
@@ -20,17 +20,17 @@ def test_cross
# autorun
- if RUBY_VERSION < '1.9'
-
- def test_autorun
- file = setup_test('Test', 'turn/autorun', 'test_autorun.rb')
- result = `ruby -Ilib #{file} 2>&1`
- assert(result.index('pass: 1'))
- assert(result.index('fail: 0'))
- assert(result.index('error: 0'))
- end
-
- else
+ #if RUBY_VERSION < '1.9'
+ #
+ # def test_autorun
+ # file = setup_test('Test', 'turn/autorun', 'test_autorun.rb')
+ # result = `ruby -Ilib #{file} 2>&1`
+ # assert(result.index('pass: 1'))
+ # assert(result.index('fail: 0'))
+ # assert(result.index('error: 0'))
+ # end
+ #
+ #else
def test_autorun
file = setup_minitest_autorun
@@ -49,6 +49,8 @@ def test_autorun_with_trace
# TODO: the backtrace is empty, why?
#assert result.scan(/\.rb:\d+:in/).length > 1
end
- end
+
+ #end
+
end

0 comments on commit a180592

Please sign in to comment.