From cf10890d63bb28e3cbd8b41122435ce89591b649 Mon Sep 17 00:00:00 2001 From: Pere Urbon-Bayes Date: Thu, 18 Jun 2015 18:39:09 +0200 Subject: [PATCH] fix the coverage analysis throw simplecov to take care of all files make the eager loading patterns consistent in the spec_helper.rb file make the setup-simplecov task not a dependency, but an explicit task only executed when ENV['COVERAGE'] is defined refactor eager loading code plus add some documentation to the setup-simplecov task Added more comments to the test:setup task Fixes #3465 --- lib/logstash/environment.rb | 2 +- rakelib/test.rake | 30 ++++++++++++++++++++++++++++++ spec/coverage_helper.rb | 14 ++++++++++++++ spec/spec_helper.rb | 5 +++++ 4 files changed, 50 insertions(+), 1 deletion(-) create mode 100644 spec/coverage_helper.rb diff --git a/lib/logstash/environment.rb b/lib/logstash/environment.rb index 697ce838264..244671533ec 100644 --- a/lib/logstash/environment.rb +++ b/lib/logstash/environment.rb @@ -77,7 +77,7 @@ def jruby? end def windows? - Gem.win_platform? + ::Gem.win_platform? end def vendor_path(path) diff --git a/rakelib/test.rake b/rakelib/test.rake index e674d226b91..1e5a3408233 100644 --- a/rakelib/test.rake +++ b/rakelib/test.rake @@ -4,7 +4,13 @@ require "pluginmanager/util" namespace "test" do + task "setup" do + # Need to be run here as because if run aftewarse (after the bundler.setup task) then the report got wrong + # numbers and misses files. There is an issue with our setup! method as this does not happen with the regular + # bundler.setup used in regular bundler flows. + Rake::Task["test:setup-simplecov"].invoke if ENV['COVERAGE'] + require "bootstrap/environment" LogStash::Bundler.setup!({:without => [:build]}) @@ -45,6 +51,30 @@ namespace "test" do task "install-vendor-plugins" => ["bootstrap", "plugin:install-vendor", "plugin:install-development-dependencies"] task "install-jar-dependencies-plugins" => ["bootstrap", "plugin:install-jar-dependencies", "plugin:install-development-dependencies"] + + # Setup simplecov to group files per functional modules, like this is easier to spot places with small coverage + task "setup-simplecov" do + require "simplecov" + SimpleCov.start do + # Skip non core related directories and files. + ["vendor/", "spec/", "bootstrap/rspec", "Gemfile", "gemspec"].each do |pattern| + add_filter pattern + end + + add_group "bootstrap", "bootstrap/" # This module is used during bootstraping of LS + add_group "plugin manager", "pluginmanager/" # Code related to the plugin manager + add_group "core" do |src_file| # The LS core codebase + /logstash\/\w+.rb/.match(src_file.filename) + end + add_group "core-util", "logstash/util" # Set of LS utils module + add_group "core-config", "logstash/config" # LS Configuration modules + add_group "core-patches", "logstash/patches" # Patches used to overcome known issues in dependencies. + # LS Core plugins code base. + add_group "core-plugins", [ "logstash/codecs", "logstash/filters", "logstash/outputs", "logstash/inputs" ] + end + task.reenable + end + end task "test" => [ "test:core" ] diff --git a/spec/coverage_helper.rb b/spec/coverage_helper.rb new file mode 100644 index 00000000000..871d322ef96 --- /dev/null +++ b/spec/coverage_helper.rb @@ -0,0 +1,14 @@ +# Useful module to help loading all logstash content when +# running coverage analysis +module CoverageHelper + + SKIP_LIST = ["lib/bootstrap/rspec.rb", "lib/logstash/util/prctl.rb"] + + def self.eager_load + Dir.glob("lib/**/*.rb") do |file| + next if SKIP_LIST.include?(file) + require file + end + end + +end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 9d926b4bd1c..d52ff8be413 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,3 +1,8 @@ +require_relative 'coverage_helper' +# In order to archive an expected coverage analysis we need to eager load +# all logstash code base, otherwise it will not get a good analysis. +CoverageHelper.eager_load if ENV['COVERAGE'] + require "logstash/devutils/rspec/spec_helper" def installed_plugins