2012-08-16 04:10:54 +02:00
|
|
|
module Mutant
|
|
|
|
class Reporter
|
|
|
|
# Reporter that reports in human readable format
|
|
|
|
class CLI < self
|
2014-08-10 22:09:29 +00:00
|
|
|
include Concord.new(:output, :format)
|
2012-08-29 13:36:29 +02:00
|
|
|
|
2014-08-10 22:09:29 +00:00
|
|
|
# Build reporter
|
|
|
|
#
|
|
|
|
# @param [IO] output
|
|
|
|
#
|
|
|
|
# @return [Reporter::CLI]
|
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
#
|
|
|
|
def self.build(output)
|
|
|
|
ci = ENV.key?('CI')
|
|
|
|
tty = output.respond_to?(:tty?) && output.tty?
|
2014-08-10 22:33:36 +00:00
|
|
|
format =
|
|
|
|
if !ci && tty && Tput::INSTANCE.available
|
|
|
|
Format::Framed.new(tty: tty, tput: Tput::INSTANCE)
|
|
|
|
else
|
|
|
|
Format::Progressive.new(tty: tty)
|
|
|
|
end
|
2014-08-10 22:09:29 +00:00
|
|
|
|
|
|
|
new(output, format)
|
|
|
|
end
|
2014-07-17 13:59:25 +00:00
|
|
|
|
2014-08-10 22:09:29 +00:00
|
|
|
# Report start
|
2014-07-17 13:59:25 +00:00
|
|
|
#
|
2014-08-10 22:09:29 +00:00
|
|
|
# @param [Env] env
|
2014-07-17 13:59:25 +00:00
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
#
|
2014-08-10 22:09:29 +00:00
|
|
|
def start(env)
|
|
|
|
write(format.start(env))
|
|
|
|
self
|
2014-07-17 13:59:25 +00:00
|
|
|
end
|
|
|
|
|
2014-05-12 13:48:15 +00:00
|
|
|
# Report progress object
|
|
|
|
#
|
2014-07-17 13:59:25 +00:00
|
|
|
# @param [Runner::Collector] collector
|
2014-05-12 13:48:15 +00:00
|
|
|
#
|
|
|
|
# @return [self]
|
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
#
|
2014-07-17 13:59:25 +00:00
|
|
|
def progress(collector)
|
2014-08-10 22:16:53 +00:00
|
|
|
write(format.progress(collector))
|
2014-07-17 13:59:25 +00:00
|
|
|
|
2014-05-12 13:48:15 +00:00
|
|
|
self
|
|
|
|
end
|
|
|
|
|
2014-06-30 13:19:47 +00:00
|
|
|
# Report warning
|
|
|
|
#
|
|
|
|
# @param [String] message
|
|
|
|
#
|
|
|
|
# @return [self]
|
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
#
|
|
|
|
def warn(message)
|
|
|
|
output.puts(message)
|
|
|
|
self
|
|
|
|
end
|
|
|
|
|
2014-07-17 13:59:25 +00:00
|
|
|
# Report env
|
2013-04-21 02:20:18 +02:00
|
|
|
#
|
2014-07-17 13:59:25 +00:00
|
|
|
# @param [Result::Env] env
|
2013-04-21 02:20:18 +02:00
|
|
|
#
|
|
|
|
# @return [self]
|
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
#
|
2014-07-17 13:59:25 +00:00
|
|
|
def report(env)
|
2014-08-10 22:09:29 +00:00
|
|
|
write(format.report(env))
|
2013-04-21 02:20:18 +02:00
|
|
|
self
|
|
|
|
end
|
|
|
|
|
2014-07-17 13:59:25 +00:00
|
|
|
private
|
|
|
|
|
2014-08-10 22:09:29 +00:00
|
|
|
# Write output frame
|
2014-07-17 13:59:25 +00:00
|
|
|
#
|
|
|
|
# @param [String] frame
|
|
|
|
#
|
|
|
|
# @return [undefined]
|
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
#
|
2014-08-10 22:09:29 +00:00
|
|
|
def write(frame)
|
2014-07-17 13:59:25 +00:00
|
|
|
output.write(frame)
|
|
|
|
end
|
|
|
|
|
2013-06-14 20:54:02 +02:00
|
|
|
end # CLI
|
|
|
|
end # Reporter
|
|
|
|
end # Mutant
|