diff --git a/Gemfile b/Gemfile index c59ccbe1a..58e8fe976 100644 --- a/Gemfile +++ b/Gemfile @@ -7,3 +7,5 @@ gem "rake-compiler" gem "test-unit", "~> 3.0" gem "test-unit-rr" gem "json-schema" + +gem 'simplecov' diff --git a/test/support/console_test_case.rb b/test/support/console_test_case.rb index 49e0bb87f..495fb3066 100644 --- a/test/support/console_test_case.rb +++ b/test/support/console_test_case.rb @@ -9,6 +9,15 @@ class ConsoleTestCase < TestCase warn "Tests on local and remote. You can disable remote tests with RUBY_DEBUG_TEST_NO_REMOTE=1." end + if WITH_COVERAGE + require "simplecov" + + Test::Unit.at_exit do + SimpleCov.start + SimpleCov.at_exit_behavior + end + end + # CIs usually doesn't allow overriding the HOME path # we also don't need to worry about adding or being affected by ~/.rdbgrc on CI # so we can just use the original home page there @@ -250,7 +259,13 @@ def manual_debug_code(program) private def debug_code_on_local test_info = TestInfo.new(dup_scenario, 'LOCAL', /\(rdbg\)/) - cmd = "#{RDBG_EXECUTABLE} #{temp_file_path}" + + if WITH_COVERAGE + cmd = "#{RUBY} -I#{Dir.pwd}/lib -r#{__dir__}/simplecov_rdbg #{temp_file_path}" + else + cmd = "#{RDBG_EXECUTABLE} #{temp_file_path}" + end + run_test_scenario cmd, test_info end diff --git a/test/support/simplecov_rdbg.rb b/test/support/simplecov_rdbg.rb new file mode 100644 index 000000000..ec37b5ee4 --- /dev/null +++ b/test/support/simplecov_rdbg.rb @@ -0,0 +1,14 @@ +# Start simplecov as a spawned process before debugger starts +require 'simplecov' +SimpleCov.command_name "spawn" +SimpleCov.at_fork.call(Process.pid) +SimpleCov.start + +require "debug/session" +# Make sure simplecov is in the skip_path +simplecov_path = Gem.loaded_specs['simplecov'].full_require_paths.freeze + Gem.loaded_specs['simplecov-html'].full_require_paths.freeze +DEBUGGER__::CONFIG[:skip_path] = Array(DEBUGGER__::CONFIG[:skip_path]) + simplecov_path + RbConfig::CONFIG['rubylibprefix'].split(':') + +# Start debugger similar to how it is started in exe/rdbg +DEBUGGER__.start no_sigint_hook: false, nonstop: true +DEBUGGER__::SESSION.add_line_breakpoint($0, 0, oneshot: true, hook_call: false) diff --git a/test/support/test_case.rb b/test/support/test_case.rb index fae5b9f58..d6115d3a4 100644 --- a/test/support/test_case.rb +++ b/test/support/test_case.rb @@ -96,7 +96,8 @@ def debug_print msg RUBY = ENV['RUBY'] || RbConfig.ruby RDBG_EXECUTABLE = "#{RUBY} #{__dir__}/../../exe/rdbg" - TIMEOUT_SEC = (ENV['RUBY_DEBUG_TIMEOUT_SEC'] || 10).to_i + WITH_COVERAGE = ENV['COVERAGE'] == 'true' || ENV['COVERAGE'] == '1' + TIMEOUT_SEC = (ENV['RUBY_DEBUG_TIMEOUT_SEC'] || 10).to_i * (WITH_COVERAGE ? 3 : 1) def get_target_ui ENV['RUBY_DEBUG_TEST_UI']