-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #224 from DataDog/anmarchenko/fix_datadog_cov_crashes
[SDTEST-755] attempt to fix datadog_cov crash when doing allocation profiling
- Loading branch information
Showing
3 changed files
with
91 additions
and
1 deletion.
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,2 @@ | ||
class MyModel❤️ | ||
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 |
---|---|---|
|
@@ -3,6 +3,7 @@ | |
require "datadog_cov.#{RUBY_VERSION}_#{RUBY_PLATFORM}" | ||
|
||
require_relative "app/model/my_model" | ||
require_relative "app/model/my_model_❤️" | ||
require_relative "app/model/my_struct" | ||
require_relative "calculator/calculator" | ||
require_relative "calculator/code_with_❤️" | ||
|
@@ -357,6 +358,93 @@ def thread_local_cov | |
expect(coverage.keys).to include(absolute_path("app/model/my_struct.rb")) | ||
end | ||
|
||
it "tracks coverage for objects defined with emojis" do | ||
subject.start | ||
|
||
MyModel❤️.new | ||
|
||
coverage = subject.stop | ||
expect(coverage.size).to eq(1) | ||
expect(coverage.keys).to include(absolute_path("app/model/my_model_❤️.rb")) | ||
end | ||
|
||
context "Object.const_source_location is redefined in tests" do | ||
context "returns invalid values" do | ||
before do | ||
allow(Object).to receive(:const_source_location).and_return([-1, -1]) | ||
end | ||
|
||
it "does not break" do | ||
subject.start | ||
|
||
User.new("john doe", "[email protected]") | ||
|
||
coverage = subject.stop | ||
expect(coverage.size).to eq(0) | ||
end | ||
end | ||
|
||
context "returns nil" do | ||
before do | ||
allow(Object).to receive(:const_source_location).and_return(nil) | ||
end | ||
|
||
it "does not break" do | ||
subject.start | ||
|
||
User.new("john doe", "[email protected]") | ||
|
||
coverage = subject.stop | ||
expect(coverage.size).to eq(0) | ||
end | ||
end | ||
|
||
context "returns empty array" do | ||
before do | ||
allow(Object).to receive(:const_source_location).and_return([]) | ||
end | ||
|
||
it "does not break" do | ||
subject.start | ||
|
||
User.new("john doe", "[email protected]") | ||
|
||
coverage = subject.stop | ||
expect(coverage.size).to eq(0) | ||
end | ||
end | ||
|
||
context "returns empty nested array" do | ||
before do | ||
allow(Object).to receive(:const_source_location).and_return([[]]) | ||
end | ||
|
||
it "does not break" do | ||
subject.start | ||
|
||
User.new("john doe", "[email protected]") | ||
|
||
coverage = subject.stop | ||
expect(coverage.size).to eq(0) | ||
end | ||
end | ||
|
||
context "raises" do | ||
before do | ||
allow(Object).to receive(:const_source_location).and_raise(StandardError) | ||
end | ||
|
||
it "does not break" do | ||
subject.start | ||
|
||
User.new("john doe", "[email protected]") | ||
|
||
coverage = subject.stop | ||
expect(coverage.size).to eq(0) | ||
end | ||
end | ||
end | ||
|
||
context "Data structs available since Ruby 3.2" do | ||
before do | ||
if RUBY_VERSION < "3.2" | ||
|