Skip to content

Commit

Permalink
Fix assert_raises tests
Browse files Browse the repository at this point in the history
  • Loading branch information
peterzhu2118 committed Nov 1, 2021
1 parent 836906c commit 396aaf3
Showing 1 changed file with 15 additions and 10 deletions.
25 changes: 15 additions & 10 deletions test/ruby_memcheck/shared_test_task_reporter_tests.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,12 @@ def test_succeeds_when_there_is_no_memory_leak
end

def test_reports_memory_leak
assert_raises(RubyMemcheck::TestTask::VALGRIND_REPORT_MSG) do
error = assert_raises do
run_with_memcheck(<<~RUBY)
RubyMemcheck::CTest.new.memory_leak
RUBY
end
assert_equal(RubyMemcheck::TestTask::VALGRIND_REPORT_MSG, error.message)

assert_equal(1, @test_task.errors.length)

Expand All @@ -30,11 +31,12 @@ def test_reports_memory_leak
end

def test_reports_use_after_free
assert_raises(RubyMemcheck::TestTask::VALGRIND_REPORT_MSG) do
error = assert_raises do
run_with_memcheck(<<~RUBY)
RubyMemcheck::CTest.new.use_after_free
RUBY
end
assert_equal(RubyMemcheck::TestTask::VALGRIND_REPORT_MSG, error.message)

assert_equal(1, @test_task.errors.length)

Expand Down Expand Up @@ -68,11 +70,12 @@ def test_call_into_ruby_mem_leak_does_not_report
def test_call_into_ruby_mem_leak_reports_when_not_skipped
build_configuration(skipped_ruby_functions: [])

assert_raises(RubyMemcheck::TestTask::VALGRIND_REPORT_MSG) do
error = assert_raises do
run_with_memcheck(<<~RUBY)
RubyMemcheck::CTest.new.call_into_ruby_mem_leak
RUBY
end
assert_equal(RubyMemcheck::TestTask::VALGRIND_REPORT_MSG, error.message)

assert_operator(@test_task.errors.length, :>=, 1)
end
Expand All @@ -90,15 +93,14 @@ def test_suppressions
end

def test_generation_of_suppressions
valgrind_options = RubyMemcheck::Configuration::DEFAULT_VALGRIND_OPTIONS.dup
valgrind_options << "--gen-suppressions=all"
build_configuration(valgrind_options: valgrind_options)
build_configuration(valgrind_generate_suppressions: true)

assert_raises(RubyMemcheck::TestTask::VALGRIND_REPORT_MSG) do
error = assert_raises do
run_with_memcheck(<<~RUBY)
RubyMemcheck::CTest.new.memory_leak
RUBY
end
assert_equal(RubyMemcheck::TestTask::VALGRIND_REPORT_MSG, error.message)

assert_equal(1, @test_task.errors.length)

Expand All @@ -112,7 +114,7 @@ def test_generation_of_suppressions
end

def test_follows_forked_children
assert_raises(RubyMemcheck::TestTask::VALGRIND_REPORT_MSG) do
error = assert_raises do
run_with_memcheck(<<~RUBY)
pid = Process.fork do
RubyMemcheck::CTest.new.memory_leak
Expand All @@ -121,6 +123,7 @@ def test_follows_forked_children
Process.wait(pid)
RUBY
end
assert_equal(RubyMemcheck::TestTask::VALGRIND_REPORT_MSG, error.message)

assert_equal(1, @test_task.errors.length)

Expand All @@ -131,12 +134,13 @@ def test_follows_forked_children
end

def test_reports_multiple_errors
assert_raises(RubyMemcheck::TestTask::VALGRIND_REPORT_MSG) do
error = assert_raises do
run_with_memcheck(<<~RUBY)
RubyMemcheck::CTest.new.memory_leak
RubyMemcheck::CTest.new.use_after_free
RUBY
end
assert_equal(RubyMemcheck::TestTask::VALGRIND_REPORT_MSG, error.message)

assert_equal(2, @test_task.errors.length)

Expand All @@ -159,12 +163,13 @@ def test_ruby_failure_without_errors
end

def test_ruby_failure_with_errors
assert_raises(RubyMemcheck::TestTask::VALGRIND_REPORT_MSG) do
error = assert_raises do
run_with_memcheck(<<~RUBY, raise_on_failure: false, spawn_opts: { out: "/dev/null", err: "/dev/null" })
RubyMemcheck::CTest.new.memory_leak
raise
RUBY
end
assert_equal(RubyMemcheck::TestTask::VALGRIND_REPORT_MSG, error.message)

assert_equal(1, @test_task.errors.length)

Expand Down

0 comments on commit 396aaf3

Please sign in to comment.