Skip to content

Commit

Permalink
Merge pull request #31 from Shopify/output-assert
Browse files Browse the repository at this point in the history
Add output to assertions
  • Loading branch information
peterzhu2118 authored May 1, 2024
2 parents 274b95f + 9bc6c92 commit 6ee68f2
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 16 deletions.
2 changes: 1 addition & 1 deletion test/ruby_memcheck/ext/extconf_one.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

require "mkmf"

$warnflags&.gsub!(/-Wdeclaration-after-statement/, "") # rubocop:disable Style/GlobalVars
$warnflags&.gsub!("-Wdeclaration-after-statement", "") # rubocop:disable Style/GlobalVars

create_makefile("ruby_memcheck_c_test_one")
2 changes: 1 addition & 1 deletion test/ruby_memcheck/ext/extconf_two.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

require "mkmf"

$warnflags&.gsub!(/-Wdeclaration-after-statement/, "") # rubocop:disable Style/GlobalVars
$warnflags&.gsub!("-Wdeclaration-after-statement", "") # rubocop:disable Style/GlobalVars

create_makefile("ruby_memcheck_c_test_two")
34 changes: 20 additions & 14 deletions test/ruby_memcheck/shared_test_task_reporter_tests.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,10 @@ def test_reports_memory_leak
end
assert_equal(RubyMemcheck::TestTaskReporter::VALGRIND_REPORT_MSG, error.message)

assert_equal(1, @test_task.reporter.errors.length)

output = @output_io.string

assert_equal(1, @test_task.reporter.errors.length, output)

refute_empty(output)
assert_match(/^100 bytes in 1 blocks are definitely lost in loss record/, output)
assert_match(/^ \*c_test_one_memory_leak \(ruby_memcheck_c_test_one\.c:\d+\)$/, output)
Expand All @@ -38,9 +39,10 @@ def test_reports_use_after_free
end
assert_equal(RubyMemcheck::TestTaskReporter::VALGRIND_REPORT_MSG, error.message)

assert_equal(1, @test_task.reporter.errors.length)

output = @output_io.string

assert_equal(1, @test_task.reporter.errors.length, output)

refute_empty(output)
assert_match(/^Invalid write of size 1$/, output)
assert_match(/^ \*c_test_one_use_after_free \(ruby_memcheck_c_test_one\.c:\d+\)$/, output)
Expand All @@ -52,7 +54,7 @@ def test_does_not_report_uninitialized_value
RubyMemcheck::CTestOne.new.uninitialized_value
RUBY

assert_equal(0, @test_task.reporter.errors.length)
assert_equal(0, @test_task.reporter.errors.length, @output_io.string)
assert_empty(@test_task.reporter.errors)
assert_empty(@output_io.string)
end
Expand All @@ -77,7 +79,7 @@ def test_call_into_ruby_mem_leak_reports_when_not_skipped
end
assert_equal(RubyMemcheck::TestTaskReporter::VALGRIND_REPORT_MSG, error.message)

assert_operator(@test_task.reporter.errors.length, :>=, 1)
assert_operator(@test_task.reporter.errors.length, :>=, 1, @output_io.string)
end

def test_suppressions
Expand All @@ -102,9 +104,10 @@ def test_generation_of_suppressions
end
assert_equal(RubyMemcheck::TestTaskReporter::VALGRIND_REPORT_MSG, error.message)

assert_equal(1, @test_task.reporter.errors.length)

output = @output_io.string

assert_equal(1, @test_task.reporter.errors.length, output)

refute_empty(output)
assert_match(/^100 bytes in 1 blocks are definitely lost in loss record/, output)
assert_match(/^ \*c_test_one_memory_leak \(ruby_memcheck_c_test_one\.c:\d+\)$/, output)
Expand All @@ -125,9 +128,10 @@ def test_follows_forked_children
end
assert_equal(RubyMemcheck::TestTaskReporter::VALGRIND_REPORT_MSG, error.message)

assert_equal(1, @test_task.reporter.errors.length)

output = @output_io.string

assert_equal(1, @test_task.reporter.errors.length, output)

refute_empty(output)
assert_match(/^100 bytes in 1 blocks are definitely lost in loss record/, output)
assert_match(/^ \*c_test_one_memory_leak \(ruby_memcheck_c_test_one\.c:\d+\)$/, output)
Expand Down Expand Up @@ -203,9 +207,10 @@ def test_ruby_failure_with_errors
end
assert_equal(RubyMemcheck::TestTaskReporter::VALGRIND_REPORT_MSG, error.message)

assert_equal(1, @test_task.reporter.errors.length)

output = @output_io.string

assert_equal(1, @test_task.reporter.errors.length, output)

refute_empty(output)
assert_match(/^100 bytes in 1 blocks are definitely lost in loss record/, output)
assert_match(/^ \*c_test_one_memory_leak \(ruby_memcheck_c_test_one\.c:\d+\)$/, output)
Expand Down Expand Up @@ -257,9 +262,10 @@ def test_configration_binary_name
end
assert_equal(RubyMemcheck::TestTaskReporter::VALGRIND_REPORT_MSG, error.message)

assert_equal(1, @test_task.reporter.errors.length)

output = @output_io.string

assert_equal(1, @test_task.reporter.errors.length, output)

refute_empty(output)
assert_match(/^100 bytes in 1 blocks are definitely lost in loss record/, output)
assert_match(/^ \*c_test_one_memory_leak \(ruby_memcheck_c_test_one\.c:\d+\)$/, output)
Expand Down

0 comments on commit 6ee68f2

Please sign in to comment.