simplecov 0.6.0 → 0.22.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/CHANGELOG.md +163 -80
- data/LICENSE +1 -1
- data/README.md +776 -277
- data/doc/alternate-formatters.md +71 -0
- data/doc/commercial-services.md +25 -0
- data/doc/editor-integration.md +18 -0
- data/lib/minitest/simplecov_plugin.rb +15 -0
- data/lib/simplecov/combine/branches_combiner.rb +32 -0
- data/lib/simplecov/combine/files_combiner.rb +24 -0
- data/lib/simplecov/combine/lines_combiner.rb +43 -0
- data/lib/simplecov/combine/results_combiner.rb +60 -0
- data/lib/simplecov/combine.rb +30 -0
- data/lib/simplecov/command_guesser.rb +53 -38
- data/lib/simplecov/configuration.rb +478 -193
- data/lib/simplecov/coverage_statistics.rb +56 -0
- data/lib/simplecov/default_formatter.rb +20 -0
- data/lib/simplecov/defaults.rb +40 -44
- data/lib/simplecov/exit_codes/exit_code_handling.rb +29 -0
- data/lib/simplecov/exit_codes/maximum_coverage_drop_check.rb +83 -0
- data/lib/simplecov/exit_codes/minimum_coverage_by_file_check.rb +54 -0
- data/lib/simplecov/exit_codes/minimum_overall_coverage_check.rb +53 -0
- data/lib/simplecov/exit_codes.rb +15 -0
- data/lib/simplecov/file_list.rb +112 -36
- data/lib/simplecov/filter.rb +54 -4
- data/lib/simplecov/formatter/multi_formatter.rb +32 -0
- data/lib/simplecov/formatter/simple_formatter.rb +21 -15
- data/lib/simplecov/formatter.rb +4 -1
- data/lib/simplecov/last_run.rb +28 -0
- data/lib/simplecov/lines_classifier.rb +48 -0
- data/lib/simplecov/load_global_config.rb +8 -0
- data/lib/simplecov/no_defaults.rb +4 -0
- data/lib/simplecov/process.rb +19 -0
- data/lib/simplecov/profiles/bundler_filter.rb +5 -0
- data/lib/simplecov/profiles/hidden_filter.rb +5 -0
- data/lib/simplecov/profiles/rails.rb +18 -0
- data/lib/simplecov/profiles/root_filter.rb +10 -0
- data/lib/simplecov/profiles/test_frameworks.rb +8 -0
- data/lib/simplecov/profiles.rb +35 -0
- data/lib/simplecov/result.rb +33 -64
- data/lib/simplecov/result_adapter.rb +30 -0
- data/lib/simplecov/result_merger.rb +178 -64
- data/lib/simplecov/simulate_coverage.rb +29 -0
- data/lib/simplecov/source_file/branch.rb +84 -0
- data/lib/simplecov/source_file/line.rb +72 -0
- data/lib/simplecov/source_file.rb +304 -123
- data/lib/simplecov/useless_results_remover.rb +18 -0
- data/lib/simplecov/version.rb +4 -2
- data/lib/simplecov.rb +396 -49
- metadata +81 -242
- data/.gitignore +0 -30
- data/.rvmrc +0 -1
- data/.travis.yml +0 -13
- data/Gemfile +0 -9
- data/Rakefile +0 -16
- data/cucumber.yml +0 -13
- data/features/config_adapters.feature +0 -44
- data/features/config_autoload.feature +0 -46
- data/features/config_command_name.feature +0 -33
- data/features/config_coverage_dir.feature +0 -20
- data/features/config_deactivate_merging.feature +0 -42
- data/features/config_merge_timeout.feature +0 -38
- data/features/config_nocov_token.feature +0 -79
- data/features/config_project_name.feature +0 -27
- data/features/config_styles.feature +0 -93
- data/features/cucumber_basic.feature +0 -29
- data/features/merging_test_unit_and_rspec.feature +0 -44
- data/features/rspec_basic.feature +0 -31
- data/features/rspec_fails_on_initialization.feature +0 -14
- data/features/rspec_groups_and_filters_basic.feature +0 -29
- data/features/rspec_groups_and_filters_complex.feature +0 -35
- data/features/rspec_groups_using_filter_class.feature +0 -40
- data/features/rspec_without_simplecov.feature +0 -20
- data/features/skipping_code_blocks_manually.feature +0 -70
- data/features/step_definitions/html_steps.rb +0 -45
- data/features/step_definitions/simplecov_steps.rb +0 -61
- data/features/step_definitions/transformers.rb +0 -13
- data/features/step_definitions/web_steps.rb +0 -64
- data/features/support/env.rb +0 -26
- data/features/test_unit_basic.feature +0 -34
- data/features/test_unit_groups_and_filters_basic.feature +0 -29
- data/features/test_unit_groups_and_filters_complex.feature +0 -35
- data/features/test_unit_groups_using_filter_class.feature +0 -40
- data/features/test_unit_without_simplecov.feature +0 -20
- data/features/unicode_compatiblity.feature +0 -67
- data/lib/simplecov/adapters.rb +0 -29
- data/lib/simplecov/merge_helpers.rb +0 -39
- data/lib/simplecov/railtie.rb +0 -7
- data/lib/simplecov/railties/tasks.rake +0 -11
- data/simplecov.gemspec +0 -28
- data/test/faked_project/Gemfile +0 -6
- data/test/faked_project/Rakefile +0 -8
- data/test/faked_project/cucumber.yml +0 -13
- data/test/faked_project/features/step_definitions/my_steps.rb +0 -23
- data/test/faked_project/features/support/env.rb +0 -12
- data/test/faked_project/features/test_stuff.feature +0 -6
- data/test/faked_project/lib/faked_project/framework_specific.rb +0 -18
- data/test/faked_project/lib/faked_project/meta_magic.rb +0 -24
- data/test/faked_project/lib/faked_project/some_class.rb +0 -29
- data/test/faked_project/lib/faked_project.rb +0 -11
- data/test/faked_project/spec/faked_spec.rb +0 -11
- data/test/faked_project/spec/meta_magic_spec.rb +0 -10
- data/test/faked_project/spec/some_class_spec.rb +0 -10
- data/test/faked_project/spec/spec_helper.rb +0 -15
- data/test/faked_project/test/faked_test.rb +0 -11
- data/test/faked_project/test/meta_magic_test.rb +0 -13
- data/test/faked_project/test/some_class_test.rb +0 -15
- data/test/faked_project/test/test_helper.rb +0 -16
- data/test/fixtures/app/controllers/sample_controller.rb +0 -10
- data/test/fixtures/app/models/user.rb +0 -10
- data/test/fixtures/deleted_source_sample.rb +0 -15
- data/test/fixtures/frameworks/rspec_bad.rb +0 -9
- data/test/fixtures/frameworks/rspec_good.rb +0 -9
- data/test/fixtures/frameworks/testunit_bad.rb +0 -9
- data/test/fixtures/frameworks/testunit_good.rb +0 -9
- data/test/fixtures/resultset1.rb +0 -4
- data/test/fixtures/resultset2.rb +0 -5
- data/test/fixtures/sample.rb +0 -16
- data/test/fixtures/utf-8.rb +0 -3
- data/test/helper.rb +0 -35
- data/test/shoulda_macros.rb +0 -29
- data/test/test_1_8_fallbacks.rb +0 -33
- data/test/test_command_guesser.rb +0 -21
- data/test/test_deleted_source.rb +0 -16
- data/test/test_file_list.rb +0 -24
- data/test/test_filters.rb +0 -80
- data/test/test_merge_helpers.rb +0 -107
- data/test/test_result.rb +0 -147
- data/test/test_return_codes.rb +0 -39
- data/test/test_source_file.rb +0 -86
- data/test/test_source_file_line.rb +0 -110
@@ -1,19 +1,25 @@
|
|
1
|
-
#
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module SimpleCov
|
4
|
+
module Formatter
|
5
|
+
#
|
6
|
+
# A ridiculously simple formatter for SimpleCov results.
|
7
|
+
#
|
8
|
+
class SimpleFormatter
|
9
|
+
# Takes a SimpleCov::Result and generates a string out of it
|
10
|
+
def format(result)
|
11
|
+
output = +""
|
12
|
+
result.groups.each do |name, files|
|
13
|
+
output << "Group: #{name}\n"
|
14
|
+
output << "=" * 40
|
15
|
+
output << "\n"
|
16
|
+
files.each do |file|
|
17
|
+
output << "#{file.filename} (coverage: #{file.covered_percent.round(2)}%)\n"
|
18
|
+
end
|
19
|
+
output << "\n"
|
20
|
+
end
|
21
|
+
output
|
14
22
|
end
|
15
|
-
output << "\n"
|
16
23
|
end
|
17
|
-
output
|
18
24
|
end
|
19
25
|
end
|
data/lib/simplecov/formatter.rb
CHANGED
@@ -1,7 +1,10 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module SimpleCov
|
2
4
|
# TODO: Documentation on how to build your own formatters
|
3
5
|
module Formatter
|
4
6
|
end
|
5
7
|
end
|
6
8
|
|
7
|
-
|
9
|
+
require_relative "formatter/simple_formatter"
|
10
|
+
require_relative "formatter/multi_formatter"
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "json"
|
4
|
+
|
5
|
+
module SimpleCov
|
6
|
+
module LastRun
|
7
|
+
class << self
|
8
|
+
def last_run_path
|
9
|
+
File.join(SimpleCov.coverage_path, ".last_run.json")
|
10
|
+
end
|
11
|
+
|
12
|
+
def read
|
13
|
+
return nil unless File.exist?(last_run_path)
|
14
|
+
|
15
|
+
json = File.read(last_run_path)
|
16
|
+
return nil if json.strip.empty?
|
17
|
+
|
18
|
+
JSON.parse(json, symbolize_names: true)
|
19
|
+
end
|
20
|
+
|
21
|
+
def write(json)
|
22
|
+
File.open(last_run_path, "w+") do |f|
|
23
|
+
f.puts JSON.pretty_generate(json)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module SimpleCov
|
4
|
+
# Classifies whether lines are relevant for code coverage analysis.
|
5
|
+
# Comments & whitespace lines, and :nocov: token blocks, are considered not relevant.
|
6
|
+
|
7
|
+
class LinesClassifier
|
8
|
+
RELEVANT = 0
|
9
|
+
NOT_RELEVANT = nil
|
10
|
+
|
11
|
+
WHITESPACE_LINE = /^\s*$/.freeze
|
12
|
+
COMMENT_LINE = /^\s*#/.freeze
|
13
|
+
WHITESPACE_OR_COMMENT_LINE = Regexp.union(WHITESPACE_LINE, COMMENT_LINE)
|
14
|
+
|
15
|
+
def self.no_cov_line
|
16
|
+
/^(\s*)#(\s*)(:#{SimpleCov.nocov_token}:)/o
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.no_cov_line?(line)
|
20
|
+
no_cov_line.match?(line)
|
21
|
+
rescue ArgumentError
|
22
|
+
# E.g., line contains an invalid byte sequence in UTF-8
|
23
|
+
false
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.whitespace_line?(line)
|
27
|
+
WHITESPACE_OR_COMMENT_LINE.match?(line)
|
28
|
+
rescue ArgumentError
|
29
|
+
# E.g., line contains an invalid byte sequence in UTF-8
|
30
|
+
false
|
31
|
+
end
|
32
|
+
|
33
|
+
def classify(lines)
|
34
|
+
skipping = false
|
35
|
+
|
36
|
+
lines.map do |line|
|
37
|
+
if self.class.no_cov_line?(line)
|
38
|
+
skipping = !skipping
|
39
|
+
NOT_RELEVANT
|
40
|
+
elsif skipping || self.class.whitespace_line?(line)
|
41
|
+
NOT_RELEVANT
|
42
|
+
else
|
43
|
+
RELEVANT
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,8 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "etc"
|
4
|
+
home_dir = (ENV["HOME"] && File.expand_path("~")) || Etc.getpwuid.dir || (ENV["USER"] && File.expand_path("~#{ENV['USER']}"))
|
5
|
+
if home_dir
|
6
|
+
global_config_path = File.join(home_dir, ".simplecov")
|
7
|
+
load global_config_path if File.exist?(global_config_path)
|
8
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Process
|
4
|
+
class << self
|
5
|
+
def fork_with_simplecov(&block)
|
6
|
+
if defined?(SimpleCov) && SimpleCov.running
|
7
|
+
fork_without_simplecov do
|
8
|
+
SimpleCov.at_fork.call(Process.pid)
|
9
|
+
block.call if block_given?
|
10
|
+
end
|
11
|
+
else
|
12
|
+
fork_without_simplecov(&block)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
alias fork_without_simplecov fork
|
17
|
+
alias fork fork_with_simplecov
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
SimpleCov.profiles.define "rails" do
|
4
|
+
load_profile "test_frameworks"
|
5
|
+
|
6
|
+
add_filter %r{^/config/}
|
7
|
+
add_filter %r{^/db/}
|
8
|
+
|
9
|
+
add_group "Controllers", "app/controllers"
|
10
|
+
add_group "Channels", "app/channels"
|
11
|
+
add_group "Models", "app/models"
|
12
|
+
add_group "Mailers", "app/mailers"
|
13
|
+
add_group "Helpers", "app/helpers"
|
14
|
+
add_group "Jobs", %w[app/jobs app/workers]
|
15
|
+
add_group "Libraries", "lib/"
|
16
|
+
|
17
|
+
track_files "{app,lib}/**/*.rb"
|
18
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
SimpleCov.profiles.define "root_filter" do
|
4
|
+
# Exclude all files outside of simplecov root
|
5
|
+
root_filter = nil
|
6
|
+
add_filter do |src|
|
7
|
+
root_filter ||= /\A#{Regexp.escape(SimpleCov.root + File::SEPARATOR)}/io
|
8
|
+
src.filename !~ root_filter
|
9
|
+
end
|
10
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module SimpleCov
|
4
|
+
#
|
5
|
+
# Profiles are SimpleCov configuration procs that can be easily
|
6
|
+
# loaded using SimpleCov.start :rails and defined using
|
7
|
+
# SimpleCov.profiles.define :foo do
|
8
|
+
# # SimpleCov configuration here, same as in SimpleCov.configure
|
9
|
+
# end
|
10
|
+
#
|
11
|
+
class Profiles < Hash
|
12
|
+
#
|
13
|
+
# Define a SimpleCov profile:
|
14
|
+
# SimpleCov.profiles.define 'rails' do
|
15
|
+
# # Same as SimpleCov.configure do .. here
|
16
|
+
# end
|
17
|
+
#
|
18
|
+
def define(name, &blk)
|
19
|
+
name = name.to_sym
|
20
|
+
raise "SimpleCov Profile '#{name}' is already defined" unless self[name].nil?
|
21
|
+
|
22
|
+
self[name] = blk
|
23
|
+
end
|
24
|
+
|
25
|
+
#
|
26
|
+
# Applies the profile of given name on SimpleCov.configure
|
27
|
+
#
|
28
|
+
def load(name)
|
29
|
+
name = name.to_sym
|
30
|
+
raise "Could not find SimpleCov Profile called '#{name}'" unless key?(name)
|
31
|
+
|
32
|
+
SimpleCov.configure(&self[name])
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
data/lib/simplecov/result.rb
CHANGED
@@ -1,27 +1,37 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "digest/sha1"
|
4
|
+
require "forwardable"
|
2
5
|
|
3
6
|
module SimpleCov
|
4
7
|
#
|
5
|
-
# A simplecov code coverage result, initialized from the Hash Ruby
|
8
|
+
# A simplecov code coverage result, initialized from the Hash Ruby's built-in coverage
|
6
9
|
# library generates (Coverage.result).
|
7
10
|
#
|
8
11
|
class Result
|
12
|
+
extend Forwardable
|
9
13
|
# Returns the original Coverage.result used for this instance of SimpleCov::Result
|
10
14
|
attr_reader :original_result
|
11
15
|
# Returns all files that are applicable to this result (sans filters!) as instances of SimpleCov::SourceFile. Aliased as :source_files
|
12
16
|
attr_reader :files
|
13
|
-
|
17
|
+
alias source_files files
|
14
18
|
# Explicitly set the Time this result has been created
|
15
19
|
attr_writer :created_at
|
16
20
|
# Explicitly set the command name that was used for this coverage result. Defaults to SimpleCov.command_name
|
17
21
|
attr_writer :command_name
|
18
22
|
|
23
|
+
def_delegators :files, :covered_percent, :covered_percentages, :least_covered_file, :covered_strength, :covered_lines, :missed_lines, :total_branches, :covered_branches, :missed_branches, :coverage_statistics, :coverage_statistics_by_file
|
24
|
+
def_delegator :files, :lines_of_code, :total_lines
|
25
|
+
|
19
26
|
# Initialize a new SimpleCov::Result from given Coverage.result (a Hash of filenames each containing an array of
|
20
27
|
# coverage data)
|
21
|
-
def initialize(original_result)
|
22
|
-
|
23
|
-
@
|
24
|
-
|
28
|
+
def initialize(original_result, command_name: nil, created_at: nil)
|
29
|
+
result = original_result
|
30
|
+
@original_result = result.freeze
|
31
|
+
@command_name = command_name
|
32
|
+
@created_at = created_at
|
33
|
+
@files = SimpleCov::FileList.new(result.map do |filename, coverage|
|
34
|
+
SimpleCov::SourceFile.new(filename, JSON.parse(JSON.dump(coverage))) if File.file?(filename)
|
25
35
|
end.compact.sort_by(&:filename))
|
26
36
|
filter!
|
27
37
|
end
|
@@ -36,55 +46,6 @@ module SimpleCov
|
|
36
46
|
@groups ||= SimpleCov.grouped(files)
|
37
47
|
end
|
38
48
|
|
39
|
-
# The overall percentual coverage for this result
|
40
|
-
def covered_percent
|
41
|
-
# Make sure that weird rounding error from #15, #23 and #24 does not occur again!
|
42
|
-
total_lines.zero? ? 0 : 100.0 * covered_lines / total_lines
|
43
|
-
end
|
44
|
-
|
45
|
-
# The multiple of coverage for this result
|
46
|
-
def covered_strength
|
47
|
-
return @covered_strength if @covered_strength
|
48
|
-
m = 0
|
49
|
-
@files.each do |file|
|
50
|
-
original_result[file.filename].each do |line_result|
|
51
|
-
if line_result
|
52
|
-
m += line_result
|
53
|
-
end
|
54
|
-
end
|
55
|
-
end
|
56
|
-
@covered_strength = m.to_f / total_lines
|
57
|
-
end
|
58
|
-
|
59
|
-
# Returns the count of lines that are covered
|
60
|
-
def covered_lines
|
61
|
-
return @covered_lines if @covered_lines
|
62
|
-
@covered_lines = 0
|
63
|
-
@files.each do |file|
|
64
|
-
original_result[file.filename].each do |line_result|
|
65
|
-
@covered_lines += 1 if line_result and line_result > 0
|
66
|
-
end
|
67
|
-
end
|
68
|
-
@covered_lines
|
69
|
-
end
|
70
|
-
|
71
|
-
# Returns the count of missed lines
|
72
|
-
def missed_lines
|
73
|
-
return @missed_lines if @missed_lines
|
74
|
-
@missed_lines = 0
|
75
|
-
@files.each do |file|
|
76
|
-
original_result[file.filename].each do |line_result|
|
77
|
-
@missed_lines += 1 if line_result == 0
|
78
|
-
end
|
79
|
-
end
|
80
|
-
@missed_lines
|
81
|
-
end
|
82
|
-
|
83
|
-
# Total count of relevant lines (covered + missed)
|
84
|
-
def total_lines
|
85
|
-
@total_lines ||= (covered_lines + missed_lines)
|
86
|
-
end
|
87
|
-
|
88
49
|
# Applies the configured SimpleCov.formatter on this result
|
89
50
|
def format!
|
90
51
|
SimpleCov.formatter.new.format(self)
|
@@ -101,21 +62,29 @@ module SimpleCov
|
|
101
62
|
@command_name ||= SimpleCov.command_name
|
102
63
|
end
|
103
64
|
|
104
|
-
# Returns a hash representation of this Result that can be used for marshalling it into
|
65
|
+
# Returns a hash representation of this Result that can be used for marshalling it into JSON
|
105
66
|
def to_hash
|
106
|
-
{
|
67
|
+
{
|
68
|
+
command_name => {
|
69
|
+
"coverage" => coverage,
|
70
|
+
"timestamp" => created_at.to_i
|
71
|
+
}
|
72
|
+
}
|
107
73
|
end
|
108
74
|
|
109
75
|
# Loads a SimpleCov::Result#to_hash dump
|
110
76
|
def self.from_hash(hash)
|
111
|
-
command_name, data
|
112
|
-
|
113
|
-
|
114
|
-
result.created_at = Time.at(data["timestamp"])
|
115
|
-
result
|
77
|
+
hash.map do |command_name, data|
|
78
|
+
new(data.fetch("coverage"), command_name: command_name, created_at: Time.at(data["timestamp"]))
|
79
|
+
end
|
116
80
|
end
|
117
81
|
|
118
|
-
|
82
|
+
private
|
83
|
+
|
84
|
+
def coverage
|
85
|
+
keys = original_result.keys & filenames
|
86
|
+
Hash[keys.zip(original_result.values_at(*keys))]
|
87
|
+
end
|
119
88
|
|
120
89
|
# Applies all configured SimpleCov filters on this result's source files
|
121
90
|
def filter!
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module SimpleCov
|
4
|
+
#
|
5
|
+
# Responsible for adapting the format of the coverage result whether it's default or with statistics
|
6
|
+
#
|
7
|
+
class ResultAdapter
|
8
|
+
attr_reader :result
|
9
|
+
|
10
|
+
def initialize(result)
|
11
|
+
@result = result
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.call(*args)
|
15
|
+
new(*args).adapt
|
16
|
+
end
|
17
|
+
|
18
|
+
def adapt
|
19
|
+
return unless result
|
20
|
+
|
21
|
+
result.each_with_object({}) do |(file_name, cover_statistic), adapted_result|
|
22
|
+
if cover_statistic.is_a?(Array)
|
23
|
+
adapted_result.merge!(file_name => {"lines" => cover_statistic})
|
24
|
+
else
|
25
|
+
adapted_result.merge!(file_name => cover_statistic)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|