-
Notifications
You must be signed in to change notification settings - Fork 5
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
[NO TICKET] test code coverage with symlinked dependency required via entrypoint #188
Merged
anmarchenko
merged 3 commits into
main
from
anmarchenko/test_code_coverage_with_symlinks
Jun 4, 2024
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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_relative "vendor/gems/operations/operations" | ||
|
||
class Calculator | ||
def initialize | ||
@adder = Add.new | ||
@subtractor = Subtract.new | ||
@multiplier = Multiply.new | ||
@divider = Divide.new | ||
end | ||
|
||
def add(a, b) | ||
@adder.call(a, b) | ||
end | ||
|
||
def subtract(a, b) | ||
@subtractor.call(a, b) | ||
end | ||
|
||
def multiply(a, b) | ||
@multiplier.call(a, b) | ||
end | ||
|
||
def divide(a, b) | ||
@divider.call(a, b) | ||
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,7 @@ | ||
# frozen_string_literal: true | ||
|
||
class Add | ||
def call(a, b) | ||
a + b | ||
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 @@ | ||
# frozen_string_literal: true | ||
|
||
require_relative "helpers/calculator_logger" | ||
|
||
class Divide | ||
prepend CalculatorLogger | ||
|
||
def call(a, b) | ||
a / b | ||
end | ||
end |
12 changes: 12 additions & 0 deletions
12
spec/ddcov/calculator_with_symlinks/operations/helpers/calculator_logger.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,12 @@ | ||
# frozen_string_literal: true | ||
|
||
module CalculatorLogger | ||
def call(a, b) | ||
res = super | ||
|
||
@log ||= [] | ||
@log << "operation performed" | ||
|
||
res | ||
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,7 @@ | ||
# frozen_string_literal: true | ||
|
||
class Multiply | ||
def call(a, b) | ||
a * b | ||
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,4 @@ | ||
require_relative "add" | ||
require_relative "divide" | ||
require_relative "multiply" | ||
require_relative "subtract" |
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,7 @@ | ||
# frozen_string_literal: true | ||
|
||
class Subtract | ||
def call(a, b) | ||
a - b | ||
end | ||
end |
Empty file.
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,55 @@ | ||
# frozen_string_literal: true | ||
|
||
require "fileutils" | ||
|
||
require "datadog_cov.#{RUBY_VERSION}_#{RUBY_PLATFORM}" | ||
|
||
RSpec.describe Datadog::CI::ITR::Coverage::DDCov do | ||
def absolute_path(path) | ||
File.expand_path(File.join(__dir__, path)) | ||
end | ||
|
||
before do | ||
# create a symlink to the calculator_with_symlinks/operations folder in vendor/gems | ||
FileUtils.ln_s( | ||
absolute_path("calculator_with_symlinks/operations"), | ||
absolute_path("calculator_with_symlinks/vendor/gems/operations"), | ||
force: true | ||
) | ||
|
||
require_relative "calculator_with_symlinks/calculator" | ||
end | ||
|
||
after do | ||
# delete symlink | ||
FileUtils.rm_f( | ||
absolute_path("calculator_with_symlinks/vendor/gems/operations") | ||
) | ||
end | ||
|
||
subject { described_class.new(root: root) } | ||
|
||
describe "code coverage collection" do | ||
let!(:calculator) { Calculator.new } | ||
|
||
context "when root is the calculator project dir" do | ||
let(:root) { absolute_path("calculator_with_symlinks") } | ||
|
||
it "collects code coverage including Calculator and operations" do | ||
subject.start | ||
|
||
expect(calculator.add(1, 2)).to eq(3) | ||
expect(calculator.subtract(1, 2)).to eq(-1) | ||
|
||
coverage = subject.stop | ||
|
||
expect(coverage.size).to eq(3) | ||
expect(coverage.keys).to include( | ||
absolute_path("calculator_with_symlinks/calculator.rb"), | ||
absolute_path("calculator_with_symlinks/operations/add.rb"), | ||
absolute_path("calculator_with_symlinks/operations/subtract.rb") | ||
) | ||
end | ||
end | ||
end | ||
end |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
changes in this file are unrelated, just enjoying our own Datadog's static code analysis tool