Skip to content

Commit

Permalink
fix the coverage analysis throw simplecov to take care of all files
Browse files Browse the repository at this point in the history
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 elastic#3465
  • Loading branch information
Pere Urbon-Bayes authored and jordansissel committed Jun 25, 2015
1 parent e715248 commit cf10890
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/logstash/environment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def jruby?
end

def windows?
Gem.win_platform?
::Gem.win_platform?
end

def vendor_path(path)
Expand Down
30 changes: 30 additions & 0 deletions rakelib/test.rake
Original file line number Diff line number Diff line change
Expand Up @@ -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]})

Expand Down Expand Up @@ -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" ]
14 changes: 14 additions & 0 deletions spec/coverage_helper.rb
Original file line number Diff line number Diff line change
@@ -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
5 changes: 5 additions & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -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
Expand Down

0 comments on commit cf10890

Please sign in to comment.