-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
initial simplecov instrumentation to report total coverage percentage
- Loading branch information
1 parent
17b2e4f
commit 9681ab4
Showing
18 changed files
with
298 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,4 +31,5 @@ target :lib do | |
library "capybara" | ||
library "timecop" | ||
library "webmock" | ||
library "simplecov" | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
lib/datadog/ci/contrib/simplecov/configuration/settings.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# frozen_string_literal: true | ||
|
||
require "datadog/core" | ||
|
||
require_relative "../ext" | ||
require_relative "../../settings" | ||
|
||
module Datadog | ||
module CI | ||
module Contrib | ||
module Simplecov | ||
module Configuration | ||
# Custom settings for the Simplecov integration | ||
# @public_api | ||
class Settings < Datadog::CI::Contrib::Settings | ||
option :enabled do |o| | ||
o.type :bool | ||
o.env Ext::ENV_ENABLED | ||
o.default true | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# frozen_string_literal: true | ||
|
||
module Datadog | ||
module CI | ||
module Contrib | ||
module Simplecov | ||
# Simplecov integration constants | ||
# @public_api | ||
module Ext | ||
ENV_ENABLED = "DD_CIVISIBILITY_SIMPLECOV_INSTRUMENTATION_ENABLED" | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
# frozen_string_literal: true | ||
|
||
require_relative "../integration" | ||
require_relative "configuration/settings" | ||
require_relative "patcher" | ||
|
||
module Datadog | ||
module CI | ||
module Contrib | ||
module Simplecov | ||
# Description of Simplecov integration | ||
class Integration | ||
include Datadog::CI::Contrib::Integration | ||
|
||
MINIMUM_VERSION = Gem::Version.new("0.18.0") | ||
|
||
register_as :simplecov | ||
|
||
def self.version | ||
Gem.loaded_specs["simplecov"]&.version | ||
end | ||
|
||
def self.loaded? | ||
!defined?(::SimpleCov).nil? | ||
end | ||
|
||
def self.compatible? | ||
super && version >= MINIMUM_VERSION | ||
end | ||
|
||
# additional instrumentations for test helpers are auto instrumented on test session start | ||
def auto_instrument? | ||
true | ||
end | ||
|
||
def new_configuration | ||
Configuration::Settings.new | ||
end | ||
|
||
def patcher | ||
Patcher | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# frozen_string_literal: true | ||
|
||
require "datadog/tracing/contrib/patcher" | ||
|
||
require_relative "result_extractor" | ||
|
||
module Datadog | ||
module CI | ||
module Contrib | ||
module Simplecov | ||
# Patcher enables patching of 'SimpleCov' module. | ||
module Patcher | ||
include Datadog::Tracing::Contrib::Patcher | ||
|
||
module_function | ||
|
||
def target_version | ||
Integration.version | ||
end | ||
|
||
def patch | ||
::SimpleCov.include(ResultExtractor) | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
# frozen_string_literal: true | ||
|
||
require "coverage" | ||
|
||
module Datadog | ||
module CI | ||
module Contrib | ||
module Simplecov | ||
module ResultExtractor | ||
def self.included(base) | ||
base.singleton_class.prepend(ClassMethods) | ||
end | ||
|
||
module ClassMethods | ||
def __dd_peek_result | ||
return nil unless datadog_configuration[:enabled] | ||
|
||
result = ::SimpleCov::UselessResultsRemover.call( | ||
::SimpleCov::ResultAdapter.call(::Coverage.peek_result) | ||
) | ||
|
||
::SimpleCov::Result.new(add_not_loaded_files(result)) | ||
end | ||
|
||
def datadog_configuration | ||
Datadog.configuration.ci[:simplecov] | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# frozen_string_literal: true | ||
|
||
require_relative "../ext/test" | ||
|
||
module Datadog | ||
module CI | ||
module TestVisibility | ||
module TotalCoverage | ||
def self.extract_lines_pct(test_session) | ||
return unless defined?(::SimpleCov) | ||
return unless ::SimpleCov.running | ||
return unless ::SimpleCov.respond_to?(:__dd_peek_result) | ||
|
||
result = ::SimpleCov.__dd_peek_result | ||
return unless result | ||
|
||
test_session.set_tag(Ext::Test::TAG_CODE_COVERAGE_LINES_PCT, result.covered_percent) | ||
end | ||
end | ||
end | ||
end | ||
end |
12 changes: 12 additions & 0 deletions
12
sig/datadog/ci/contrib/simplecov/configuration/settings.rbs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
module Datadog | ||
module CI | ||
module Contrib | ||
module Simplecov | ||
module Configuration | ||
class Settings < Datadog::CI::Contrib::Settings | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
module Datadog | ||
module CI | ||
module Contrib | ||
module Simplecov | ||
module Ext | ||
ENV_ENABLED: "DD_CIVISIBILITY_SIMPLECOV_INSTRUMENTATION_ENABLED" | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
module Datadog | ||
module CI | ||
module Contrib | ||
module Simplecov | ||
class Integration | ||
extend Datadog::CI::Contrib::Integration::ClassMethods | ||
include Datadog::CI::Contrib::Integration::InstanceMethods | ||
|
||
MINIMUM_VERSION: Gem::Version | ||
|
||
def self.version: () -> untyped | ||
|
||
def self.loaded?: () -> bool | ||
|
||
def self.compatible?: () -> bool | ||
|
||
def auto_instrument?: () -> bool | ||
|
||
def new_configuration: () -> untyped | ||
|
||
def patcher: () -> untyped | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
module Datadog | ||
module CI | ||
module Contrib | ||
module Simplecov | ||
module Patcher | ||
include Datadog::Tracing::Contrib::Patcher | ||
|
||
def self?.target_version: () -> untyped | ||
|
||
def self?.patch: () -> untyped | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
module Coverage | ||
def self.peek_result: () -> untyped | ||
end | ||
|
||
module Datadog | ||
module CI | ||
module Contrib | ||
module Simplecov | ||
module ResultExtractor | ||
def self.included: (untyped base) -> untyped | ||
|
||
module ClassMethods | ||
include ::SimpleCov | ||
|
||
def __dd_peek_result: () -> ::SimpleCov::Result? | ||
|
||
def datadog_configuration: () -> untyped | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
module Datadog | ||
module CI | ||
module TestVisibility | ||
module TotalCoverage | ||
def self.extract_lines_pct: (Datadog::CI::TestSession test_session) -> void | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
module SimpleCov | ||
def self.running: () -> bool | ||
|
||
def add_not_loaded_files: (untyped result) -> untyped | ||
|
||
def self.__dd_peek_result: () -> SimpleCov::Result? | ||
end | ||
|
||
class SimpleCov::Result | ||
def initialize: (untyped result) -> void | ||
|
||
def covered_percent: () -> Float | ||
end | ||
|
||
class SimpleCov::UselessResultsRemover | ||
def self.call: (untyped result) -> untyped | ||
end | ||
|
||
class SimpleCov::ResultAdapter | ||
def self.call: (untyped result) -> untyped | ||
end |