Skip to content

Commit

Permalink
Make tracer integration skip IRB traces
Browse files Browse the repository at this point in the history
  • Loading branch information
st0012 committed Feb 7, 2024
1 parent ea4f147 commit ee0ad19
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
7 changes: 7 additions & 0 deletions lib/irb/ext/tracer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,13 @@
end

module IRB
class CallTracer < ::CallTracer
IRB_DIR = File.expand_path('../..', __dir__)

def skip?(tp)
super || tp.path.match?(IRB_DIR) || tp.path.match?('<internal:prelude>')
end
end
class WorkSpace
alias __evaluate__ evaluate
# Evaluate the context of this workspace and use the Tracer library to
Expand Down
9 changes: 6 additions & 3 deletions test/irb/test_tracer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def test_use_tracer_enabled_when_gem_is_unavailable

output = run_ruby_file do
type "bar(Foo)"
type "exit!"
type "exit"
end

assert_include(output, "Tracer extension of IRB is enabled but tracer gem wasn't found.")
Expand All @@ -63,21 +63,24 @@ def test_use_tracer_enabled_when_gem_is_available

output = run_ruby_file do
type "bar(Foo)"
type "exit!"
type "exit"
end

assert_include(output, "Object#bar at")
assert_include(output, "Foo.foo at")
assert_include(output, "Foo.foo #=> 100")
assert_include(output, "Object#bar #=> 100")

# Test that the tracer output does not include IRB's own files
assert_not_include(output, "irb/workspace.rb")
end

def test_use_tracer_is_disabled_by_default
write_ruby example_ruby_file

output = run_ruby_file do
type "bar(Foo)"
type "exit!"
type "exit"
end

assert_not_include(output, "#depth:")
Expand Down

0 comments on commit ee0ad19

Please sign in to comment.