aboutsummaryrefslogtreecommitdiffstats
path: root/lib/minitest/pride.rb
diff options
context:
space:
mode:
authorryan <ryan@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2011-08-23 21:47:25 +0000
committerryan <ryan@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2011-08-23 21:47:25 +0000
commit2c43b9664b29f76c73ac8bae5400b79d0a5313e0 (patch)
tree6e9b4a581ac460c38d22de2750939fa815a98295 /lib/minitest/pride.rb
parent885f5fa2b0c1ba20a26759e65fefeece48cb56db (diff)
downloadruby-2c43b9664b29f76c73ac8bae5400b79d0a5313e0.tar.gz
Imported minitest 2.5.0 (r6557)
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@33036 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib/minitest/pride.rb')
-rw-r--r--lib/minitest/pride.rb76
1 files changed, 67 insertions, 9 deletions
diff --git a/lib/minitest/pride.rb b/lib/minitest/pride.rb
index 9a4d68859a..ac7745695c 100644
--- a/lib/minitest/pride.rb
+++ b/lib/minitest/pride.rb
@@ -10,32 +10,90 @@ require "minitest/unit"
# Show your testing pride!
class PrideIO
- attr_reader :io
+ ESC = "\e["
+ NND = "#{ESC}0m"
- # stolen from /System/Library/Perl/5.10.0/Term/ANSIColor.pm
- COLORS = (31..36).to_a
- CHARS = ["*"]
+ attr_reader :io
def initialize io
@io = io
- @colors = COLORS.cycle
- @chars = CHARS.cycle
+ # 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
def print o
case o
when "." then
- io.print "\e[#{@colors.next}m#{@chars.next}\e[0m"
+ io.print pride o
when "E", "F" then
- io.print "\e[41m\e[37m#{o}\e[0m"
+ io.print "#{ESC}41m#{ESC}37m#{o}#{NND}"
else
io.print o
end
end
+ def puts(*o)
+ o.map! { |s|
+ s.sub(/Finished tests/) {
+ @index = 0
+ 'Fabulous tests'.split(//).map { |c|
+ pride(c)
+ }.join
+ }
+ }
+
+ super
+ end
+
+ def pride string
+ string = "*" if string == "."
+ c = @colors[@index % @size]
+ @index += 1
+ "#{ESC}#{c}m#{string}#{NND}"
+ end
+
def method_missing msg, *args
io.send(msg, *args)
end
end
-MiniTest::Unit.output = PrideIO.new(MiniTest::Unit.output)
+class PrideLOL < PrideIO # inspired by lolcat, but massively cleaned up
+ PI_3 = Math::PI / 3
+
+ def initialize io
+ # 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
+
+ def pride string
+ c = @colors[@index % @size]
+ @index += 1
+ "#{ESC}38;5;#{c}m#{string}#{NND}"
+ end
+end
+
+klass = ENV['TERM'] =~ /^xterm(-256color)?$/ ? PrideLOL : PrideIO
+MiniTest::Unit.output = klass.new(MiniTest::Unit.output)