Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit fcb36a1

Browse files
committed
+ 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]
1 parent bfa6a4f commit fcb36a1

4 files changed

Lines changed: 152 additions & 121 deletions

File tree

Manifest.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ lib/minitest/hell.rb
1414
lib/minitest/mock.rb
1515
lib/minitest/parallel_each.rb
1616
lib/minitest/pride.rb
17+
lib/minitest/pride_plugin.rb
1718
lib/minitest/spec.rb
1819
lib/minitest/test.rb
1920
lib/minitest/unit.rb

lib/minitest.rb

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -58,14 +58,16 @@ def self.after_run &block
5858
@@after_run << block
5959
end
6060

61-
def self.init_plugins # :nodoc:
61+
def self.init_plugins options # :nodoc:
6262
self.extensions.each do |name|
6363
msg = "plugin_#{name}_init"
64-
send msg if self.respond_to? msg
64+
send msg, options if self.respond_to? msg
6565
end
6666
end
6767

6868
def self.load_plugins # :nodoc:
69+
return unless self.extensions.empty?
70+
6971
Gem.find_files("minitest/*_plugin.rb").each do |plugin_path|
7072
require plugin_path
7173
name = File.basename plugin_path, "_plugin.rb"
@@ -97,7 +99,7 @@ def self.run args = []
9799
reporter << Reporter.new(options[:io], options)
98100

99101
self.reporter = reporter # this makes it available to plugins
100-
self.init_plugins
102+
self.init_plugins options
101103
self.reporter = nil # runnables shouldn't depend on the reporter, ever
102104

103105
reporter.run_and_report do
@@ -143,12 +145,6 @@ def self.process_args args = [] # :nodoc:
143145
options[:verbose] = true
144146
end
145147

146-
opts.on "-p", "--pride", "Pride. Show your testing pride!" do
147-
require "minitest/pride"
148-
klass = ENV["TERM"] =~ /^xterm|-256color$/ ? PrideLOL : PrideIO
149-
options[:io] = klass.new(options[:io])
150-
end
151-
152148
opts.on "-n", "--name PATTERN", "Filter method names on pattern (e.g. /foo/)" do |a|
153149
options[:filter] = a
154150
end

lib/minitest/pride.rb

Lines changed: 3 additions & 112 deletions
Original file line numberDiff line numberDiff line change
@@ -1,113 +1,4 @@
1-
require "minitest/unit"
1+
require "minitest"
22

3-
##
4-
# Show your testing pride!
5-
6-
class PrideIO
7-
8-
# Start an escape sequence
9-
ESC = "\e["
10-
11-
# End the escape sequence
12-
NND = "#{ESC}0m"
13-
14-
# The IO we're going to pipe through.
15-
attr_reader :io
16-
17-
def initialize io # :nodoc:
18-
@io = io
19-
# stolen from /System/Library/Perl/5.10.0/Term/ANSIColor.pm
20-
# also reference http://en.wikipedia.org/wiki/ANSI_escape_code
21-
@colors ||= (31..36).to_a
22-
@size = @colors.size
23-
@index = 0
24-
# io.sync = true
25-
end
26-
27-
##
28-
# Wrap print to colorize the output.
29-
30-
def print o
31-
case o
32-
when "." then
33-
io.print pride o
34-
when "E", "F" then
35-
io.print "#{ESC}41m#{ESC}37m#{o}#{NND}"
36-
when "S" then
37-
io.print pride o
38-
else
39-
io.print o
40-
end
41-
end
42-
43-
def puts(*o) # :nodoc:
44-
o.map! { |s|
45-
s.to_s.sub(/Finished tests/) {
46-
@index = 0
47-
'Fabulous tests'.split(//).map { |c|
48-
pride(c)
49-
}.join
50-
}
51-
}
52-
53-
super
54-
end
55-
56-
##
57-
# Color a string.
58-
59-
def pride string
60-
string = "*" if string == "."
61-
c = @colors[@index % @size]
62-
@index += 1
63-
"#{ESC}#{c}m#{string}#{NND}"
64-
end
65-
66-
def method_missing msg, *args # :nodoc:
67-
io.send(msg, *args)
68-
end
69-
end
70-
71-
##
72-
# If you thought the PrideIO was colorful...
73-
#
74-
# (Inspired by lolcat, but with clean math)
75-
76-
class PrideLOL < PrideIO
77-
PI_3 = Math::PI / 3 # :nodoc:
78-
79-
def initialize io # :nodoc:
80-
# walk red, green, and blue around a circle separated by equal thirds.
81-
#
82-
# To visualize, type this into wolfram-alpha:
83-
#
84-
# plot (3*sin(x)+3), (3*sin(x+2*pi/3)+3), (3*sin(x+4*pi/3)+3)
85-
86-
# 6 has wide pretty gradients. 3 == lolcat, about half the width
87-
@colors = (0...(6 * 7)).map { |n|
88-
n *= 1.0 / 6
89-
r = (3 * Math.sin(n ) + 3).to_i
90-
g = (3 * Math.sin(n + 2 * PI_3) + 3).to_i
91-
b = (3 * Math.sin(n + 4 * PI_3) + 3).to_i
92-
93-
# Then we take rgb and encode them in a single number using base 6.
94-
# For some mysterious reason, we add 16... to clear the bottom 4 bits?
95-
# Yes... they're ugly.
96-
97-
36 * r + 6 * g + b + 16
98-
}
99-
100-
super
101-
end
102-
103-
##
104-
# Make the string even more colorful. Damnit.
105-
106-
def pride string
107-
c = @colors[@index % @size]
108-
@index += 1
109-
"#{ESC}38;5;#{c}m#{string}#{NND}"
110-
end
111-
end
112-
113-
ARGV.unshift "-p"
3+
Minitest.load_plugins
4+
Minitest::PrideIO.pride!

