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
This commit is contained in:
parent
8c92d442bb
commit
4a4647159e
17
Rakefile.rb
17
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]
|
||||
|
||||
@ -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)
|
||||
|
||||
@ -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
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user