fix simplecov setup to get coverage for integration build tests

This commit is contained in:
Josh Holtrop 2017-05-22 11:19:55 -04:00
parent 28e56251dd
commit bfbbc19728
2 changed files with 12 additions and 5 deletions

View File

@ -57,12 +57,11 @@ describe Rscons do
def run_test(options = {}) def run_test(options = {})
rsconsfile = options[:rsconsfile] || "Rsconsfile" rsconsfile = options[:rsconsfile] || "Rsconsfile"
rscons_args = options[:rscons_args] || [] rscons_args = options[:rscons_args] || []
command = %w[rscons -f _build_test.rb] + rscons_args command = %W[ruby -I. -r _simplecov_setup #{@owd}/bin/rscons -f #{rsconsfile}] + rscons_args
@statics[:build_test_id] ||= 0 @statics[:build_test_id] ||= 0
@statics[:build_test_id] += 1 @statics[:build_test_id] += 1
command_name = "b#{@statics[:build_test_id]}" command_name = "b#{@statics[:build_test_id]}"
rsconsfile_contents = File.read(rsconsfile) File.open("_simplecov_setup.rb", "w") do |fh|
File.open("_build_test.rb", "w") do |fh|
fh.puts <<EOF fh.puts <<EOF
require "simplecov" require "simplecov"
class MyFormatter class MyFormatter
@ -72,15 +71,21 @@ end
SimpleCov.start do SimpleCov.start do
root(#{@owd.inspect}) root(#{@owd.inspect})
command_name(#{command_name.inspect}) command_name(#{command_name.inspect})
filters.clear
add_filter do |src|
!(src.filename[SimpleCov.root])
end
formatter(MyFormatter) formatter(MyFormatter)
end end
$LOAD_PATH.unshift(#{@owd.inspect} + "/lib") $LOAD_PATH.unshift(#{@owd.inspect} + "/lib")
# force color off # force color off
ENV["TERM"] = nil ENV["TERM"] = nil
EOF EOF
fh.puts rsconsfile_contents
end end
stdout, stderr, status = Open3.capture3(*command) stdout, stderr, status = nil, nil, nil
Bundler.with_clean_env do
stdout, stderr, status = Open3.capture3(*command)
end
# Remove output lines generated as a result of the test environment # Remove output lines generated as a result of the test environment
stderr = stderr.lines.find_all do |line| stderr = stderr.lines.find_all do |line|
not (line =~ /Warning: coverage data provided by Coverage.*exceeds number of lines/) not (line =~ /Warning: coverage data provided by Coverage.*exceeds number of lines/)

View File

@ -2,6 +2,8 @@ require "simplecov"
SimpleCov.start do SimpleCov.start do
add_filter "/spec/" add_filter "/spec/"
project_name "Rscons"
merge_timeout 3600
end end
require "rscons" require "rscons"