2012-05-04 17:46:01 -04:00
|
|
|
# encoding: utf-8
|
2011-02-19 15:44:08 -05:00
|
|
|
######################################################################
|
|
|
|
# This file is imported from the minitest project.
|
|
|
|
# DO NOT make modifications in this repo. They _will_ be reverted!
|
|
|
|
# File a patch instead and assign it to Ryan Davis.
|
|
|
|
######################################################################
|
2010-12-01 00:33:32 -05:00
|
|
|
|
|
|
|
require "minitest/unit"
|
|
|
|
|
|
|
|
##
|
|
|
|
# Show your testing pride!
|
|
|
|
|
|
|
|
class PrideIO
|
2012-05-04 17:46:01 -04:00
|
|
|
|
|
|
|
# Start an escape sequence
|
2011-08-23 17:47:25 -04:00
|
|
|
ESC = "\e["
|
2012-05-04 17:46:01 -04:00
|
|
|
|
|
|
|
# End the escape sequence
|
2011-08-23 17:47:25 -04:00
|
|
|
NND = "#{ESC}0m"
|
2010-12-01 00:33:32 -05:00
|
|
|
|
2012-05-04 17:46:01 -04:00
|
|
|
# The IO we're going to pipe through.
|
2011-08-23 17:47:25 -04:00
|
|
|
attr_reader :io
|
2010-12-01 00:33:32 -05:00
|
|
|
|
2012-05-04 17:46:01 -04:00
|
|
|
def initialize io # :nodoc:
|
2010-12-01 00:33:32 -05:00
|
|
|
@io = io
|
2011-08-23 17:47:25 -04:00
|
|
|
# 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
|
2010-12-01 00:33:32 -05:00
|
|
|
end
|
|
|
|
|
2012-05-04 17:46:01 -04:00
|
|
|
##
|
|
|
|
# Wrap print to colorize the output.
|
|
|
|
|
2010-12-01 00:33:32 -05:00
|
|
|
def print o
|
|
|
|
case o
|
|
|
|
when "." then
|
2011-08-23 17:47:25 -04:00
|
|
|
io.print pride o
|
2010-12-01 00:33:32 -05:00
|
|
|
when "E", "F" then
|
2011-08-23 17:47:25 -04:00
|
|
|
io.print "#{ESC}41m#{ESC}37m#{o}#{NND}"
|
2010-12-01 00:33:32 -05:00
|
|
|
else
|
|
|
|
io.print o
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-05-04 17:46:01 -04:00
|
|
|
def puts(*o) # :nodoc:
|
2011-08-23 17:47:25 -04:00
|
|
|
o.map! { |s|
|
2012-11-28 22:23:11 -05:00
|
|
|
s.to_s.sub(/Finished tests/) {
|
2011-08-23 17:47:25 -04:00
|
|
|
@index = 0
|
|
|
|
'Fabulous tests'.split(//).map { |c|
|
|
|
|
pride(c)
|
|
|
|
}.join
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
super
|
|
|
|
end
|
|
|
|
|
2012-05-04 17:46:01 -04:00
|
|
|
##
|
|
|
|
# Color a string.
|
|
|
|
|
2011-08-23 17:47:25 -04:00
|
|
|
def pride string
|
|
|
|
string = "*" if string == "."
|
|
|
|
c = @colors[@index % @size]
|
|
|
|
@index += 1
|
|
|
|
"#{ESC}#{c}m#{string}#{NND}"
|
|
|
|
end
|
|
|
|
|
2012-05-04 17:46:01 -04:00
|
|
|
def method_missing msg, *args # :nodoc:
|
2010-12-01 00:33:32 -05:00
|
|
|
io.send(msg, *args)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-05-04 17:46:01 -04:00
|
|
|
##
|
|
|
|
# If you thought the PrideIO was colorful...
|
|
|
|
#
|
|
|
|
# (Inspired by lolcat, but with clean math)
|
|
|
|
|
|
|
|
class PrideLOL < PrideIO
|
|
|
|
PI_3 = Math::PI / 3 # :nodoc:
|
2011-08-23 17:47:25 -04:00
|
|
|
|
2012-05-04 17:46:01 -04:00
|
|
|
def initialize io # :nodoc:
|
2011-08-23 17:47:25 -04:00
|
|
|
# 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
|
|
|
|
|
2012-05-04 17:46:01 -04:00
|
|
|
##
|
|
|
|
# Make the string even more colorful. Damnit.
|
|
|
|
|
2011-08-23 17:47:25 -04:00
|
|
|
def pride string
|
|
|
|
c = @colors[@index % @size]
|
|
|
|
@index += 1
|
|
|
|
"#{ESC}38;5;#{c}m#{string}#{NND}"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2011-11-17 18:02:16 -05:00
|
|
|
klass = ENV['TERM'] =~ /^xterm|-256color$/ ? PrideLOL : PrideIO
|
2011-08-23 17:47:25 -04:00
|
|
|
MiniTest::Unit.output = klass.new(MiniTest::Unit.output)
|