summaryrefslogtreecommitdiff
path: root/test/test_tracer.rb
diff options
context:
space:
mode:
Diffstat (limited to 'test/test_tracer.rb')
-rw-r--r--test/test_tracer.rb73
1 files changed, 73 insertions, 0 deletions
diff --git a/test/test_tracer.rb b/test/test_tracer.rb
index 6622b53663..634501c11a 100644
--- a/test/test_tracer.rb
+++ b/test/test_tracer.rb
@@ -53,4 +53,77 @@ require 'tracer'
end
end
end
+
+ def test_tracer_by_add_filter_with_block
+ Dir.mktmpdir("test_ruby_tracer") do |dir|
+ script = File.join(dir, "require_tracer.rb")
+ open(script, "w") do |f|
+ f.print <<-'EOF'
+require 'tracer'
+
+class Hoge
+ def Hoge.fuga(i)
+ "fuga #{i}"
+ end
+end
+
+Tracer.add_filter {|event, file, line, id, binding, klass|
+ event =~ /line/ and klass.to_s =~ /hoge/i
+}
+Tracer.on
+for i in 0..3
+ puts Hoge.fuga(i) if i % 3 == 0
+end
+Tracer.off
+ EOF
+ end
+ assert_in_out_err([script]) do |(*lines), err|
+ expected = [
+ "#0:#{script}:5:Hoge:-: \"fuga \#{i}\"",
+ "fuga 0",
+ "#0:#{script}:5:Hoge:-: \"fuga \#{i}\"",
+ "fuga 3"
+ ]
+ assert_equal(expected, lines)
+ assert_empty(err)
+ end
+ end
+ end
+
+ def test_tracer_by_add_filter_with_proc
+ Dir.mktmpdir("test_ruby_tracer") do |dir|
+ script = File.join(dir, "require_tracer.rb")
+ open(script, "w") do |f|
+ f.print <<-'EOF'
+require 'tracer'
+
+class Hoge
+ def Hoge.fuga(i)
+ "fuga #{i}"
+ end
+end
+
+a_proc_to_add_filter = proc {|event, file, line, id, binding, klass|
+ event =~ /line/ and klass.to_s =~ /hoge/i
+}
+Tracer.add_filter(a_proc_to_add_filter)
+Tracer.on
+for i in 0..3
+ puts Hoge.fuga(i) if i % 3 == 0
+end
+Tracer.off
+ EOF
+ end
+ assert_in_out_err([script]) do |(*lines), err|
+ expected = [
+ "#0:#{script}:5:Hoge:-: \"fuga \#{i}\"",
+ "fuga 0",
+ "#0:#{script}:5:Hoge:-: \"fuga \#{i}\"",
+ "fuga 3"
+ ]
+ assert_equal(expected, lines)
+ assert_empty(err)
+ end
+ end
+ end
end