obj, name, warned = CLASS_MAPPING[klass_id]
unless warned
STDERR.puts "Warning: class #{name} is deprecated"
- STDERR.puts " from #{caller.first}"
+ STDERR.puts " from #{Thrift::DeprecationProxy.process_caller(caller)}"
CLASS_MAPPING[klass_id][2] = true
end
if klass.__id__ == self.__id__
obj, name, warned = MODULE_MAPPING[mod_id]
unless warned
STDERR.puts "Warning: module #{name} is deprecated"
- STDERR.puts " from #{caller.first}"
+ STDERR.puts " from #{Thrift::DeprecationProxy.process_caller(caller)}"
MODULE_MAPPING[mod_id][2] = true
end
obj.instance_method(sym).bind(self).call(*args, &block)
obj, name, warned = MODULE_MAPPING[mod_id]
unless warned
STDERR.puts "Warning: module #{name} is deprecated"
- STDERR.puts " from #{caller.first}"
+ STDERR.puts " from #{Thrift::DeprecationProxy.process_caller(caller)}"
MODULE_MAPPING[mod_id][2] = true
end
obj.send sym, *args, &block
MODULE_MAPPING[mod_id][2] = false
mod
end
+ def self.process_caller(stack)
+ dir = File.dirname(__FILE__)
+ stack.find { |frame| frame[0,dir.size] != dir }
+ end
end
module Kernel
def stub_stderr(mod, offset=1, called=nil)
STDERR.should_receive(:puts).with("Warning: module #{mod} is deprecated")
+ source = Regexp.escape(__FILE__) + ":"
if offset
line = (called || caller.first)[/\d+$/].to_i + offset
- STDERR.should_receive(:puts).with(" from #{__FILE__}:#{line}")
+ source += Regexp.escape(line.to_s)
else
- STDERR.should_receive(:puts).with(/^ from #{Regexp.escape(__FILE__)}:/)
+ source += "\d+"
end
+ STDERR.should_receive(:puts).with(/^ from #{source}(?::in `[^']+')?$/)
end
it "should create a new global constant that points to the old one" do
end
end
end
+
+ it "should skip thrift library code when printing caller" do
+ klass = Class.new do
+ include ThriftStruct
+ FIELDS = {
+ 1 => {:name => "foo", :type => Thrift::Types::STRING}
+ }
+ end
+ stub_stderr('ThriftStruct')
+ klass.new(:foo => "foo")
+ end
end