From fc964eed7abd7e762e2e6ae61af5137f8ce71c52 Mon Sep 17 00:00:00 2001 From: Kevin Clark Date: Wed, 18 Jun 2008 00:57:46 +0000 Subject: [PATCH] Add caller info to the deprecation warning git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@668915 13f79535-47bb-0310-9956-ffa450edef68 --- lib/rb/lib/thrift/deprecation.rb | 1 + lib/rb/spec/deprecation_spec.rb | 8 +++++--- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/lib/rb/lib/thrift/deprecation.rb b/lib/rb/lib/thrift/deprecation.rb index 2f7d8986..b3fd12e5 100644 --- a/lib/rb/lib/thrift/deprecation.rb +++ b/lib/rb/lib/thrift/deprecation.rb @@ -17,6 +17,7 @@ class Module def #{old}(*args, &block) old, new = #{[old,new].inspect} STDERR.puts "Warning: calling deprecated method \#{self.is_a?(Module) ? "\#{self}." : "\#{self.class}#"}\#{old}" + STDERR.puts " from \#{caller.first}" target = (self.is_a?(Module) ? (class << self;self;end) : self.class) target.send :define_method, old, target.instance_method(new) # unwrap target.instance_method(new).bind(self).call(*args, &block) diff --git a/lib/rb/spec/deprecation_spec.rb b/lib/rb/spec/deprecation_spec.rb index 03a7427d..08e1504d 100644 --- a/lib/rb/spec/deprecation_spec.rb +++ b/lib/rb/spec/deprecation_spec.rb @@ -18,8 +18,10 @@ end describe 'deprecate!' do it_should_behave_like "deprecation" - def stub_stderr(callstr) + def stub_stderr(callstr, offset=1) STDERR.should_receive(:puts).with("Warning: calling deprecated method #{callstr}") + line = caller.first[/\d+$/].to_i + offset + STDERR.should_receive(:puts).with(" from #{__FILE__}:#{line}") end it "should work for Module methods" do @@ -95,8 +97,8 @@ describe 'deprecate!' do end deprecate! :old1 => :new1, :old2 => :new2 end - stub_stderr("#{klass.inspect}#old1").ordered - stub_stderr("#{klass.inspect}#old2").ordered + stub_stderr("#{klass.inspect}#old1", 3).ordered + stub_stderr("#{klass.inspect}#old2", 3).ordered inst = klass.new inst.old1.should == "new 1" inst.old2.should == "new 2" -- 2.17.1