test/unit.rb: most-asserted
* test/lib/test/unit.rb (Statistics#record): record most asserted tests. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57559 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
950d15bc97
commit
a02a8dfa5a
@ -587,12 +587,22 @@ module Test
|
|||||||
end
|
end
|
||||||
|
|
||||||
module Statistics
|
module Statistics
|
||||||
|
def update_list(list, rec, max)
|
||||||
|
if i = list.empty? ? 0 : list.bsearch_index {|*a| yield(*a)}
|
||||||
|
list[i, 0] = [rec]
|
||||||
|
list[max..-1] = [] if list.size >= max
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def record(suite, method, assertions, time, error)
|
def record(suite, method, assertions, time, error)
|
||||||
if max = @options[:longest]
|
if @options.values_at(:longest, :most_asserted).any?
|
||||||
longest = @longest ||= []
|
@tops ||= {}
|
||||||
if i = longest.empty? ? 0 : longest.bsearch_index {|_,_,_,t,_|t<time}
|
rec = [suite.name, method, assertions, time, error]
|
||||||
longest[i, 0] = [[suite.name, method, assertions, time, error]]
|
if max = @options[:longest]
|
||||||
longest[max..-1] = [] if longest.size >= max
|
update_list(@tops[:longest] ||= [], rec, max) {|_,_,_,t,_|t<time}
|
||||||
|
end
|
||||||
|
if max = @options[:most_asserted]
|
||||||
|
update_list(@tops[:most_asserted] ||= [], rec, max) {|_,_,a,_,_|a<assertions}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
# (((@record ||= {})[suite] ||= {})[method]) = [assertions, time, error]
|
# (((@record ||= {})[suite] ||= {})[method]) = [assertions, time, error]
|
||||||
@ -601,10 +611,15 @@ module Test
|
|||||||
|
|
||||||
def run(*args)
|
def run(*args)
|
||||||
result = super
|
result = super
|
||||||
if defined?(@longest) and @longest
|
if @tops ||= nil
|
||||||
@longest.each {|suite, method, assertions, time, error|
|
@tops.each do |t, list|
|
||||||
printf "%5.2fsec(%d): %s#%s\n", time, assertions, suite, method
|
if list
|
||||||
}
|
puts "#{t.to_s.tr('_', ' ')} tests:"
|
||||||
|
list.each {|suite, method, assertions, time, error|
|
||||||
|
printf "%5.2fsec(%d): %s#%s\n", time, assertions, suite, method
|
||||||
|
}
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
result
|
result
|
||||||
end
|
end
|
||||||
@ -616,6 +631,9 @@ module Test
|
|||||||
opts.on '--longest=N', Integer, 'Show longest N tests' do |n|
|
opts.on '--longest=N', Integer, 'Show longest N tests' do |n|
|
||||||
options[:longest] = n
|
options[:longest] = n
|
||||||
end
|
end
|
||||||
|
opts.on '--most-asserted=N', Integer, 'Show most asserted N tests' do |n|
|
||||||
|
options[:most_asserted] = n
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user