-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
sinmplest code coverage with resume/suspend POC
- Loading branch information
1 parent
8eb9540
commit 2d24951
Showing
3 changed files
with
101 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 |
---|---|---|
@@ -0,0 +1,47 @@ | ||
# frozen_string_literal: true | ||
|
||
require "coverage" | ||
|
||
require_relative "filter" | ||
|
||
module Datadog | ||
module CI | ||
module Itr | ||
module Coverage | ||
class Collector | ||
def initialize | ||
# Do not run code coverage if someone else is already running it. | ||
# It means that user is running the test with coverage and ITR would mess it up. | ||
@coverage_supported = !::Coverage.running? | ||
# @coverage_supported = false | ||
end | ||
|
||
def setup | ||
if @coverage_supported | ||
p "RUNNING WITH CODE COVERAGE ENABLED!" | ||
::Coverage.setup(lines: true) | ||
else | ||
p "RUNNING WITH CODE COVERAGE DISABLED!" | ||
end | ||
end | ||
|
||
def start | ||
return unless @coverage_supported | ||
|
||
# if execution is threaded then coverage might already be running | ||
::Coverage.resume unless ::Coverage.running? | ||
end | ||
|
||
def stop | ||
return nil unless @coverage_supported | ||
|
||
result = ::Coverage.result(stop: false, clear: true) | ||
::Coverage.suspend if ::Coverage.running? | ||
|
||
Filter.call(result) | ||
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,29 @@ | ||
# frozen_string_literal: true | ||
|
||
require_relative "../../utils/git" | ||
|
||
module Datadog | ||
module CI | ||
module Itr | ||
module Coverage | ||
class Filter | ||
def self.call(raw_result) | ||
new.call(raw_result) | ||
end | ||
|
||
def initialize(root: Utils::Git.root) | ||
@regex = /\A#{Regexp.escape(root + File::SEPARATOR)}/i.freeze | ||
end | ||
|
||
def call(raw_result) | ||
return nil if raw_result.nil? | ||
|
||
raw_result.select do |path, coverage| | ||
path =~ @regex && coverage[:lines].any? { |count| count && count > 0 } | ||
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