Skip to content

Commit

Permalink
minitest: use class constant location as test suite source location
Browse files Browse the repository at this point in the history
  • Loading branch information
anmarchenko committed Mar 11, 2024
1 parent ed680fa commit 09c647b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
16 changes: 15 additions & 1 deletion lib/datadog/ci/contrib/minitest/helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,12 @@ module Contrib
module Minitest
module Helpers
def self.test_suite_name(klass, method_name)
source_location, = klass.instance_method(method_name).source_location
source_location = extract_source_location_from_class(klass)
# if we are in anonymous class, fallback to the method source location
if source_location.nil?
source_location, = klass.instance_method(method_name).source_location
end

source_file_path = Pathname.new(source_location.to_s).relative_path_from(Pathname.pwd).to_s

"#{klass.name} at #{source_file_path}"
Expand All @@ -16,6 +21,15 @@ def self.parallel?(klass)
klass.ancestors.include?(::Minitest::Parallel::Test) ||
(defined?(::Minitest::Queue) && ::Minitest.singleton_class.ancestors.include?(::Minitest::Queue))
end

def self.extract_source_location_from_class(klass)
return nil if klass.nil? || klass.name.nil?

source_location = klass.const_source_location(klass.name)
source_location.first unless source_location.nil?
rescue
nil
end
end
end
end
Expand Down
2 changes: 2 additions & 0 deletions sig/datadog/ci/contrib/minitest/helpers.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ module Datadog
def self.test_suite_name: (untyped klass, String? method_name) -> ::String

def self.parallel?: (untyped klass) -> bool

def self.extract_source_location_from_class: (untyped klass) -> String?
end
end
end
Expand Down

0 comments on commit 09c647b

Please sign in to comment.