Skip to content

Commit

Permalink
Merge pull request #49 from alpaca-tc/fix-singleton-class-name
Browse files Browse the repository at this point in the history
Early return nil if source_name is nil
  • Loading branch information
alpaca-tc authored May 23, 2024
2 parents 4595134 + 44fa242 commit ab9d8b4
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 0 deletions.
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

0 comments on commit ab9d8b4

Please sign in to comment.