simplecov 0.15.1 → 0.16.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/CHANGELOG.md +17 -1
- data/CONTRIBUTING.md +12 -9
- data/ISSUE_TEMPLATE.md +23 -0
- data/README.md +41 -14
- data/doc/alternate-formatters.md +10 -0
- data/lib/simplecov.rb +91 -0
- data/lib/simplecov/command_guesser.rb +2 -0
- data/lib/simplecov/configuration.rb +2 -0
- data/lib/simplecov/defaults.rb +9 -80
- data/lib/simplecov/exit_codes.rb +2 -0
- data/lib/simplecov/file_list.rb +2 -0
- data/lib/simplecov/filter.rb +3 -1
- data/lib/simplecov/formatter.rb +2 -0
- data/lib/simplecov/formatter/multi_formatter.rb +2 -0
- data/lib/simplecov/formatter/simple_formatter.rb +2 -0
- data/lib/simplecov/jruby_fix.rb +2 -0
- data/lib/simplecov/last_run.rb +2 -0
- data/lib/simplecov/lines_classifier.rb +19 -3
- data/lib/simplecov/load_global_config.rb +2 -0
- data/lib/simplecov/no_defaults.rb +2 -0
- data/lib/simplecov/profiles.rb +2 -0
- data/lib/simplecov/profiles/bundler_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/railtie.rb +2 -0
- data/lib/simplecov/railties/tasks.rake +2 -0
- data/lib/simplecov/raw_coverage.rb +2 -0
- data/lib/simplecov/result.rb +2 -0
- data/lib/simplecov/result_merger.rb +2 -0
- data/lib/simplecov/source_file.rb +3 -1
- data/lib/simplecov/version.rb +3 -1
- metadata +22 -118
- data/.gitignore +0 -31
- data/.rspec +0 -3
- data/.rubocop.yml +0 -88
- data/.travis.yml +0 -29
- data/.yardopts +0 -1
- data/Gemfile +0 -38
- data/MIT-LICENSE +0 -20
- data/Rakefile +0 -39
- data/cucumber.yml +0 -13
- data/features/config_autoload.feature +0 -46
- data/features/config_command_name.feature +0 -45
- data/features/config_coverage_dir.feature +0 -33
- data/features/config_deactivate_merging.feature +0 -42
- data/features/config_formatters.feature +0 -77
- data/features/config_merge_timeout.feature +0 -39
- data/features/config_nocov_token.feature +0 -79
- data/features/config_profiles.feature +0 -44
- data/features/config_project_name.feature +0 -27
- data/features/config_styles.feature +0 -121
- data/features/config_tracked_files.feature +0 -29
- data/features/config_tracked_files_relevant_lines.feature +0 -31
- data/features/cucumber_basic.feature +0 -29
- data/features/maximum_coverage_drop.feature +0 -89
- data/features/merging_test_unit_and_rspec.feature +0 -44
- data/features/minimum_coverage.feature +0 -59
- data/features/refuse_coverage_drop.feature +0 -95
- data/features/rspec_basic.feature +0 -32
- 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 -37
- data/features/rspec_groups_using_filter_class.feature +0 -41
- 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 -44
- data/features/step_definitions/simplecov_steps.rb +0 -68
- data/features/step_definitions/transformers.rb +0 -13
- data/features/step_definitions/web_steps.rb +0 -64
- data/features/support/aruba_freedom_patch.rb +0 -53
- data/features/support/env.rb +0 -50
- 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/simplecov.gemspec +0 -27
- data/spec/1_8_fallbacks_spec.rb +0 -31
- data/spec/command_guesser_spec.rb +0 -48
- data/spec/config_loader_spec.rb +0 -14
- data/spec/configuration_spec.rb +0 -35
- data/spec/defaults_spec.rb +0 -41
- data/spec/deleted_source_spec.rb +0 -12
- data/spec/faked_project/Gemfile +0 -6
- data/spec/faked_project/Rakefile +0 -8
- data/spec/faked_project/cucumber.yml +0 -13
- data/spec/faked_project/features/step_definitions/my_steps.rb +0 -22
- data/spec/faked_project/features/support/env.rb +0 -12
- data/spec/faked_project/features/test_stuff.feature +0 -6
- data/spec/faked_project/lib/faked_project.rb +0 -11
- data/spec/faked_project/lib/faked_project/framework_specific.rb +0 -18
- data/spec/faked_project/lib/faked_project/meta_magic.rb +0 -24
- data/spec/faked_project/lib/faked_project/some_class.rb +0 -28
- data/spec/faked_project/lib/faked_project/untested_class.rb +0 -11
- data/spec/faked_project/spec/faked_spec.rb +0 -11
- data/spec/faked_project/spec/forking_spec.rb +0 -8
- data/spec/faked_project/spec/meta_magic_spec.rb +0 -15
- data/spec/faked_project/spec/some_class_spec.rb +0 -13
- data/spec/faked_project/spec/spec_helper.rb +0 -11
- data/spec/faked_project/test/faked_test.rb +0 -11
- data/spec/faked_project/test/meta_magic_test.rb +0 -13
- data/spec/faked_project/test/some_class_test.rb +0 -15
- data/spec/faked_project/test/test_helper.rb +0 -12
- data/spec/file_list_spec.rb +0 -50
- data/spec/filters_spec.rb +0 -202
- data/spec/fixtures/app/controllers/sample_controller.rb +0 -10
- data/spec/fixtures/app/models/user.rb +0 -10
- data/spec/fixtures/deleted_source_sample.rb +0 -15
- data/spec/fixtures/frameworks/rspec_bad.rb +0 -9
- data/spec/fixtures/frameworks/rspec_good.rb +0 -9
- data/spec/fixtures/frameworks/testunit_bad.rb +0 -9
- data/spec/fixtures/frameworks/testunit_good.rb +0 -9
- data/spec/fixtures/iso-8859.rb +0 -3
- data/spec/fixtures/never.rb +0 -2
- data/spec/fixtures/resultset1.rb +0 -4
- data/spec/fixtures/resultset2.rb +0 -4
- data/spec/fixtures/sample.rb +0 -16
- data/spec/fixtures/skipped.rb +0 -4
- data/spec/fixtures/skipped_and_executed.rb +0 -8
- data/spec/fixtures/utf-8.rb +0 -3
- data/spec/helper.rb +0 -26
- data/spec/last_run_spec.rb +0 -48
- data/spec/lines_classifier_spec.rb +0 -103
- data/spec/multi_formatter_spec.rb +0 -20
- data/spec/raw_coverage_spec.rb +0 -92
- data/spec/result_merger_spec.rb +0 -171
- data/spec/result_spec.rb +0 -209
- data/spec/return_codes_spec.rb +0 -34
- data/spec/simplecov_spec.rb +0 -109
- data/spec/source_file_line_spec.rb +0 -155
- data/spec/source_file_spec.rb +0 -145
- data/spec/support/fail_rspec_on_ruby_warning.rb +0 -75
@@ -1,15 +0,0 @@
|
|
1
|
-
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), "..", ".."))
|
2
|
-
require "lib/simplecov"
|
3
|
-
SimpleCov.start { command_name "Test" }
|
4
|
-
|
5
|
-
dir = File.expand_path(File.dirname(__FILE__))
|
6
|
-
file = File.join(dir, "generated_buddha.rb")
|
7
|
-
code = %{
|
8
|
-
def kill_the_buddha(z)
|
9
|
-
z**z
|
10
|
-
end
|
11
|
-
}
|
12
|
-
File.open(file, "w") { |f| f.print code }
|
13
|
-
load file
|
14
|
-
File.unlink file
|
15
|
-
raise unless kill_the_buddha(3) == 27
|
@@ -1,9 +0,0 @@
|
|
1
|
-
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), "..", "..", ".."))
|
2
|
-
require "lib/simplecov"
|
3
|
-
require "rspec"
|
4
|
-
SimpleCov.start
|
5
|
-
describe "exit status" do
|
6
|
-
it "should exit with a non-zero exit status when assertion fails" do
|
7
|
-
expect(1).to eq(2)
|
8
|
-
end
|
9
|
-
end
|
data/spec/fixtures/iso-8859.rb
DELETED
data/spec/fixtures/never.rb
DELETED
data/spec/fixtures/resultset1.rb
DELETED
data/spec/fixtures/resultset2.rb
DELETED
data/spec/fixtures/sample.rb
DELETED
data/spec/fixtures/skipped.rb
DELETED
data/spec/fixtures/utf-8.rb
DELETED
data/spec/helper.rb
DELETED
@@ -1,26 +0,0 @@
|
|
1
|
-
require "rspec"
|
2
|
-
# loaded before simplecov to also capture parse time warnings
|
3
|
-
require "support/fail_rspec_on_ruby_warning"
|
4
|
-
require "simplecov"
|
5
|
-
|
6
|
-
SimpleCov.coverage_dir("tmp/coverage")
|
7
|
-
|
8
|
-
def source_fixture(filename)
|
9
|
-
File.expand_path(File.join(File.dirname(__FILE__), "fixtures", filename))
|
10
|
-
end
|
11
|
-
|
12
|
-
# Taken from http://stackoverflow.com/questions/4459330/how-do-i-temporarily-redirect-stderr-in-ruby
|
13
|
-
require "stringio"
|
14
|
-
|
15
|
-
def capture_stderr
|
16
|
-
# The output stream must be an IO-like object. In this case we capture it in
|
17
|
-
# an in-memory IO object so we can return the string value. You can assign any
|
18
|
-
# IO object here.
|
19
|
-
previous_stderr = $stderr
|
20
|
-
$stderr = StringIO.new
|
21
|
-
yield
|
22
|
-
$stderr.string
|
23
|
-
ensure
|
24
|
-
# Restore the previous value of stderr (typically equal to STDERR).
|
25
|
-
$stderr = previous_stderr
|
26
|
-
end
|
data/spec/last_run_spec.rb
DELETED
@@ -1,48 +0,0 @@
|
|
1
|
-
require "helper"
|
2
|
-
|
3
|
-
if SimpleCov.usable?
|
4
|
-
describe SimpleCov::LastRun do
|
5
|
-
subject { SimpleCov::LastRun }
|
6
|
-
|
7
|
-
it "defines a last_run_path" do
|
8
|
-
expect(subject.last_run_path).to include "tmp/coverage/.last_run.json"
|
9
|
-
end
|
10
|
-
|
11
|
-
it "writes json to its last_run_path that can be parsed again" do
|
12
|
-
structure = [{"key" => "value"}]
|
13
|
-
subject.write(structure)
|
14
|
-
file_contents = File.read(subject.last_run_path)
|
15
|
-
expect(JSON.parse(file_contents)).to eq structure
|
16
|
-
end
|
17
|
-
|
18
|
-
context "reading" do
|
19
|
-
context "but the last_run file does not exist" do
|
20
|
-
before { File.delete(subject.last_run_path) if File.exist?(subject.last_run_path) }
|
21
|
-
|
22
|
-
it "returns nil" do
|
23
|
-
expect(subject.read).to be_nil
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
context "a non empty result" do
|
28
|
-
before { subject.write([]) }
|
29
|
-
|
30
|
-
it "reads json from its last_run_path" do
|
31
|
-
expect(subject.read).to eq([])
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
context "an empty result" do
|
36
|
-
before do
|
37
|
-
File.open(subject.last_run_path, "w+") do |f|
|
38
|
-
f.puts ""
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
it "returns nil" do
|
43
|
-
expect(subject.read).to be_nil
|
44
|
-
end
|
45
|
-
end
|
46
|
-
end
|
47
|
-
end
|
48
|
-
end
|
@@ -1,103 +0,0 @@
|
|
1
|
-
require "helper"
|
2
|
-
require "simplecov/lines_classifier"
|
3
|
-
|
4
|
-
describe SimpleCov::LinesClassifier do
|
5
|
-
describe "#classify" do
|
6
|
-
describe "relevant lines" do
|
7
|
-
it "determines code as relevant" do
|
8
|
-
classified_lines = subject.classify [
|
9
|
-
"module Foo",
|
10
|
-
" class Baz",
|
11
|
-
" def Bar",
|
12
|
-
" puts 'hi'",
|
13
|
-
" end",
|
14
|
-
" end",
|
15
|
-
"end",
|
16
|
-
]
|
17
|
-
|
18
|
-
expect(classified_lines.length).to eq 7
|
19
|
-
expect(classified_lines).to all be_relevant
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
describe "not-relevant lines" do
|
24
|
-
it "determines whitespace is not-relevant" do
|
25
|
-
classified_lines = subject.classify [
|
26
|
-
"",
|
27
|
-
" ",
|
28
|
-
"\t\t",
|
29
|
-
]
|
30
|
-
|
31
|
-
expect(classified_lines.length).to eq 3
|
32
|
-
expect(classified_lines).to all be_irrelevant
|
33
|
-
end
|
34
|
-
|
35
|
-
describe "comments" do
|
36
|
-
it "determines comments are not-relevant" do
|
37
|
-
classified_lines = subject.classify [
|
38
|
-
"#Comment",
|
39
|
-
" # Leading space comment",
|
40
|
-
"\t# Leading tab comment",
|
41
|
-
]
|
42
|
-
|
43
|
-
expect(classified_lines.length).to eq 3
|
44
|
-
expect(classified_lines).to all be_irrelevant
|
45
|
-
end
|
46
|
-
|
47
|
-
it "doesn't mistake interpolation as a comment" do
|
48
|
-
classified_lines = subject.classify [
|
49
|
-
'puts "#{var}"',
|
50
|
-
]
|
51
|
-
|
52
|
-
expect(classified_lines.length).to eq 1
|
53
|
-
expect(classified_lines).to all be_relevant
|
54
|
-
end
|
55
|
-
end
|
56
|
-
|
57
|
-
describe ":nocov: blocks" do
|
58
|
-
it "determines :nocov: blocks are not-relevant" do
|
59
|
-
classified_lines = subject.classify [
|
60
|
-
"# :nocov:",
|
61
|
-
"def hi",
|
62
|
-
"end",
|
63
|
-
"# :nocov:",
|
64
|
-
]
|
65
|
-
|
66
|
-
expect(classified_lines.length).to eq 4
|
67
|
-
expect(classified_lines).to all be_irrelevant
|
68
|
-
end
|
69
|
-
|
70
|
-
it "determines all lines after a non-closing :nocov: as not-relevant" do
|
71
|
-
classified_lines = subject.classify [
|
72
|
-
"# :nocov:",
|
73
|
-
"puts 'Not relevant'",
|
74
|
-
"# :nocov:",
|
75
|
-
"puts 'Relevant again'",
|
76
|
-
"puts 'Still relevant'",
|
77
|
-
"# :nocov:",
|
78
|
-
"puts 'Not relevant till the end'",
|
79
|
-
"puts 'Ditto'",
|
80
|
-
]
|
81
|
-
|
82
|
-
expect(classified_lines.length).to eq 8
|
83
|
-
|
84
|
-
expect(classified_lines[0..2]).to all be_irrelevant
|
85
|
-
expect(classified_lines[3..4]).to all be_relevant
|
86
|
-
expect(classified_lines[5..7]).to all be_irrelevant
|
87
|
-
end
|
88
|
-
end
|
89
|
-
end
|
90
|
-
end
|
91
|
-
|
92
|
-
RSpec::Matchers.define :be_relevant do
|
93
|
-
match do |actual|
|
94
|
-
actual == SimpleCov::LinesClassifier::RELEVANT
|
95
|
-
end
|
96
|
-
end
|
97
|
-
|
98
|
-
RSpec::Matchers.define :be_irrelevant do
|
99
|
-
match do |actual|
|
100
|
-
actual == SimpleCov::LinesClassifier::NOT_RELEVANT
|
101
|
-
end
|
102
|
-
end
|
103
|
-
end
|
@@ -1,20 +0,0 @@
|
|
1
|
-
require "helper"
|
2
|
-
|
3
|
-
require "simplecov/formatter/multi_formatter"
|
4
|
-
|
5
|
-
describe SimpleCov::Formatter::MultiFormatter do
|
6
|
-
describe ".[]" do
|
7
|
-
# Regression test for https://github.com/colszowka/simplecov/issues/428
|
8
|
-
it "constructs a formatter with multiple children" do
|
9
|
-
# Silence deprecation warnings.
|
10
|
-
allow(described_class).to receive(:warn)
|
11
|
-
|
12
|
-
children = [
|
13
|
-
SimpleCov::Formatter::SimpleFormatter,
|
14
|
-
SimpleCov::Formatter::SimpleFormatter,
|
15
|
-
]
|
16
|
-
|
17
|
-
expect(described_class[*children].new.formatters).to eq(children)
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
data/spec/raw_coverage_spec.rb
DELETED
@@ -1,92 +0,0 @@
|
|
1
|
-
require "helper"
|
2
|
-
|
3
|
-
if SimpleCov.usable?
|
4
|
-
describe SimpleCov::RawCoverage do
|
5
|
-
describe "with two faked coverage resultsets" do
|
6
|
-
before do
|
7
|
-
@resultset1 = {
|
8
|
-
source_fixture("sample.rb") => [nil, 1, 1, 1, nil, nil, 1, 1, nil, nil],
|
9
|
-
source_fixture("app/models/user.rb") => [nil, 1, 1, 1, nil, nil, 1, 0, nil, nil],
|
10
|
-
source_fixture("app/controllers/sample_controller.rb") => [nil, 1, 1, 1, nil, nil, 1, 0, nil, nil],
|
11
|
-
source_fixture("resultset1.rb") => [1, 1, 1, 1],
|
12
|
-
source_fixture("parallel_tests.rb") => [nil, 0, nil, 0],
|
13
|
-
source_fixture("conditionally_loaded_1.rb") => [nil, 0, 1], # loaded only in the first resultset
|
14
|
-
source_fixture("three.rb") => [nil, 1, 1],
|
15
|
-
}
|
16
|
-
|
17
|
-
@resultset2 = {
|
18
|
-
source_fixture("sample.rb") => [1, nil, 1, 1, nil, nil, 1, 1, nil, nil],
|
19
|
-
source_fixture("app/models/user.rb") => [nil, 1, 5, 1, nil, nil, 1, 0, nil, nil],
|
20
|
-
source_fixture("app/controllers/sample_controller.rb") => [nil, 3, 1, nil, nil, nil, 1, 0, nil, nil],
|
21
|
-
source_fixture("resultset2.rb") => [nil, 1, 1, nil],
|
22
|
-
source_fixture("parallel_tests.rb") => [nil, nil, 0, 0],
|
23
|
-
source_fixture("conditionally_loaded_2.rb") => [nil, 0, 1], # loaded only in the second resultset
|
24
|
-
source_fixture("three.rb") => [nil, 1, 4],
|
25
|
-
}
|
26
|
-
|
27
|
-
@resultset3 = {
|
28
|
-
source_fixture("three.rb") => [nil, 1, 2],
|
29
|
-
}
|
30
|
-
end
|
31
|
-
|
32
|
-
context "a merge" do
|
33
|
-
subject do
|
34
|
-
SimpleCov::RawCoverage.merge_results(@resultset1, @resultset2, @resultset3)
|
35
|
-
end
|
36
|
-
|
37
|
-
it "has proper results for sample.rb" do
|
38
|
-
expect(subject[source_fixture("sample.rb")]).to eq([1, 1, 2, 2, nil, nil, 2, 2, nil, nil])
|
39
|
-
end
|
40
|
-
|
41
|
-
it "has proper results for user.rb" do
|
42
|
-
expect(subject[source_fixture("app/models/user.rb")]).to eq([nil, 2, 6, 2, nil, nil, 2, 0, nil, nil])
|
43
|
-
end
|
44
|
-
|
45
|
-
it "has proper results for sample_controller.rb" do
|
46
|
-
expect(subject[source_fixture("app/controllers/sample_controller.rb")]).to eq([nil, 4, 2, 1, nil, nil, 2, 0, nil, nil])
|
47
|
-
end
|
48
|
-
|
49
|
-
it "has proper results for resultset1.rb" do
|
50
|
-
expect(subject[source_fixture("resultset1.rb")]).to eq([1, 1, 1, 1])
|
51
|
-
end
|
52
|
-
|
53
|
-
it "has proper results for resultset2.rb" do
|
54
|
-
expect(subject[source_fixture("resultset2.rb")]).to eq([nil, 1, 1, nil])
|
55
|
-
end
|
56
|
-
|
57
|
-
it "has proper results for parallel_tests.rb" do
|
58
|
-
expect(subject[source_fixture("parallel_tests.rb")]).to eq([nil, nil, nil, 0])
|
59
|
-
end
|
60
|
-
|
61
|
-
it "has proper results for conditionally_loaded_1.rb" do
|
62
|
-
expect(subject[source_fixture("conditionally_loaded_1.rb")]).to eq([nil, 0, 1])
|
63
|
-
end
|
64
|
-
|
65
|
-
it "has proper results for conditionally_loaded_2.rb" do
|
66
|
-
expect(subject[source_fixture("conditionally_loaded_2.rb")]).to eq([nil, 0, 1])
|
67
|
-
end
|
68
|
-
|
69
|
-
it "has proper results for three.rb" do
|
70
|
-
expect(subject[source_fixture("three.rb")]).to eq([nil, 3, 7])
|
71
|
-
end
|
72
|
-
end
|
73
|
-
end
|
74
|
-
|
75
|
-
it "merges frozen resultsets" do
|
76
|
-
resultset1 = {
|
77
|
-
source_fixture("sample.rb").freeze => [nil, 1, 1, 1, nil, nil, 1, 1, nil, nil].freeze,
|
78
|
-
source_fixture("app/models/user.rb").freeze => [nil, 1, 1, 1, nil, nil, 1, 0, nil, nil].freeze,
|
79
|
-
}.freeze
|
80
|
-
|
81
|
-
resultset2 = {
|
82
|
-
source_fixture("sample.rb").freeze => [1, nil, 1, 1, nil, nil, 1, 1, nil, nil].freeze,
|
83
|
-
}.freeze
|
84
|
-
|
85
|
-
merged_result = SimpleCov::RawCoverage.merge_results(resultset1, resultset2)
|
86
|
-
expect(merged_result.keys).to eq(resultset1.keys)
|
87
|
-
expect(merged_result.values.map(&:frozen?)).to eq([false, false])
|
88
|
-
expect(merged_result[source_fixture("sample.rb")]).to eq([1, 1, 2, 2, nil, nil, 2, 2, nil, nil])
|
89
|
-
expect(merged_result[source_fixture("app/models/user.rb")]).to eq([nil, 1, 1, 1, nil, nil, 1, 0, nil, nil])
|
90
|
-
end
|
91
|
-
end
|
92
|
-
end
|
data/spec/result_merger_spec.rb
DELETED
@@ -1,171 +0,0 @@
|
|
1
|
-
require "helper"
|
2
|
-
require "tempfile"
|
3
|
-
require "timeout"
|
4
|
-
|
5
|
-
if SimpleCov.usable?
|
6
|
-
describe SimpleCov::ResultMerger do
|
7
|
-
before do
|
8
|
-
SimpleCov::ResultMerger.clear_resultset
|
9
|
-
File.delete(SimpleCov::ResultMerger.resultset_path) if File.exist?(SimpleCov::ResultMerger.resultset_path)
|
10
|
-
end
|
11
|
-
|
12
|
-
describe "with two faked coverage resultsets" do
|
13
|
-
before do
|
14
|
-
@resultset1 = {
|
15
|
-
source_fixture("sample.rb") => [nil, 1, 1, 1, nil, nil, 1, 1, nil, nil],
|
16
|
-
source_fixture("app/models/user.rb") => [nil, 1, 1, 1, nil, nil, 1, 0, nil, nil],
|
17
|
-
source_fixture("app/controllers/sample_controller.rb") => [nil, 1, 1, 1, nil, nil, 1, 0, nil, nil],
|
18
|
-
source_fixture("resultset1.rb") => [1, 1, 1, 1],
|
19
|
-
source_fixture("parallel_tests.rb") => [nil, 0, nil, 0],
|
20
|
-
source_fixture("conditionally_loaded_1.rb") => [nil, 0, 1], # loaded only in the first resultset
|
21
|
-
}
|
22
|
-
|
23
|
-
@resultset2 = {
|
24
|
-
source_fixture("sample.rb") => [1, nil, 1, 1, nil, nil, 1, 1, nil, nil],
|
25
|
-
source_fixture("app/models/user.rb") => [nil, 1, 5, 1, nil, nil, 1, 0, nil, nil],
|
26
|
-
source_fixture("app/controllers/sample_controller.rb") => [nil, 3, 1, nil, nil, nil, 1, 0, nil, nil],
|
27
|
-
source_fixture("resultset2.rb") => [nil, 1, 1, nil],
|
28
|
-
source_fixture("parallel_tests.rb") => [nil, nil, 0, 0],
|
29
|
-
source_fixture("conditionally_loaded_2.rb") => [nil, 0, 1], # loaded only in the second resultset
|
30
|
-
}
|
31
|
-
end
|
32
|
-
|
33
|
-
# See Github issue #6
|
34
|
-
it "returns an empty hash when the resultset cache file is empty" do
|
35
|
-
File.open(SimpleCov::ResultMerger.resultset_path, "w+") { |f| f.puts "" }
|
36
|
-
expect(SimpleCov::ResultMerger.resultset).to be_empty
|
37
|
-
end
|
38
|
-
|
39
|
-
# See Github issue #6
|
40
|
-
it "returns an empty hash when the resultset cache file is not present" do
|
41
|
-
system "rm #{SimpleCov::ResultMerger.resultset_path}" if File.exist?(SimpleCov::ResultMerger.resultset_path)
|
42
|
-
expect(SimpleCov::ResultMerger.resultset).to be_empty
|
43
|
-
end
|
44
|
-
|
45
|
-
context "and results generated from those" do
|
46
|
-
before do
|
47
|
-
system "rm #{SimpleCov::ResultMerger.resultset_path}" if File.exist?(SimpleCov::ResultMerger.resultset_path)
|
48
|
-
@result1 = SimpleCov::Result.new(@resultset1)
|
49
|
-
@result1.command_name = "result1"
|
50
|
-
@result2 = SimpleCov::Result.new(@resultset2)
|
51
|
-
@result2.command_name = "result2"
|
52
|
-
end
|
53
|
-
|
54
|
-
context "with stored results" do
|
55
|
-
before do
|
56
|
-
SimpleCov::ResultMerger.store_result(@result1)
|
57
|
-
SimpleCov::ResultMerger.store_result(@result2)
|
58
|
-
end
|
59
|
-
|
60
|
-
it "has stored data in resultset_path JSON file" do
|
61
|
-
expect(File.readlines(SimpleCov::ResultMerger.resultset_path).length).to be > 50
|
62
|
-
end
|
63
|
-
|
64
|
-
it "returns a hash containing keys ['result1' and 'result2'] for resultset" do
|
65
|
-
expect(SimpleCov::ResultMerger.resultset.keys.sort).to eq %w[result1 result2]
|
66
|
-
end
|
67
|
-
|
68
|
-
it "returns proper values for merged_result" do
|
69
|
-
expect(SimpleCov::ResultMerger.merged_result.source_files.find { |s| s.filename =~ /user/ }.lines.map(&:coverage)).to eq([nil, 2, 6, 2, nil, nil, 2, 0, nil, nil])
|
70
|
-
end
|
71
|
-
|
72
|
-
context "with second result way above the merge_timeout" do
|
73
|
-
before do
|
74
|
-
@result2.created_at = Time.now - 172_800 # two days ago
|
75
|
-
SimpleCov::ResultMerger.store_result(@result2)
|
76
|
-
end
|
77
|
-
|
78
|
-
it "has only one result in SimpleCov::ResultMerger.results" do
|
79
|
-
expect(SimpleCov::ResultMerger.results.length).to eq(1)
|
80
|
-
end
|
81
|
-
end
|
82
|
-
end
|
83
|
-
end
|
84
|
-
end
|
85
|
-
|
86
|
-
describe ".store_result" do
|
87
|
-
it "refreshes the resultset" do
|
88
|
-
set = SimpleCov::ResultMerger.resultset
|
89
|
-
SimpleCov::ResultMerger.store_result({})
|
90
|
-
new_set = SimpleCov::ResultMerger.resultset
|
91
|
-
expect(new_set).not_to be(set)
|
92
|
-
end
|
93
|
-
|
94
|
-
it "persists to disk" do
|
95
|
-
SimpleCov::ResultMerger.store_result("a" => [1])
|
96
|
-
SimpleCov::ResultMerger.clear_resultset
|
97
|
-
new_set = SimpleCov::ResultMerger.resultset
|
98
|
-
expect(new_set).to eq("a" => [1])
|
99
|
-
end
|
100
|
-
|
101
|
-
it "synchronizes writes" do
|
102
|
-
expect(SimpleCov::ResultMerger).to receive(:synchronize_resultset)
|
103
|
-
SimpleCov::ResultMerger.store_result({})
|
104
|
-
end
|
105
|
-
end
|
106
|
-
|
107
|
-
describe ".resultset" do
|
108
|
-
it "caches" do
|
109
|
-
set = SimpleCov::ResultMerger.resultset
|
110
|
-
new_set = SimpleCov::ResultMerger.resultset
|
111
|
-
expect(new_set).to be(set)
|
112
|
-
end
|
113
|
-
|
114
|
-
it "synchronizes reads" do
|
115
|
-
expect(SimpleCov::ResultMerger).to receive(:synchronize_resultset)
|
116
|
-
SimpleCov::ResultMerger.resultset
|
117
|
-
end
|
118
|
-
end
|
119
|
-
|
120
|
-
describe ".synchronize_resultset" do
|
121
|
-
it "is reentrant (i.e. doesn't block its own process)" do
|
122
|
-
# without @resultset_locked, this spec would fail and
|
123
|
-
# `.store_result` wouldn't work
|
124
|
-
expect do
|
125
|
-
Timeout.timeout(1) do
|
126
|
-
SimpleCov::ResultMerger.synchronize_resultset do
|
127
|
-
SimpleCov::ResultMerger.synchronize_resultset do
|
128
|
-
end
|
129
|
-
end
|
130
|
-
end
|
131
|
-
end.not_to raise_error
|
132
|
-
end
|
133
|
-
|
134
|
-
it "blocks other processes" do
|
135
|
-
file = Tempfile.new("foo")
|
136
|
-
|
137
|
-
other_process = open("|ruby -e " + Shellwords.escape(<<-CODE) + " 2>/dev/null")
|
138
|
-
require "simplecov"
|
139
|
-
SimpleCov.coverage_dir(#{SimpleCov.coverage_dir.inspect})
|
140
|
-
|
141
|
-
# ensure the parent process has enough time to get a
|
142
|
-
# lock before we do
|
143
|
-
sleep 0.5
|
144
|
-
|
145
|
-
$stdout.sync = true
|
146
|
-
puts "running" # see `sleep`s in parent process
|
147
|
-
|
148
|
-
SimpleCov::ResultMerger.synchronize_resultset do
|
149
|
-
File.open(#{file.path.inspect}, "a") { |f| f.write("process 2\n") }
|
150
|
-
end
|
151
|
-
CODE
|
152
|
-
|
153
|
-
SimpleCov::ResultMerger.synchronize_resultset do
|
154
|
-
# wait until the child process is going, and then wait some more
|
155
|
-
# so we can be sure it blocks on the lock we already have.
|
156
|
-
sleep 0.1 until other_process.gets == "running\n"
|
157
|
-
sleep 1
|
158
|
-
|
159
|
-
# despite the sleeps, this will be written first since we got
|
160
|
-
# the first lock
|
161
|
-
File.open(file.path, "a") { |f| f.write("process 1\n") }
|
162
|
-
end
|
163
|
-
|
164
|
-
# wait for it to finish
|
165
|
-
other_process.gets
|
166
|
-
|
167
|
-
expect(file.read).to eq("process 1\nprocess 2\n")
|
168
|
-
end
|
169
|
-
end
|
170
|
-
end
|
171
|
-
end
|