Skip to content

Commit

Permalink
Add verbose and runtime mark options.
Browse files Browse the repository at this point in the history
  • Loading branch information
trans committed Apr 15, 2012
1 parent c778653 commit 2d756ca
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 5 deletions.
4 changes: 4 additions & 0 deletions lib/turn/colorize.rb
Expand Up @@ -65,6 +65,10 @@ def self.bold(string)
colorize? ? ::ANSI::Code.bold{ string } : string
end

def self.mark(string)
colorize? ? ::ANSI::Code.yellow{ string } : string
end

def self.pass(string)
colorize? ? ::ANSI::Code.green{ string } : string
end
Expand Down
20 changes: 19 additions & 1 deletion lib/turn/command.rb
Expand Up @@ -76,6 +76,12 @@ def self.main(*argv)
# Use natural test case names.
attr :natural

# Show extra information.
attr :verbose

# Show extra information.
attr :mark

# Force ANSI use on or off.
attr :ansi

Expand All @@ -91,6 +97,8 @@ def initialize
@outmode = nil
@trace = nil
@natural = false
@verbose = false
@mark = nil
@ansi = nil
end

Expand Down Expand Up @@ -131,6 +139,10 @@ def option_parser
end
end

opts.on('-m', '--mark=SECONDS', "Mark test if it exceeds runtime threshold.") do |int|
@mark = int.to_i
end

opts.on('-b', '--backtrace', '--trace INT', "Limit the number of lines of backtrace.") do |int|
@trace = int
end
Expand All @@ -139,6 +151,10 @@ def option_parser
@natural = bool
end

opts.on('-v', '--verbose', "Show extra information.") do |bool|
@verbose = bool
end

opts.on('--[no-]ansi', "Force use of ANSI codes on or off.") do |bool|
@ansi = bool
end
Expand Down Expand Up @@ -218,7 +234,7 @@ def option_parser
exit
end

opts.on_tail('--help', '-h', "display this help information") do
opts.on_tail('-h', '--help', "display this help information") do
puts opts
exit
end
Expand Down Expand Up @@ -246,6 +262,8 @@ def main(*argv)
c.matchcase = matchcase
c.trace = trace
c.natural = natural
c.verbose = verbose
c.mark = mark
c.ansi = ansi unless ansi.nil?
end

Expand Down
14 changes: 12 additions & 2 deletions lib/turn/configuration.rb
Expand Up @@ -48,7 +48,11 @@ class Configuration
# Verbose output?
attr_accessor :verbose

# Test framework, either :minitest or :testunit
# Runtime threshold.
attr_accessor :mark

# Test framework, either `:minitest` or `:testunit`.
# @todo Is this used any more?
attr_accessor :framework

# Enable full backtrace
Expand Down Expand Up @@ -93,6 +97,7 @@ def initialize_defaults
@matchcase ||= nil
@pattern ||= /.*/
@natural ||= false
@verbose ||= false
@format ||= environment_format
@trace ||= environment_trace
@ansi ||= environment_ansi
Expand Down Expand Up @@ -175,7 +180,7 @@ def suite_name
# Select reporter based on output mode.
def reporter
@reporter ||= (
opts = { :trace=>trace, :natural=>natural? }
opts = reporter_options
case format
when :marshal
require 'turn/reporters/marshal_reporter'
Expand All @@ -202,6 +207,11 @@ def reporter
)
end

#
def reporter_options
{ :trace=>trace, :natural=>natural?, :verbose=>verbose?, :mark=>mark }
end

#
def environment_format
ENV['rpt']
Expand Down
2 changes: 2 additions & 0 deletions lib/turn/reporter.rb
Expand Up @@ -21,6 +21,8 @@ def initialize(io, opts={})
@io = io || $stdout
@trace = opts[:trace]
@natural = opts[:natural]
@verbose = opts[:verbose]
@mark = opts[:mark].to_i
end

# These methods are called in the process of running the tests.
Expand Down
12 changes: 10 additions & 2 deletions lib/turn/reporters/pretty_reporter.rb
Expand Up @@ -126,8 +126,16 @@ def colorize_count(str, count, colorize_method)
# PASS test: Test decription. (0.15s 0:00:02:059)
def banner(event)
name = naturalized_name(@test)
delta = Time.now - @test_time # Test runtime
io.puts "%18s (%s %0.3fs) %s" % [event, ticktock, delta, name]
delta = Time.now - @test_time # test runtime
if @verbose
out = "%18s (%0.5fs) [%s] %s" % [event, delta, ticktock, name]
else
out = "%18s [%s] %s" % [event, ticktock, name]
end
if @mark > 0 && delta > @mark
out[1] = Colorize.mark('*')
end
io.puts out
end

# Cleanups and prints test payload
Expand Down

0 comments on commit 2d756ca

Please sign in to comment.