brew/Library/Homebrew/.simplecov

92 lines
3.2 KiB
Plaintext
Raw Normal View History

2016-08-21 07:51:25 +02:00
#!/usr/bin/env ruby
2020-07-02 10:22:54 +01:00
# frozen_string_literal: true
require "English"
2016-09-25 00:51:09 +02:00
SimpleCov.enable_for_subprocesses true
SimpleCov.start do
coverage_dir File.expand_path("../test/coverage", File.realpath(__FILE__))
root File.expand_path("..", File.realpath(__FILE__))
2022-02-22 15:27:43 +00:00
# enables branch coverage as well as, the default, line coverage
enable_coverage :branch
# We manage the result cache ourselves and the default of 10 minutes can be
# too low (particularly on Travis CI), causing results from some integration
# tests to be dropped. This causes random fluctuations in test coverage.
merge_timeout 86400
at_fork do |pid|
# This needs a unique name so it won't be ovewritten
command_name "#{SimpleCov.command_name} (#{pid})"
# be quiet, the parent process will be in charge of output and checking coverage totals
2020-08-31 02:29:54 +02:00
SimpleCov.print_error_status = false
end
2021-04-06 22:53:05 +09:00
excludes = ["test", "vendor"]
2021-04-12 22:43:56 +09:00
subdirs = Dir.chdir(SimpleCov.root) { Pathname.glob("*") }
.reject { |p| p.extname == ".rb" || excludes.include?(p.to_s) }
.map { |p| "#{p}/**/*.rb" }.join(",")
2021-04-06 22:53:05 +09:00
files = "#{SimpleCov.root}/{#{subdirs},*.rb}"
if ENV["HOMEBREW_INTEGRATION_TEST"]
# This needs a unique name so it won't be ovewritten
2016-09-25 00:51:09 +02:00
command_name "#{ENV["HOMEBREW_INTEGRATION_TEST"]} (#{$PROCESS_ID})"
# be quiet, the parent process will be in charge of output and checking coverage totals
2020-08-31 02:29:54 +02:00
SimpleCov.print_error_status = false
2020-11-29 16:08:10 +01:00
SimpleCov.at_exit do
# Just save result, but don't write formatted output.
2021-04-08 23:03:28 +09:00
coverage_result = Coverage.result.dup
2021-04-06 22:53:05 +09:00
Dir[files].each do |file|
absolute_path = File.expand_path(file)
2021-04-08 23:03:28 +09:00
coverage_result[absolute_path] ||= SimpleCov::SimulateCoverage.call(absolute_path)
2021-04-06 22:53:05 +09:00
end
simplecov_result = SimpleCov::Result.new(coverage_result)
SimpleCov::ResultMerger.store_result(simplecov_result)
# If an integration test raises a `SystemExit` exception on exit,
# exit immediately using the same status code to avoid reporting
# an error when expecting a non-successful exit status.
raise if $ERROR_INFO.is_a?(SystemExit)
end
else
2016-09-25 00:51:09 +02:00
command_name "#{command_name} (#{$PROCESS_ID})"
2017-10-08 14:14:15 +02:00
# Not using this during integration tests makes the tests 4x times faster
# without changing the coverage.
2021-04-06 22:53:05 +09:00
track_files files
2016-01-27 22:03:17 +01:00
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{^/compat/}
add_filter %r{^/dev-cmd/tests.rb$}
add_filter %r{^/test/}
add_filter %r{^/vendor/}
require "rbconfig"
2018-06-13 07:17:17 +02:00
host_os = RbConfig::CONFIG["host_os"]
2020-07-02 10:22:54 +01:00
add_filter %r{/os/mac} unless /darwin/.match?(host_os)
add_filter %r{/os/linux} unless /linux/.match?(host_os)
# Add groups and the proper project name to the output.
project_name "Homebrew"
add_group "Cask", %r{^/cask/}
add_group "Commands", [%r{/cmd/}, %r{^/dev-cmd/}]
add_group "Extensions", %r{^/extend/}
add_group "OS", [%r{^/extend/os/}, %r{^/os/}]
add_group "Requirements", %r{^/requirements/}
add_group "Scripts", [
%r{^/brew.rb$},
%r{^/build.rb$},
%r{^/postinstall.rb$},
%r{^/test.rb$},
]
end