Skip to content

Commit

Permalink
remove lines mode from ddcov extension as it is dead code right now
Browse files Browse the repository at this point in the history
  • Loading branch information
anmarchenko committed May 3, 2024
1 parent 59a92c8 commit 8fd6c4c
Show file tree
Hide file tree
Showing 3 changed files with 134 additions and 206 deletions.
49 changes: 1 addition & 48 deletions ext/datadog_cov/datadog_cov.c
Original file line number Diff line number Diff line change
@@ -1,15 +1,10 @@
#include <ruby.h>
#include <ruby/debug.h>

// constants
#define DD_COV_TARGET_FILES 1
#define DD_COV_TARGET_LINES 2

// Data structure
struct dd_cov_data
{
VALUE root;
int mode;
VALUE coverage;
};

Expand Down Expand Up @@ -49,15 +44,13 @@ static VALUE dd_cov_allocate(VALUE klass)
VALUE obj = TypedData_Make_Struct(klass, struct dd_cov_data, &dd_cov_data_type, dd_cov_data);
dd_cov_data->coverage = rb_hash_new();
dd_cov_data->root = Qnil;
dd_cov_data->mode = DD_COV_TARGET_FILES;
return obj;
}

// DDCov methods
static VALUE dd_cov_initialize(int argc, VALUE *argv, VALUE self)
{
VALUE opt;
int mode;

rb_scan_args(argc, argv, "10", &opt);
VALUE rb_root = rb_hash_lookup(opt, ID2SYM(rb_intern("root")));
Expand All @@ -66,25 +59,10 @@ static VALUE dd_cov_initialize(int argc, VALUE *argv, VALUE self)
rb_raise(rb_eArgError, "root is required");
}

VALUE rb_mode = rb_hash_lookup(opt, ID2SYM(rb_intern("mode")));
if (!RTEST(rb_mode) || rb_mode == ID2SYM(rb_intern("files")))
{
mode = DD_COV_TARGET_FILES;
}
else if (rb_mode == ID2SYM(rb_intern("lines")))
{
mode = DD_COV_TARGET_LINES;
}
else
{
rb_raise(rb_eArgError, "mode is invalid");
}

struct dd_cov_data *dd_cov_data;
TypedData_Get_Struct(self, struct dd_cov_data, &dd_cov_data_type, dd_cov_data);

dd_cov_data->root = rb_root;
dd_cov_data->mode = mode;

return Qnil;
}
Expand Down Expand Up @@ -120,32 +98,7 @@ static void dd_cov_update_line_coverage(rb_event_flag_t event, VALUE data, VALUE

VALUE rb_str_source_file = rb_str_new2(filename);

if (dd_cov_data->mode == DD_COV_TARGET_FILES)
{
rb_hash_aset(dd_cov_data->coverage, rb_str_source_file, Qtrue);
return;
}

// this isn't optimized yet, this is a POC to show that lines coverage is possible
// ITR beta is going to use files coverage, we'll get back to this part when
// we need to implement lines coverage
if (dd_cov_data->mode == DD_COV_TARGET_LINES)
{
int line_number = rb_sourceline();
if (line_number <= 0)
{
return;
}

VALUE rb_lines = rb_hash_aref(dd_cov_data->coverage, rb_str_source_file);
if (rb_lines == Qnil)
{
rb_lines = rb_hash_new();
rb_hash_aset(dd_cov_data->coverage, rb_str_source_file, rb_lines);
}

rb_hash_aset(rb_lines, INT2FIX(line_number), Qtrue);
}
rb_hash_aset(dd_cov_data->coverage, rb_str_source_file, Qtrue);
}

static VALUE dd_cov_start(VALUE self)
Expand Down
2 changes: 1 addition & 1 deletion sig/datadog/ci/itr/coverage/ddcov.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module Datadog
module Coverage
class DDCov

def initialize: (root: String, ?mode: Symbol) -> void
def initialize: (root: String) -> void

def start: () -> void

Expand Down
Loading

0 comments on commit 8fd6c4c

Please sign in to comment.