Skip to content

Commit

Permalink
raise when starting coverage without root
Browse files Browse the repository at this point in the history
  • Loading branch information
anmarchenko committed Jun 10, 2024
1 parent 44e32d4 commit 357dedd
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
8 changes: 5 additions & 3 deletions ext/datadog_cov/datadog_cov.c
Original file line number Diff line number Diff line change
Expand Up @@ -160,12 +160,14 @@ static VALUE dd_cov_start(VALUE self)
struct dd_cov_data *dd_cov_data;
TypedData_Get_Struct(self, struct dd_cov_data, &dd_cov_data_type, dd_cov_data);

if (dd_cov_data->root_len != 0)
if (dd_cov_data->root_len == 0)
{
// add event hook
rb_thread_add_event_hook(thval, dd_cov_update_coverage, RUBY_EVENT_LINE, self);
rb_raise(rb_eRuntimeError, "root is required");
}

// add event hook
rb_thread_add_event_hook(thval, dd_cov_update_coverage, RUBY_EVENT_LINE, self);

return self;
}

Expand Down
7 changes: 2 additions & 5 deletions spec/ddcov/ddcov_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,10 @@ def absolute_path(path)
let!(:calculator) { Calculator.new }

context "when allocating and starting coverage without a root" do
it "does not fail" do
it "throws Runtime error" do
cov = described_class.allocate
cov.start
expect(calculator.add(1, 2)).to eq(3)

coverage = cov.stop
expect(coverage).to eq({})
expect { cov.start }.to raise_error(RuntimeError, "root is required")
end
end

Expand Down

0 comments on commit 357dedd

Please sign in to comment.