Class: Datadog::CI::ITR::Coverage::DDCov

Inherits:
Object
  • Object
show all
Defined in:
lib/datadog/ci/itr/coverage/ddcov.rb,
ext/datadog_cov/datadog_cov.c

Overview

Placeholder for code coverage collection Implementation in ext/datadog_cov

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ Object

DDCov methods



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
# File 'ext/datadog_cov/datadog_cov.c', line 57

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")));
  if (!RTEST(rb_root))
  {
    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;
}

Instance Method Details

#startObject



151
152
153
154
155
156
157
158
159
160
# File 'ext/datadog_cov/datadog_cov.c', line 151

static VALUE dd_cov_start(VALUE self)
{
  // get current thread
  VALUE thval = rb_thread_current();

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

  return self;
}

#stopObject



162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
# File 'ext/datadog_cov/datadog_cov.c', line 162

static VALUE dd_cov_stop(VALUE self)
{
  // get current thread
  VALUE thval = rb_thread_current();
  // remove event hook for the current thread
  rb_thread_remove_event_hook(thval, dd_cov_update_line_coverage);

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

  VALUE cov = dd_cov_data->coverage;

  dd_cov_data->coverage = rb_hash_new();

  return cov;
}