+ Minitest.init_plugins passes down options.

+ Minitest.load_plugins only loads once.
Moved most of minitest/pride into minitest/pride_plugin.
Moved pride cmdline option handler into pride_plugin.rb
minitest/pride now just activates pride.
- Fixed minitest/pride to work with rake test loader again. (tmiller)

[git-p4: depot-paths = "//src/minitest/dev/": change = 8475]
This commit is contained in:
Ryan Davis 2013-05-01 02:46:01 -08:00
parent bfa6a4fa81
commit fcb36a1733
4 changed files with 152 additions and 121 deletions

View File

@ -14,6 +14,7 @@ lib/minitest/hell.rb
lib/minitest/mock.rb
lib/minitest/parallel_each.rb
lib/minitest/pride.rb
lib/minitest/pride_plugin.rb
lib/minitest/spec.rb
lib/minitest/test.rb
lib/minitest/unit.rb

View File

@ -58,14 +58,16 @@ module Minitest
@@after_run << block
end
def self.init_plugins # :nodoc:
def self.init_plugins options # :nodoc:
self.extensions.each do |name|
msg = "plugin_#{name}_init"
send msg if self.respond_to? msg
send msg, options if self.respond_to? msg
end
end
def self.load_plugins # :nodoc:
return unless self.extensions.empty?
Gem.find_files("minitest/*_plugin.rb").each do |plugin_path|
require plugin_path
name = File.basename plugin_path, "_plugin.rb"
@ -97,7 +99,7 @@ module Minitest
reporter << Reporter.new(options[:io], options)
self.reporter = reporter # this makes it available to plugins
self.init_plugins
self.init_plugins options
self.reporter = nil # runnables shouldn't depend on the reporter, ever
reporter.run_and_report do
@ -143,12 +145,6 @@ module Minitest
options[:verbose] = true
end
opts.on "-p", "--pride", "Pride. Show your testing pride!" do
require "minitest/pride"
klass = ENV["TERM"] =~ /^xterm|-256color$/ ? PrideLOL : PrideIO
options[:io] = klass.new(options[:io])
end
opts.on "-n", "--name PATTERN", "Filter method names on pattern (e.g. /foo/)" do |a|
options[:filter] = a
end

View File

@ -1,113 +1,4 @@
require "minitest/unit"
require "minitest"
##
# Show your testing pride!
class PrideIO
# Start an escape sequence
ESC = "\e["
# End the escape sequence
NND = "#{ESC}0m"
# The IO we're going to pipe through.
attr_reader :io
def initialize io # :nodoc:
@io = io
# stolen from /System/Library/Perl/5.10.0/Term/ANSIColor.pm
# also reference http://en.wikipedia.org/wiki/ANSI_escape_code
@colors ||= (31..36).to_a
@size = @colors.size
@index = 0
# io.sync = true
end
##
# Wrap print to colorize the output.
def print o
case o
when "." then
io.print pride o
when "E", "F" then
io.print "#{ESC}41m#{ESC}37m#{o}#{NND}"
when "S" then
io.print pride o
else
io.print o
end
end
def puts(*o) # :nodoc:
o.map! { |s|
s.to_s.sub(/Finished tests/) {
@index = 0
'Fabulous tests'.split(//).map { |c|
pride(c)
}.join
}
}
super
end
##
# Color a string.
def pride string
string = "*" if string == "."
c = @colors[@index % @size]
@index += 1
"#{ESC}#{c}m#{string}#{NND}"
end
def method_missing msg, *args # :nodoc:
io.send(msg, *args)
end
end
##
# If you thought the PrideIO was colorful...
#
# (Inspired by lolcat, but with clean math)
class PrideLOL < PrideIO
PI_3 = Math::PI / 3 # :nodoc:
def initialize io # :nodoc:
# walk red, green, and blue around a circle separated by equal thirds.
#
# To visualize, type this into wolfram-alpha:
#
# plot (3*sin(x)+3), (3*sin(x+2*pi/3)+3), (3*sin(x+4*pi/3)+3)
# 6 has wide pretty gradients. 3 == lolcat, about half the width
@colors = (0...(6 * 7)).map { |n|
n *= 1.0 / 6
r = (3 * Math.sin(n ) + 3).to_i
g = (3 * Math.sin(n + 2 * PI_3) + 3).to_i
b = (3 * Math.sin(n + 4 * PI_3) + 3).to_i
# Then we take rgb and encode them in a single number using base 6.
# For some mysterious reason, we add 16... to clear the bottom 4 bits?
# Yes... they're ugly.
36 * r + 6 * g + b + 16
}
super
end
##
# Make the string even more colorful. Damnit.
def pride string
c = @colors[@index % @size]
@index += 1
"#{ESC}38;5;#{c}m#{string}#{NND}"
end
end
ARGV.unshift "-p"
Minitest.load_plugins
Minitest::PrideIO.pride!

