ruby-changes:20237
From: nagachika <ko1@a...>
Date: Wed, 29 Jun 2011 22:20:35 +0900 (JST)
Subject: [ruby-changes:20237] nagachika:r32285 (trunk): * lib/tracer.rb: Tracer.on only if required by -r command-line option.
nagachika 2011-06-29 22:19:59 +0900 (Wed, 29 Jun 2011) New Revision: 32285 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=32285 Log: * lib/tracer.rb: Tracer.on only if required by -r command-line option. and consider --disable-gems option. * test/test_tracer.rb: add tests for it. Modified files: trunk/ChangeLog trunk/lib/tracer.rb trunk/test/test_tracer.rb Index: ChangeLog =================================================================== --- ChangeLog (revision 32284) +++ ChangeLog (revision 32285) @@ -1,3 +1,9 @@ +Wed Jun 29 22:04:14 2011 CHIKANAGA Tomoyuki <nagachika00@g...> + + * lib/tracer.rb: Tracer.on only if required by -r command-line option. + and consider --disable-gems option. + * test/test_tracer.rb: add tests for it. + Wed Jun 29 13:55:36 2011 Yukihiro Matsumoto <matz@r...> * variable.c (rb_const_get_0): should not look for superclasses if Index: lib/tracer.rb =================================================================== --- lib/tracer.rb (revision 32284) +++ lib/tracer.rb (revision 32285) @@ -287,7 +287,12 @@ ARGV.shift Tracer.on require $0 -elsif caller.count {|bt| /\/rubygems\/custom_require.rb:/ !~ bt} <= 1 - Tracer.on +else + # call Tracer.on only if required by -r command-line option + count = caller.count {|bt| /\/rubygems\/custom_require.rb:/ !~ bt} + if (defined?(Gem) and count == 0) or + (!defined?(Gem) and count <= 1) + Tracer.on + end end # :startdoc: Index: test/test_tracer.rb =================================================================== --- test/test_tracer.rb (revision 32284) +++ test/test_tracer.rb (revision 32285) @@ -1,14 +1,15 @@ require 'test/unit' +require 'tmpdir' require_relative 'ruby/envutil' class TestTracer < Test::Unit::TestCase include EnvUtil - def test_work_with_e - assert_in_out_err(%w[--disable-gems -rtracer -e 1]) do |(*lines),| + def test_tracer_with_option_r + assert_in_out_err(%w[-rtracer -e 1]) do |(*lines),| case lines.size when 2 - assert_match %r[#0:<internal:lib/rubygems/custom_require>:\d+:Kernel:<: -], lines[0] + assert_match(%r{rubygems/custom_require\.rb:\d+:Kernel:<:}, lines[0]) when 1 # do nothing else @@ -17,4 +18,46 @@ assert_equal "#0:-e:1::-: 1", lines.last end end + + def test_tracer_with_option_r_without_gems + assert_in_out_err(%w[--disable-gems -rtracer -e 1]) do |(*lines),| + case lines.size + when 1 + # do nothing + else + flunk "unexpected output from `ruby --disable-gems -rtracer -e 1`" + end + assert_equal "#0:-e:1::-: 1", lines.last + end + end + + def test_tracer_with_require + Dir.mktmpdir("test_ruby_tracer") do |dir| + script = File.join(dir, "require_tracer.rb") + open(script, "w") do |f| + f.print <<-EOF +require 'tracer' +1 + EOF + end + assert_in_out_err([script]) do |(*lines),| + assert_empty(lines) + end + end + end + + def test_tracer_with_require_without_gems + Dir.mktmpdir("test_ruby_tracer") do |dir| + script = File.join(dir, "require_tracer.rb") + open(script, "w") do |f| + f.print <<-EOF +require 'tracer' +1 + EOF + end + assert_in_out_err(["--disable-gems", script]) do |(*lines),| + assert_empty(lines) + end + end + end end -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/