From 4007592ec42e8f1c4e3b095ba9637861720d706e Mon Sep 17 00:00:00 2001 From: Andrey Date: Fri, 12 Jul 2024 17:35:30 +0200 Subject: [PATCH] move skipping anonymous classes to the tracepoint, add struct to tests --- ext/datadog_cov/datadog_cov.c | 18 ++++++++---------- spec/ddcov/app/model/my_struct.rb | 1 + spec/ddcov/ddcov_spec.rb | 5 ++++- 3 files changed, 13 insertions(+), 11 deletions(-) create mode 100644 spec/ddcov/app/model/my_struct.rb diff --git a/ext/datadog_cov/datadog_cov.c b/ext/datadog_cov/datadog_cov.c index 9dbc26a1..c92950cd 100644 --- a/ext/datadog_cov/datadog_cov.c +++ b/ext/datadog_cov/datadog_cov.c @@ -235,16 +235,6 @@ static int process_instantiated_klass(st_data_t key, st_data_t _value, st_data_t return ST_CONTINUE; } - // Skip anonymous classes starting with "#= 2 && klass_name_ptr[0] == '#' && klass_name_ptr[1] == '<') - { - return ST_CONTINUE; - } - VALUE source_location = safely_get_source_location(klass_name); if (source_location == Qnil || RARRAY_LEN(source_location) == 0) { @@ -283,6 +273,14 @@ static void on_newobj_event(VALUE tracepoint_data, void *data) { return; } + // Skip anonymous classes starting with "#= 2 && name[0] == '#' && name[1] == '<') + { + return; + } if (st_lookup(dd_cov_data->klasses_table, (st_data_t)klass, 0)) { diff --git a/spec/ddcov/app/model/my_struct.rb b/spec/ddcov/app/model/my_struct.rb new file mode 100644 index 00000000..a22a8701 --- /dev/null +++ b/spec/ddcov/app/model/my_struct.rb @@ -0,0 +1 @@ +User = Struct.new(:name, :email) diff --git a/spec/ddcov/ddcov_spec.rb b/spec/ddcov/ddcov_spec.rb index a8d29af8..83387e07 100644 --- a/spec/ddcov/ddcov_spec.rb +++ b/spec/ddcov/ddcov_spec.rb @@ -3,6 +3,7 @@ require "datadog_cov.#{RUBY_VERSION}_#{RUBY_PLATFORM}" require_relative "app/model/my_model" +require_relative "app/model/my_struct" require_relative "calculator/calculator" require_relative "calculator/code_with_❤️" @@ -329,6 +330,7 @@ def thread_local_cov subject.start MyModel.new + User.new("john doe", "johndoe@mail.test") c = Class.new(Object) do end c.new @@ -342,8 +344,9 @@ def thread_local_cov end coverage = subject.stop - expect(coverage.size).to eq(1) + expect(coverage.size).to eq(2) expect(coverage.keys).to include(absolute_path("app/model/my_model.rb")) + expect(coverage.keys).to include(absolute_path("app/model/my_struct.rb")) end end