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

Adding Test Coverage to Console Tests #999

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,5 @@ gem "rake-compiler"
gem "test-unit", "~> 3.0"
gem "test-unit-rr"
gem "json-schema"

gem 'simplecov'
17 changes: 16 additions & 1 deletion test/support/console_test_case.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down
14 changes: 14 additions & 0 deletions test/support/simplecov_rdbg.rb
Original file line number Diff line number Diff line change
@@ -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)
3 changes: 2 additions & 1 deletion test/support/test_case.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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']
Expand Down