View File

@ -0,0 +1,143 @@
require "minitest/autorun"
module Minitest
def self.plugin_pride_options opts, options # :nodoc:
opts.on "-p", "--pride", "Pride. Show your testing pride!" do
PrideIO.pride!
end
end
def self.plugin_pride_init options # :nodoc:
if PrideIO.pride? then
klass = ENV["TERM"] =~ /^xterm|-256color$/ ? PrideLOL : PrideIO
io = klass.new options[:io]
self.reporter.reporters.grep(Minitest::Reporter).each do |rep|
rep.io = io
end
end
end
##
# Show your testing pride!
class PrideIO
##
# Activate the pride plugin. Called from both -p option and minitest/pride
def self.pride!
@pride = true
end
##
# Are we showing our testing pride?
def self.pride?
@pride ||= false
end
# Start an escape sequence
ESC = "\e["
# End the escape sequence
NND = "#{ESC}0m"
# The IO we're going to pipe through.
attr_reader :io
def initialize io # :nodoc:
@io = io
# stolen from /System/Library/Perl/5.10.0/Term/ANSIColor.pm
# also reference http://en.wikipedia.org/wiki/ANSI_escape_code
@colors ||= (31..36).to_a
@size = @colors.size
@index = 0
# io.sync = true
end
##
# Wrap print to colorize the output.
def print o
case o
when "." then
io.print pride o
when "E", "F" then
io.print "#{ESC}41m#{ESC}37m#{o}#{NND}"
when "S" then
io.print pride o
else
io.print o
end
end
def puts(*o) # :nodoc:
o.map! { |s|
s.to_s.sub(/Finished/) {
@index = 0
'Fabulous run'.split(//).map { |c|
pride(c)
}.join
}
}
super
end
##
# Color a string.
def pride string
string = "*" if string == "."
c = @colors[@index % @size]
@index += 1
"#{ESC}#{c}m#{string}#{NND}"
end
def method_missing msg, *args # :nodoc:
io.send(msg, *args)
end
end
##
# If you thought the PrideIO was colorful...
#
# (Inspired by lolcat, but with clean math)
class PrideLOL < PrideIO
PI_3 = Math::PI / 3 # :nodoc:
def initialize io # :nodoc:
# walk red, green, and blue around a circle separated by equal thirds.
#
# To visualize, type this into wolfram-alpha:
#
# plot (3*sin(x)+3), (3*sin(x+2*pi/3)+3), (3*sin(x+4*pi/3)+3)
# 6 has wide pretty gradients. 3 == lolcat, about half the width
@colors = (0...(6 * 7)).map { |n|
n *= 1.0 / 6
r = (3 * Math.sin(n ) + 3).to_i
g = (3 * Math.sin(n + 2 * PI_3) + 3).to_i
b = (3 * Math.sin(n + 4 * PI_3) + 3).to_i
# Then we take rgb and encode them in a single number using base 6.
# For some mysterious reason, we add 16... to clear the bottom 4 bits?
# Yes... they're ugly.
36 * r + 6 * g + b + 16
}
super
end
##
# Make the string even more colorful. Damnit.
def pride string
c = @colors[@index % @size]
@index += 1
"#{ESC}38;5;#{c}m#{string}#{NND}"
end
end
end