Module: Datadog::CI::TestVisibility::TotalCoverage

Defined in:
lib/datadog/ci/test_visibility/total_coverage.rb

Class Method Summary collapse

Class Method Details

.extract_lines_pct(test_session) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/datadog/ci/test_visibility/total_coverage.rb', line 9

def self.extract_lines_pct(test_session)
  unless defined?(::SimpleCov)
    Datadog.logger.debug("SimpleCov is not loaded, skipping code coverage extraction")
    return
  end

  unless ::SimpleCov.running
    Datadog.logger.debug("SimpleCov is not running, skipping code coverage extraction")
    return
  end

  unless ::SimpleCov.respond_to?(:__dd_peek_result)
    Datadog.logger.debug("SimpleCov is not patched, skipping code coverage extraction")
    return
  end

  result = ::SimpleCov.__dd_peek_result
  unless result
    Datadog.logger.debug("SimpleCov result is nil, skipping code coverage extraction")
    return
  end

  test_session.set_tag(Ext::Test::TAG_CODE_COVERAGE_LINES_PCT, result.covered_percent)
end