summaryrefslogtreecommitdiff
path: root/test/test_tracer.rb
diff options
context:
space:
mode:
authoraycabta <aycabta@gmail.com>2019-11-23 05:44:35 +0900
committeraycabta <aycabta@gmail.com>2019-11-23 05:44:35 +0900
commitb0614a0f968d40fb1bad31592fc9a607dbac447d (patch)
treeb00859e782eb898b7501fa0a073baa71c05bbb03 /test/test_tracer.rb
parent1ee010a3171978007a4550e8077f1e4b646bd80a (diff)
downloadruby-b0614a0f968d40fb1bad31592fc9a607dbac447d.tar.gz
Tracer.set_get_line_procs should support block and Proc object
Original Tracer.set_get_line_procs is implemented by "def set_get_line_procs(p = proc)". It means that original Tracer.set_get_line_procs supports block and Proc object.
Diffstat (limited to 'test/test_tracer.rb')
-rw-r--r--test/test_tracer.rb103
1 files changed, 103 insertions, 0 deletions
diff --git a/test/test_tracer.rb b/test/test_tracer.rb
index 634501c11a..c79b55251b 100644
--- a/test/test_tracer.rb
+++ b/test/test_tracer.rb
@@ -126,4 +126,107 @@ Tracer.off
end
end
end
+
+ def test_tracer_by_set_get_line_procs_with_block
+ Dir.mktmpdir("test_ruby_tracer") do |dir|
+ dummy_script = File.join(dir, "dummy.rb")
+ open(dummy_script, "w") do |f|
+ f.print <<-'EOF'
+class Dummy
+ def initialize
+ @number = 135
+ end
+ attr :number
+end
+ EOF
+ end
+ script = File.join(dir, "require_tracer.rb")
+ open(script, "w") do |f|
+ f.print <<-EOF
+require 'tracer'
+
+Tracer.set_get_line_procs('#{dummy_script}') { |line|
+ str = %{\\n}
+ str = %{!!\\n} if line >= 3 and line <= 6
+ str
+}
+Tracer.on
+require_relative 'dummy'
+
+dm = Dummy.new
+puts dm.number
+ EOF
+ end
+ assert_in_out_err([script]) do |(*lines), err|
+ expected = [
+ "#0:#{script}:9::-: require_relative 'dummy'",
+ "#0:#{dummy_script}:1::-: ",
+ "#0:#{dummy_script}:1::C: ",
+ "#0:#{dummy_script}:2::-: ",
+ "#0:#{dummy_script}:5::-: !!",
+ "#0:#{dummy_script}:6::E: !!",
+ "#0:#{script}:11::-: dm = Dummy.new",
+ "#0:#{dummy_script}:2:Dummy:>: ",
+ "#0:#{dummy_script}:3:Dummy:-: !!",
+ "#0:#{dummy_script}:4:Dummy:<: !!",
+ "#0:#{script}:12::-: puts dm.number",
+ "135"
+ ]
+ assert_equal(expected, lines)
+ assert_empty(err)
+ end
+ end
+ end
+
+ def test_tracer_by_set_get_line_procs_with_proc
+ Dir.mktmpdir("test_ruby_tracer") do |dir|
+ dummy_script = File.join(dir, "dummy.rb")
+ open(dummy_script, "w") do |f|
+ f.print <<-'EOF'
+class Dummy
+ def initialize
+ @number = 135
+ end
+ attr :number
+end
+ EOF
+ end
+ script = File.join(dir, "require_tracer.rb")
+ open(script, "w") do |f|
+ f.print <<-EOF
+require 'tracer'
+
+a_proc_to_set_get_line_procs = proc { |line|
+ str = %{\\n}
+ str = %{!!\\n} if line >= 3 and line <= 6
+ str
+}
+Tracer.set_get_line_procs('#{dummy_script}', a_proc_to_set_get_line_procs)
+Tracer.on
+require_relative 'dummy'
+
+dm = Dummy.new
+puts dm.number
+ EOF
+ end
+ assert_in_out_err([script]) do |(*lines), err|
+ expected = [
+ "#0:#{script}:10::-: require_relative 'dummy'",
+ "#0:#{dummy_script}:1::-: ",
+ "#0:#{dummy_script}:1::C: ",
+ "#0:#{dummy_script}:2::-: ",
+ "#0:#{dummy_script}:5::-: !!",
+ "#0:#{dummy_script}:6::E: !!",
+ "#0:#{script}:12::-: dm = Dummy.new",
+ "#0:#{dummy_script}:2:Dummy:>: ",
+ "#0:#{dummy_script}:3:Dummy:-: !!",
+ "#0:#{dummy_script}:4:Dummy:<: !!",
+ "#0:#{script}:13::-: puts dm.number",
+ "135"
+ ]
+ assert_equal(expected, lines)
+ assert_empty(err)
+ end
+ end
+ end
end