Skip to content
Browse files

make warning report even more concise (group all occurrences in a sin…

…gle file)
  • Loading branch information...
1 parent 0bbad5b commit 2a6497a23cff4c549d1b2b42cd8531d5dc7032e4 @alexch committed May 12, 2011
Showing with 46 additions and 8 deletions.
  1. +33 −5 lib/rubygems/deprecate.rb
  2. +13 −3 test/rubygems/test_deprecate.rb
View
38 lib/rubygems/deprecate.rb
@@ -54,12 +54,20 @@ def self.add_warning w # :nodoc:
def self.report
out = ""
out << "Some of your installed gems called deprecated methods. See http://blog.zenspider.com/2011/05/rubygems-18-is-coming.html for background. Use 'gem pristine --all' to fix or 'rubygems update --system 1.7.2' to downgrade.\n"
- last_message = nil
- warnings = @saved_warnings.sort_by{|w| w.full_name}.each do |w|
- out << (last_message = w.message) + "\n" unless last_message == w.message
- out << w.loc
- out << "\n"
+ last_warning = nil
+ warnings = @saved_warnings.sort.each do |w|
+ if last_warning and last_warning.target == w.target and last_warning.method_name == w.method_name
+ if last_warning.file == w.file
+ out << ",#{w.line}"
+ else
+ out << "\n#{w.loc}"
+ end
+ else
+ out << "\n#{w.message}\n#{w.loc}"
+ end
+ last_warning = w
end
+ out << "\n"
out
end
@@ -87,6 +95,18 @@ def ==(other)
location == other.location
end
+ def <=>(other)
+ self.compare_string <=> other.compare_string
+ end
+
+ def compare_string
+ [target, method_name, file, line].join('|')
+ end
+
+ def to_s
+ [target, method_name, replacement, year, month, location].map(&:inspect).join('|')
+ end
+
def message
[ "#{target}#{method_name} is deprecated",
replacement == :none ? " with no replacement" : "; use #{replacement} instead.",
@@ -101,6 +121,14 @@ def loc
def full_name
"#{target}#{method_name}"
end
+
+ def line
+ location.last
+ end
+
+ def file
+ location.first
+ end
end
##
View
16 test/rubygems/test_deprecate.rb
@@ -175,17 +175,27 @@ def test_report
thing.foo
thing.goo
thing.foo
+ # also throw one in from a different file
+ Deprecate.add_warning Deprecate::Warning.new({
+ :target => "TestDeprecate::Thing#",
+ :method_name => :foo,
+ :location => ["/some/other/file.rb", 99],
+ :replacement => :bar,
+ :year => 2099,
+ :month => 1
+ })
s = Deprecate.report
f = __FILE__
assert_equal s, <<-REPORT
Some of your installed gems called deprecated methods. See http://blog.zenspider.com/2011/05/rubygems-18-is-coming.html for background. Use 'gem pristine --all' to fix or 'rubygems update --system 1.7.2' to downgrade.
+
TestDeprecate::Thing#foo is deprecated; use bar instead. It will be removed on or after 2099-03-01.
- called from #{f}:#{line}
- called from #{f}:#{line+1}
- called from #{f}:#{line+3}
+ called from #{f}:#{line},#{line+1},#{line+3}
+ called from /some/other/file.rb:99
TestDeprecate::Thing#goo is deprecated; use bar instead. It will be removed on or after 2099-04-01.
called from #{f}:#{line+2}
REPORT
+
end
end
end

0 comments on commit 2a6497a

Please sign in to comment.
Something went wrong with that request. Please try again.