Class: RubyMemcheck::TestTaskReporter

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby_memcheck/test_task_reporter.rb

Constant Summary collapse

VALGRIND_REPORT_MSG =
"Valgrind reported errors (e.g. memory leak or use-after-free)"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(configuration) ⇒ TestTaskReporter

Returns a new instance of TestTaskReporter.



10
11
12
13
# File 'lib/ruby_memcheck/test_task_reporter.rb', line 10

def initialize(configuration)
  @configuration = configuration
  @loaded_binaries = nil
end

Instance Attribute Details

#configurationObject (readonly)

Returns the value of attribute configuration.



7
8
9
# File 'lib/ruby_memcheck/test_task_reporter.rb', line 7

def configuration
  @configuration
end

#errorsObject (readonly)

Returns the value of attribute errors.



8
9
10
# File 'lib/ruby_memcheck/test_task_reporter.rb', line 8

def errors
  @errors
end

Instance Method Details

#report_valgrind_errorsObject



27
28
29
30
31
32
33
34
35
# File 'lib/ruby_memcheck/test_task_reporter.rb', line 27

def report_valgrind_errors
  parse_valgrind_output
  remove_valgrind_xml_files

  unless errors.empty?
    output_valgrind_errors
    raise VALGRIND_REPORT_MSG
  end
end

#run_ruby_with_valgrind(&block) ⇒ Object



15
16
17
18
19
# File 'lib/ruby_memcheck/test_task_reporter.rb', line 15

def run_ruby_with_valgrind(&block)
  setup
  yield
  report_valgrind_errors
end

#setupObject



21
22
23
24
25
# File 'lib/ruby_memcheck/test_task_reporter.rb', line 21

def setup
  ENV["RUBY_MEMCHECK_LOADED_FEATURES_FILE"] = File.expand_path(configuration.loaded_features_file)
  ENV["RUBY_MEMCHECK_RUNNING"] = "1"
  ENV["RUBY_FREE_AT_EXIT"] = "1"
end