Permalink
Browse files

Turn is going to be MiniTest only. [major]

  • Loading branch information...
1 parent 8239e27 commit b7447f2225b1a483ded03522e660eb33c0a7f883 @trans trans committed Jan 28, 2012
View
@@ -1,21 +1,18 @@
-module Turn
- # Returns +true+ if the ruby version supports minitest.
- # Otherwise, +false+ is returned.
- def self.minitest?
- RUBY_VERSION >= '1.9'
- end
-end
+module Turn; end
+
+require 'fileutils'
-#require 'turn/autoload'
+require 'turn/version'
+require 'turn/autoload'
+require 'turn/configuration'
+require 'turn/colorize'
+require 'turn/components'
+require 'turn/controller'
+require 'turn/minitest'
-# TODO: Remove autorun in turn.rb for v1.0.
-unless defined?(Turn::Command)
+# TODO: Remove this in turn.rb for v1.0.
+if ENV['autorun']
warn "Use `require 'turn/autorun'` instead of `require 'turn'` for future versions."
- if Turn.minitest?
- require 'turn/autorun/minitest'
- MiniTest::Unit.autorun
- else
- require 'turn/autorun/testunit'
- end
+ MiniTest::Unit.autorun
end
View
@@ -1,9 +1,4 @@
-require 'turn/autoload'
+require 'turn'
-if Turn.minitest?
- require 'turn/autorun/minitest'
- MiniTest::Unit.autorun
-else
- require 'turn/autorun/testunit'
-end
+MiniTest::Unit.autorun
@@ -1,17 +1,3 @@
-require 'turn/autoload'
-
-require 'minitest/unit'
-require 'minitest/spec'
-
-require 'turn/colorize'
-require 'turn/controller'
-require 'turn/runners/minirunner'
-
-if MiniTest::Unit.respond_to?(:runner=)
- MiniTest::Unit.runner = Turn::MiniRunner.new
-else
- raise "MiniTest v#{MiniTest::Unit::VERSION} is out of date.\n" \
- "`gem install minitest` and add `gem 'minitest' to you test helper."
- #MiniTest::Unit = Turn::MiniRunner
-end
+require 'turn/minitest'
+MiniTest::Unit.autorun
@@ -1,10 +1,8 @@
-#require 'test/unit/ui/console/testrunner'
-require 'turn/autoload_trick'
-
-require 'turn/colorize'
-require 'turn/controller'
-require 'turn/runners/testrunner'
+require 'turn/testunit'
Test::Unit::AutoRunner::RUNNERS[:console] = proc do |r|
Turn::TestRunner
end
+
+Test::Unit.run = true
+
View
@@ -1,3 +1,5 @@
+require 'turn/configuration' # why is this needed here?
+
begin
require 'ansi/code'
rescue LoadError
@@ -16,16 +18,25 @@ module Colorize
COLORLESS_TERMINALS = ['dumb']
- def colorize?
+ def self.colorize?
+ @colorize ||= (
+ ansi = Turn.config.ansi?
+ if ansi.nil?
+ color_supported?
+ else
+ Turn.config.ansi?
+ end
+ )
+ end
+
+ def self.color_supported?
return false unless defined?(::ANSI::Code)
return false unless $stdout.tty?
return true if ENV.has_key?('TERM') && !COLORLESS_TERMINALS.include?(ENV['TERM'])
return true if ::RbConfig::CONFIG['host_os'] =~ /mswin|mingw/ && ENV.has_key?('ANSICON')
return false
end
- module_function :colorize?
-
def self.red(string)
colorize? ? ::ANSI::Code.red{ string } : string
end
@@ -68,6 +79,10 @@ def self.skip(string)
ERROR = error('ERROR')
SKIP = skip('SKIP')
+ def colorize?
+ Colorize.colorize?
+ end
+
end
end
View
@@ -1,7 +1,7 @@
require 'optparse'
+require 'turn'
module Turn
- require 'turn/controller'
# Turn - Pretty Unit Test Runner for Ruby
#
@@ -13,10 +13,11 @@ module Turn
# --live don't use loadpath
# --log log results to a file
# -n --name=PATTERN only run tests that match regexp PATTERN
+ # -c --case=PATTERN only run testcases that match regexp PATTERN
# -I --loadpath=PATHS add given PATHS to the $LOAD_PATH
# -r --requires=LIBS require given LIBS before running tests
# -m --minitest Force use of MiniTest framework.
- # -t --trace Turn on invoke/execute tracing, enable full backtrace.
+ # -b --backtrace=INT Set the number of lines to show in backtrace.
#
# RUN MODES
# --normal run all tests in a single process [default]
@@ -27,9 +28,9 @@ module Turn
# -O --outline turn's original case/test outline mode [default]
# -P --progress indicates progress with progress bar
# -D --dotted test/unit's traditonal dot-progress mode
- # --pretty new pretty reporter
+ # -R --pretty new pretty reporter
# -M --marshal dump output as YAML (normal run mode only)
- # -Q --queued interactive testing
+ # -C --cue interactive testing
#
class Command
@@ -57,7 +58,7 @@ def self.main(*argv)
attr :requires
# Framework to use, :minitest or :testunit.
- attr :framework
+ #attr :framework
# Run mode.
attr :runmode
@@ -71,6 +72,9 @@ def self.main(*argv)
# Use natural test case names.
attr :natural
+ # Force ANSI use on or off.
+ attr :ansi
+
#
def initialize
@live = nil
@@ -81,9 +85,10 @@ def initialize
@requires = []
@runmode = nil
@outmode = nil
- @framework = RUBY_VERSION >= "1.9" ? :minitest : :testunit
+ #@framework = RUBY_VERSION >= "1.9" ? :minitest : :testunit
@trace = nil
@natural = false
+ @ansi = nil
end
#
@@ -123,16 +128,20 @@ def option_parser
end
end
- opts.on('-m', '--minitest', "Force use of MiniTest framework") do
- @framework = :minitest
- end
+ #opts.on('-m', '--minitest', "Force use of MiniTest framework") do
+ # @framework = :minitest
+ #end
opts.on('-b', '--backtrace', '--trace INT', "Limit the number of lines of backtrace.") do |int|
@trace = int
end
opts.on('--natural', "Show natualized test names.") do |bool|
- @natural = true
+ @natural = bool
+ end
+
+ opts.on('--[no-]ansi', "Force use of ANSI codes on or off.") do |bool|
+ @ansi = bool
end
# Turn does not support Test::Unit 2.0+
@@ -233,9 +242,10 @@ def main(*argv)
c.format = outmode
c.pattern = pattern
c.matchcase = matchcase
- c.framework = framework
+ #c.framework = framework
c.trace = trace
c.natural = natural
+ c.ansi = ansi unless ansi.nil?
end
controller = Turn::Controller.new(config)
View
@@ -0,0 +1,4 @@
+require 'turn/components/suite'
+require 'turn/components/case'
+require 'turn/components/method'
+
@@ -60,6 +60,7 @@ class Configuration
def verbose? ; @verbose ; end
def live? ; @live ; end
def natural? ; @natural ; end
+ def ansi? ; @ansi ; end
private
@@ -116,6 +117,10 @@ def list_option(list)
public
+ def ansi=(boolean)
+ @ansi = boolean ? true : false
+ end
+
def tests=(paths)
@tests = list_option(paths)
end
View
@@ -1,14 +1,5 @@
-require 'fileutils'
-
module Turn
- require 'turn/version'
- require 'turn/autoload'
- require 'turn/components/suite.rb'
- require 'turn/components/case.rb'
- require 'turn/components/method.rb'
- require 'turn/configuration.rb'
-
# Controls execution of test run.
#
class Controller
View
@@ -0,0 +1,18 @@
+require 'turn'
+
+# we save the developer the trouble of having to load these (TODO: should we?)
+require 'minitest/unit'
+require 'minitest/spec'
+
+# load Turn's minitest runner
+require 'turn/runners/minirunner'
+
+# set MiniTest's runner to Turn::MiniRunner instance
+if MiniTest::Unit.respond_to?(:runner=)
+ MiniTest::Unit.runner = Turn::MiniRunner.new
+else
+ raise "MiniTest v#{MiniTest::Unit::VERSION} is out of date.\n" \
+ "`gem install minitest` and add `gem 'minitest' to you test helper."
+ #MiniTest::Unit = Turn::MiniRunner
+end
+
View
@@ -0,0 +1,7 @@
+require 'turn'
+
+require 'turn/runners/testrunner'
+
+# need to turn this off unless autorun mode
+Test::Unit.run = false
+
View
@@ -1,6 +1,6 @@
$:.unshift './lib'
-require 'turn/colorize'
+#require 'turn/colorize'
require 'fileutils'
if RUBY_VERSION < "1.9"
@@ -96,6 +96,7 @@ def test_sample_fail
def setup_minitest_autorun
text = <<-HERE
require 'turn'
+MiniTest::Unit.runner = Turn::MiniRunner.new
MiniTest::Unit.autorun
#require 'minitest/unit'
class TestTest < MiniTest::Unit::TestCase
@@ -113,6 +114,7 @@ def setup_minitest_autorun_with_trace
#require 'minitest/unit'
#require 'rubygems'
require 'turn'
+MiniTest::Unit.runner = Turn::MiniRunner.new
MiniTest::Unit.autorun
Turn.config do |c|
c.trace = 1
View
@@ -20,23 +20,23 @@ def $stdout.tty?
end
ENV['ANSICON'] = nil
ENV['TERM'] = 'xterm'
- assert_equal true, Turn::Colorize.colorize?
+ assert_equal true, Turn::Colorize.color_supported?
ENV['TERM'] = 'dumb'
- assert_equal false, Turn::Colorize.colorize?
+ assert_equal false, Turn::Colorize.color_supported?
ENV['TERM'] = nil
- assert_equal false, Turn::Colorize.colorize?
+ assert_equal false, Turn::Colorize.color_supported?
['mingw32', 'mswin32'].each do |os|
::RbConfig::CONFIG['host_os'] = os
ENV['ANSICON'] = '120x5000 (120x50)'
- assert_equal true, Turn::Colorize.colorize?
+ assert_equal true, Turn::Colorize.color_supported?
ENV['ANSICON'] = nil
- assert_equal false, Turn::Colorize.colorize?
+ assert_equal false, Turn::Colorize.color_supported?
end
ENV['TERM'] = 'xterm'
def $stdout.tty?
false
end
- assert_equal false, Turn::Colorize.colorize?
+ assert_equal false, Turn::Colorize.color_supported?
ensure
ENV['TERM'], $stdout = term, stdout
::RbConfig::CONFIG['host_os'], ENV['ANSICON'] = host_os, ansicon
View
@@ -23,7 +23,7 @@ def test_cross
if RUBY_VERSION < '1.9'
def test_autorun
- file = setup_test('Test', 'turn', 'test_autorun.rb')
+ 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'))
@@ -35,8 +35,8 @@ def test_autorun
def test_autorun
file = setup_minitest_autorun
result = `ruby -Ilib #{file} 2>&1`
- assert result.index('fail: 0')
- assert result.index('error: 0')
+ assert result.index('fail: 0'), "ACTUAL RESULT --->\n #{result}"
+ assert result.index('error: 0'), "ACTUAL RESULT --->\n #{result}"
end
def test_autorun_with_trace

0 comments on commit b7447f2

Please sign in to comment.