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



85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
# File 'ext/datadog_cov/datadog_cov.c', line 85

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_ignored_path = rb_hash_lookup(opt, ID2SYM(rb_intern("ignored_path")));

  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->ignored_path = rb_ignored_path;
  dd_cov_data->mode = mode;

  return Qnil;
}

Instance Method Details

#startObject



177
178
179
180
181
182
183
184
185
186
# File 'ext/datadog_cov/datadog_cov.c', line 177

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



188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
# File 'ext/datadog_cov/datadog_cov.c', line 188

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;
}