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

Improve coverage tracking #16204

Merged
merged 1 commit into from
Nov 11, 2023
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
33 changes: 19 additions & 14 deletions Library/Homebrew/.simplecov
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ SimpleCov.start do
.map { |p| "#{p}/**/*.rb" }.join(",")
files = "#{SimpleCov.root}/{#{subdirs},*.rb}"

if ENV["HOMEBREW_INTEGRATION_TEST"]
if (integration_test_number = ENV.fetch("HOMEBREW_INTEGRATION_TEST", nil))
# This needs a unique name so it won't be overwritten
command_name "brew_i#{ENV.fetch("TEST_ENV_NUMBER", $PROCESS_ID)}"
command_name "brew_i:#{integration_test_number}"

# be quiet, the parent process will be in charge of output and checking coverage totals
SimpleCov.print_error_status = false
Expand All @@ -51,21 +51,23 @@ SimpleCov.start do
raise if $ERROR_INFO.is_a?(SystemExit)
end
else
command_name "brew#{ENV.fetch("TEST_ENV_NUMBER", $PROCESS_ID)}"
command_name "brew:#{ENV.fetch("TEST_ENV_NUMBER", $PROCESS_ID)}"

# Not using this during integration tests makes the tests 4x times faster
# without changing the coverage.
track_files files
end

add_filter %r{^/build.rb$}
add_filter %r{^/config.rb$}
add_filter %r{^/constants.rb$}
add_filter %r{^/postinstall.rb$}
add_filter %r{^/test.rb$}
add_filter %r{^/dev-cmd/tests.rb$}
add_filter %r{^/build\.rb$}
add_filter %r{^/config\.rb$}
add_filter %r{^/constants\.rb$}
add_filter %r{^/postinstall\.rb$}
add_filter %r{^/test\.rb$}
add_filter %r{^/dev-cmd/tests\.rb$}
add_filter %r{^/sorbet/}
add_filter %r{^/test/}
add_filter %r{^/vendor/}
add_filter %r{^/yard/}

require "rbconfig"
host_os = RbConfig::CONFIG["host_os"]
Expand All @@ -74,15 +76,18 @@ SimpleCov.start do

# Add groups and the proper project name to the output.
project_name "Homebrew"
add_group "Cask", %r{^/cask/}
add_group "Cask", %r{^/cask(/|\.rb$)}
add_group "Commands", [%r{/cmd/}, %r{^/dev-cmd/}]
add_group "Extensions", %r{^/extend/}
add_group "Livecheck", %r{^/livecheck(/|\.rb$)}
add_group "OS", [%r{^/extend/os/}, %r{^/os/}]
add_group "Requirements", %r{^/requirements/}
add_group "RuboCops", %r{^/rubocops/}
add_group "Unpack Strategies", %r{^/unpack_strategy(/|\.rb$)}
add_group "Scripts", [
%r{^/brew.rb$},
%r{^/build.rb$},
%r{^/postinstall.rb$},
%r{^/test.rb$},
%r{^/brew\.rb$},
%r{^/build\.rb$},
%r{^/postinstall\.rb$},
%r{^/test\.rb$},
]
end
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,9 @@ def expects_call_stack_jump?

# Generate unique ID to be able to
# properly merge coverage results.
def command_id_from_args(args)
@command_count ||= 0
pretty_args = args.join(" ").gsub(TEST_TMPDIR, "@TMPDIR@")
file_and_line = caller.second
.sub(/(.*\d+):.*/, '\1')
.sub("#{HOMEBREW_LIBRARY_PATH}/test/", "")
"#{file_and_line}:brew #{pretty_args}:#{@command_count += 1}"
def command_id
Thread.current[:brew_integration_test_number] ||= 0
"#{ENV.fetch("TEST_ENV_NUMBER", "")}:#{Thread.current[:brew_integration_test_number] += 1}"
end

# Runs a `brew` command with the test configuration
Expand All @@ -81,7 +77,7 @@ def brew(*args)
"PATH" => path,
"HOMEBREW_PATH" => path,
"HOMEBREW_BREW_FILE" => HOMEBREW_PREFIX/"bin/brew",
"HOMEBREW_INTEGRATION_TEST" => command_id_from_args(args),
"HOMEBREW_INTEGRATION_TEST" => command_id,
"HOMEBREW_TEST_TMPDIR" => TEST_TMPDIR,
"HOMEBREW_DEV_CMD_RUN" => "true",
"HOMEBREW_USE_RUBY_FROM_PATH" => ENV.fetch("HOMEBREW_USE_RUBY_FROM_PATH", nil),
Expand All @@ -103,19 +99,11 @@ def brew(*args)
onoe e
end
end
libs = specs.flat_map do |spec|
full_gem_path = spec.full_gem_path
# full_require_paths isn't available in RubyGems < 2.2.
spec.require_paths.map do |lib|
next lib if lib.include?(full_gem_path)

"#{full_gem_path}/#{lib}"
end
end
libs.each { |lib| ruby_args << "-I" << lib }
specs.flat_map(&:full_require_paths).each { |lib| ruby_args << "-I" << lib }
ruby_args << "-rsimplecov"
end
ruby_args << "-r#{HOMEBREW_LIBRARY_PATH}/test/support/helper/integration_mocks"
ruby_args << "-e" << "$0 = ARGV.shift; load($0)"
ruby_args << (HOMEBREW_LIBRARY_PATH/"brew.rb").resolved_path.to_s
end

Expand Down