Author: kclark
Date: Thu Jun 26 11:45:19 2008
New Revision: 671984

URL: http://svn.apache.org/viewvc?rev=671984&view=rev
Log:
rb: The deprecation stuff should skip thrift library code when showing caller 
[THRIFT-56]

Author: Kevin Ballard <[EMAIL PROTECTED]>

Modified:
    incubator/thrift/trunk/lib/rb/lib/thrift/deprecation.rb
    incubator/thrift/trunk/lib/rb/spec/deprecation_spec.rb

Modified: incubator/thrift/trunk/lib/rb/lib/thrift/deprecation.rb
URL: 
http://svn.apache.org/viewvc/incubator/thrift/trunk/lib/rb/lib/thrift/deprecation.rb?rev=671984&r1=671983&r2=671984&view=diff
==============================================================================
--- incubator/thrift/trunk/lib/rb/lib/thrift/deprecation.rb (original)
+++ incubator/thrift/trunk/lib/rb/lib/thrift/deprecation.rb Thu Jun 26 11:45:19 
2008
@@ -62,7 +62,7 @@
           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__
@@ -92,7 +92,7 @@
         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)
@@ -109,7 +109,7 @@
           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
@@ -119,6 +119,10 @@
     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

Modified: incubator/thrift/trunk/lib/rb/spec/deprecation_spec.rb
URL: 
http://svn.apache.org/viewvc/incubator/thrift/trunk/lib/rb/spec/deprecation_spec.rb?rev=671984&r1=671983&r2=671984&view=diff
==============================================================================
--- incubator/thrift/trunk/lib/rb/spec/deprecation_spec.rb (original)
+++ incubator/thrift/trunk/lib/rb/spec/deprecation_spec.rb Thu Jun 26 11:45:19 
2008
@@ -311,12 +311,14 @@
 
   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
@@ -423,4 +425,15 @@
       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


Reply via email to