Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Early return nil if source_name is nil #49

Merged
merged 1 commit into from
May 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions lib/diver_down/trace/session.rb
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,8 @@ def normalize_module_name(mod, tp)
end

def constantizable_source_name(source_name)
return if source_name.nil?

DiverDown::Helper.constantize(source_name)
source_name
rescue NameError
Expand Down
37 changes: 37 additions & 0 deletions spec/diver_down/trace/tracer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -782,6 +782,43 @@ def self.wrap
))
end

it 'traces tracer_nil_name_class.rb' do
definition = trace_fixture(
'tracer_nil_name_class.rb',
caller_paths: [fixture_path('tracer_nil_name_class.rb')],
module_set: {
paths: [fixture_path('tracer_nil_name_class.rb')],
}
)

expect(definition.to_h).to match(fill_default(
title: 'title',
sources: [
{
source_name: 'AntipollutionModule::A',
dependencies: [
{
source_name: 'AntipollutionModule::B',
method_ids: [
{
name: 'call_b',
context: 'class',
paths: [
match(/tracer_nil_name_class\.rb:\d+/),
],
},
],
},
],
},
{
source_name: 'AntipollutionModule::B',
dependencies: [],
},
]
))
end

it 'traces wrapped in the module to be target before starting the trace' do
dir = Dir.mktmpdir
File.write(File.join(dir, 'a.rb'), <<~RUBY)
Expand Down
17 changes: 17 additions & 0 deletions spec/fixtures/tracer_nil_name_class.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
def run
class_a = Class.new(A) do
def self.name = nil
end

class_a.call_b
end

class A
def self.call_b
B.call_b
end
end

class B
def self.call_b = ''
end