From 4a4647159eedf8d8f1258d17c0173ceff7f9dc40 Mon Sep 17 00:00:00 2001 From: Josh Holtrop Date: Wed, 19 Aug 2026 09:24:03 -0400 Subject: [PATCH] Improve rake tasks for specs - clean coverage directory before running specs to avoid simplecov slowdowns - add valgrind task to run valgrind; normal spec does not run it - delay combining and reporting simplecov results until end of task to speed up task execution --- Rakefile.rb | 17 +++++++++++++++-- spec/propane_spec.rb | 7 ++++++- spec/spec_helper.rb | 4 ++++ 3 files changed, 25 insertions(+), 3 deletions(-) diff --git a/Rakefile.rb b/Rakefile.rb index 64762a7..e4a7b8a 100644 --- a/Rakefile.rb +++ b/Rakefile.rb @@ -1,3 +1,4 @@ +require "fileutils" require "rake/clean" require "rspec/core/rake_task" require "simplecov" @@ -11,7 +12,10 @@ end RSpec::Core::RakeTask.new(:spec, :example_pattern) do |task, args| if args.example_pattern + ENV["partial_specs"] = "1" task.rspec_opts = %W[-e "#{args.example_pattern}" -f documentation] + else + FileUtils.rm_rf("coverage") end end task :spec do |task, args| @@ -19,7 +23,7 @@ task :spec do |task, args| original_stdout = $stdout sio = StringIO.new $stdout = sio - SimpleCov.collate Dir["coverage/.resultset.json"] + SimpleCov.collate Dir["coverage/parts/*/.resultset.json"] $stdout = original_stdout sio.string.lines.each do |line| $stdout.write(line) unless line =~ /Coverage report generated for/ @@ -27,6 +31,15 @@ task :spec do |task, args| end end +task :valgrind do + begin + ENV["spec-valgrind"] = "1" + Rake::Task[:spec].execute + ensure + ENV.delete("spec-valgrind") + end +end + # dspec task is useful to test the distributable release script, but is not # useful for coverage information. desc "Dist Specs" @@ -43,4 +56,4 @@ task :user_guide do system("ruby", "-Ilib", "rb/gen_user_guide.rb") end -task :all => [:spec, :dspec, :user_guide] +task :all => [:valgrind, :dspec, :user_guide] diff --git a/spec/propane_spec.rb b/spec/propane_spec.rb index e2b167c..75ad83a 100644 --- a/spec/propane_spec.rb +++ b/spec/propane_spec.rb @@ -39,6 +39,11 @@ class MyFormatter end SimpleCov.start do command_name(#{command_name.inspect}) + # Write this process's results to its own directory. Sharing one resultset + # file means every propane invocation must read, merge, and rewrite the + # results of all previous invocations, which grows quadratically over the + # suite. The parts are merged once at the end by the spec Rake task. + coverage_dir(#{"coverage/parts/#{command_name}".inspect}) filters.clear add_filter do |src| !(src.filename[SimpleCov.root]) @@ -119,7 +124,7 @@ EOF results = Results.new(stdout, stderr, status) # Valgrind is only reliably available on Linux, so limit the leak check to # Linux platforms. - if RUBY_PLATFORM =~ /linux/ + if RUBY_PLATFORM =~ /linux/ && ENV["spec-valgrind"] stdout, stderr, status = Open3.capture3("valgrind --leak-check=full --show-leak-kinds=all --track-origins=yes --verbose spec/run/testparser") vgout = stdout + stderr File.binwrite("spec/run/.vgout", vgout) diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 7011fea..d284b32 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -15,6 +15,10 @@ unless ENV["dist_specs"] command_name "RSpec" end project_name "Propane" + # Keep this process's results separate from the propane subprocess results + # so that nothing has to merge on the fly; the spec Rake task collates all + # of the parts once the suite is done. + coverage_dir "coverage/parts/rspec" merge_timeout 3600 formatter(MyFormatter) end