lib/minitest/pride_plugin.rb

Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
require "minitest/autorun"
2+
3+
module Minitest
4+
def self.plugin_pride_options opts, options # :nodoc:
5+
opts.on "-p", "--pride", "Pride. Show your testing pride!" do
6+
PrideIO.pride!
7+
end
8+
end
9+
10+
def self.plugin_pride_init options # :nodoc:
11+
if PrideIO.pride? then
12+
klass = ENV["TERM"] =~ /^xterm|-256color$/ ? PrideLOL : PrideIO
13+
io = klass.new options[:io]
14+
15+
self.reporter.reporters.grep(Minitest::Reporter).each do |rep|
16+
rep.io = io
17+
end
18+
end
19+
end
20+
21+
##
22+
# Show your testing pride!
23+
24+
class PrideIO
25+
##
26+
# Activate the pride plugin. Called from both -p option and minitest/pride
27+
28+
def self.pride!
29+
@pride = true
30+
end
31+
32+
##
33+
# Are we showing our testing pride?
34+
35+
def self.pride?
36+
@pride ||= false
37+
end
38+
39+
# Start an escape sequence
40+
ESC = "\e["
41+
42+
# End the escape sequence
43+
NND = "#{ESC}0m"
44+
45+
# The IO we're going to pipe through.
46+
attr_reader :io
47+
48+
def initialize io # :nodoc:
49+
@io = io
50+
# stolen from /System/Library/Perl/5.10.0/Term/ANSIColor.pm
51+
# also reference http://en.wikipedia.org/wiki/ANSI_escape_code
52+
@colors ||= (31..36).to_a
53+
@size = @colors.size
54+
@index = 0
55+
# io.sync = true
56+
end
57+
58+
##
59+
# Wrap print to colorize the output.
60+
61+
def print o
62+
case o
63+
when "." then
64+
io.print pride o
65+
when "E", "F" then
66+
io.print "#{ESC}41m#{ESC}37m#{o}#{NND}"
67+
when "S" then
68+
io.print pride o
69+
else
70+
io.print o
71+
end
72+
end
73+
74+
def puts(*o) # :nodoc:
75+
o.map! { |s|
76+
s.to_s.sub(/Finished/) {
77+
@index = 0
78+
'Fabulous run'.split(//).map { |c|
79+
pride(c)
80+
}.join
81+
}
82+
}
83+
84+
super
85+
end
86+
87+
##
88+
# Color a string.
89+
90+
def pride string
91+
string = "*" if string == "."
92+
c = @colors[@index % @size]
93+
@index += 1
94+
"#{ESC}#{c}m#{string}#{NND}"
95+
end
96+
97+
def method_missing msg, *args # :nodoc:
98+
io.send(msg, *args)
99+
end
100+
end
101+
102+
##
103+
# If you thought the PrideIO was colorful...
104+
#
105+
# (Inspired by lolcat, but with clean math)
106+
107+
class PrideLOL < PrideIO
108+
PI_3 = Math::PI / 3 # :nodoc:
109+
110+
def initialize io # :nodoc:
111+
# walk red, green, and blue around a circle separated by equal thirds.
112+
#
113+
# To visualize, type this into wolfram-alpha:
114+
#
115+
# plot (3*sin(x)+3), (3*sin(x+2*pi/3)+3), (3*sin(x+4*pi/3)+3)
116+
117+
# 6 has wide pretty gradients. 3 == lolcat, about half the width
118+
@colors = (0...(6 * 7)).map { |n|
119+
n *= 1.0 / 6
120+
r = (3 * Math.sin(n ) + 3).to_i
121+
g = (3 * Math.sin(n + 2 * PI_3) + 3).to_i
122+
b = (3 * Math.sin(n + 4 * PI_3) + 3).to_i
123+
124+
# Then we take rgb and encode them in a single number using base 6.
125+
# For some mysterious reason, we add 16... to clear the bottom 4 bits?
126+
# Yes... they're ugly.
127+
128+
36 * r + 6 * g + b + 16
129+
}
130+
131+
super
132+
end
133+
134+
##
135+
# Make the string even more colorful. Damnit.
136+
137+
def pride string
138+
c = @colors[@index % @size]
139+
@index += 1
140+
"#{ESC}38;5;#{c}m#{string}#{NND}"
141+
end
142+
end
143+
end

0 commit comments

Comments
 (0)