From 5b16f3877d1e0ec39b390ee94f89a46cb5037dfa Mon Sep 17 00:00:00 2001 From: Peter Zhu Date: Tue, 30 Apr 2024 17:41:02 -0400 Subject: [PATCH 1/2] Add output to assertions --- .../shared_test_task_reporter_tests.rb | 34 +++++++++++-------- 1 file changed, 20 insertions(+), 14 deletions(-) diff --git a/test/ruby_memcheck/shared_test_task_reporter_tests.rb b/test/ruby_memcheck/shared_test_task_reporter_tests.rb index f00a011..25b422d 100644 --- a/test/ruby_memcheck/shared_test_task_reporter_tests.rb +++ b/test/ruby_memcheck/shared_test_task_reporter_tests.rb @@ -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) @@ -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) @@ -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 @@ -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 @@ -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) @@ -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) @@ -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) @@ -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) From 9bc6c9250b1c2ed27e39962ac15d983715b59816 Mon Sep 17 00:00:00 2001 From: Peter Zhu Date: Tue, 30 Apr 2024 17:53:05 -0400 Subject: [PATCH 2/2] Make Rubocop happy --- test/ruby_memcheck/ext/extconf_one.rb | 2 +- test/ruby_memcheck/ext/extconf_two.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/test/ruby_memcheck/ext/extconf_one.rb b/test/ruby_memcheck/ext/extconf_one.rb index 5f48633..86e7a7b 100644 --- a/test/ruby_memcheck/ext/extconf_one.rb +++ b/test/ruby_memcheck/ext/extconf_one.rb @@ -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") diff --git a/test/ruby_memcheck/ext/extconf_two.rb b/test/ruby_memcheck/ext/extconf_two.rb index 4d1ba8e..6b4a7ee 100644 --- a/test/ruby_memcheck/ext/extconf_two.rb +++ b/test/ruby_memcheck/ext/extconf_two.rb @@ -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")