simplecov 0.14.0 → 0.15.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,10 +1,16 @@
1
1
  require "helper"
2
+ require "tempfile"
3
+ require "timeout"
2
4
 
3
5
  if SimpleCov.usable?
4
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
+
5
12
  describe "with two faked coverage resultsets" do
6
13
  before do
7
- SimpleCov.use_merging true
8
14
  @resultset1 = {
9
15
  source_fixture("sample.rb") => [nil, 1, 1, 1, nil, nil, 1, 1, nil, nil],
10
16
  source_fixture("app/models/user.rb") => [nil, 1, 1, 1, nil, nil, 1, 0, nil, nil],
@@ -56,7 +62,7 @@ if SimpleCov.usable?
56
62
  end
57
63
 
58
64
  it "returns a hash containing keys ['result1' and 'result2'] for resultset" do
59
- expect(SimpleCov::ResultMerger.resultset.keys.sort).to eq %w(result1 result2)
65
+ expect(SimpleCov::ResultMerger.resultset.keys.sort).to eq %w[result1 result2]
60
66
  end
61
67
 
62
68
  it "returns proper values for merged_result" do
@@ -73,15 +79,92 @@ if SimpleCov.usable?
73
79
  expect(SimpleCov::ResultMerger.results.length).to eq(1)
74
80
  end
75
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
76
93
 
77
- context "with merging disabled" do
78
- before { SimpleCov.use_merging false }
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
79
106
 
80
- it "returns nil for SimpleCov.result" do
81
- expect(SimpleCov.result).to be_nil
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
82
129
  end
83
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") }
84
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")
85
168
  end
86
169
  end
87
170
  end
@@ -0,0 +1,109 @@
1
+ require "helper"
2
+
3
+ if SimpleCov.usable?
4
+ describe SimpleCov do
5
+ describe ".result" do
6
+ before do
7
+ SimpleCov.clear_result
8
+ allow(Coverage).to receive(:result).once.and_return({})
9
+ end
10
+
11
+ context "with merging disabled" do
12
+ before do
13
+ allow(SimpleCov).to receive(:use_merging).once.and_return(false)
14
+ end
15
+
16
+ context "when not running" do
17
+ before do
18
+ allow(SimpleCov).to receive(:running).and_return(false)
19
+ end
20
+
21
+ it "returns nil" do
22
+ expect(SimpleCov.result).to be_nil
23
+ end
24
+ end
25
+
26
+ context "when running" do
27
+ before do
28
+ allow(SimpleCov).to receive(:running).and_return(true, false)
29
+ end
30
+
31
+ it "uses the result from Coverage" do
32
+ expect(Coverage).to receive(:result).once.and_return(__FILE__ => [0, 1])
33
+ expect(SimpleCov.result.filenames).to eq [__FILE__]
34
+ end
35
+
36
+ it "adds not-loaded-files" do
37
+ expect(SimpleCov).to receive(:add_not_loaded_files).once.and_return({})
38
+ SimpleCov.result
39
+ end
40
+
41
+ it "doesn't store the current coverage" do
42
+ expect(SimpleCov::ResultMerger).not_to receive(:store_result)
43
+ SimpleCov.result
44
+ end
45
+
46
+ it "doesn't merge the result" do
47
+ expect(SimpleCov::ResultMerger).not_to receive(:merged_result)
48
+ SimpleCov.result
49
+ end
50
+
51
+ it "caches its result" do
52
+ result = SimpleCov.result
53
+ expect(SimpleCov.result).to be(result)
54
+ end
55
+ end
56
+ end
57
+
58
+ context "with merging enabled" do
59
+ let(:the_merged_result) { double }
60
+
61
+ before do
62
+ allow(SimpleCov).to receive(:use_merging).once.and_return(true)
63
+ allow(SimpleCov::ResultMerger).to receive(:store_result).once
64
+ allow(SimpleCov::ResultMerger).to receive(:merged_result).once.and_return(the_merged_result)
65
+ end
66
+
67
+ context "when not running" do
68
+ before do
69
+ allow(SimpleCov).to receive(:running).and_return(false)
70
+ end
71
+
72
+ it "merges the result" do
73
+ expect(SimpleCov.result).to be(the_merged_result)
74
+ end
75
+ end
76
+
77
+ context "when running" do
78
+ before do
79
+ allow(SimpleCov).to receive(:running).and_return(true, false)
80
+ end
81
+
82
+ it "uses the result from Coverage" do
83
+ expect(Coverage).to receive(:result).once.and_return({})
84
+ SimpleCov.result
85
+ end
86
+
87
+ it "adds not-loaded-files" do
88
+ expect(SimpleCov).to receive(:add_not_loaded_files).once.and_return({})
89
+ SimpleCov.result
90
+ end
91
+
92
+ it "stores the current coverage" do
93
+ expect(SimpleCov::ResultMerger).to receive(:store_result).once
94
+ SimpleCov.result
95
+ end
96
+
97
+ it "merges the result" do
98
+ expect(SimpleCov.result).to be(the_merged_result)
99
+ end
100
+
101
+ it "caches its result" do
102
+ result = SimpleCov.result
103
+ expect(SimpleCov.result).to be(result)
104
+ end
105
+ end
106
+ end
107
+ end
108
+ end
109
+ end
@@ -16,6 +16,10 @@ if SimpleCov.usable?
16
16
  expect(subject.src).to eq(subject.source)
17
17
  end
18
18
 
19
+ it "has a project filename which removes the project directory" do
20
+ expect(subject.project_filename).to eq("/spec/fixtures/sample.rb")
21
+ end
22
+
19
23
  it "has source_lines equal to lines" do
20
24
  expect(subject.lines).to eq(subject.source_lines)
21
25
  end
@@ -73,5 +77,69 @@ if SimpleCov.usable?
73
77
  expect(captured_output).to match(/^Warning: coverage data provided/)
74
78
  end
75
79
  end
80
+
81
+ context "a file that is never relevant" do
82
+ COVERAGE_FOR_NEVER_RB = [nil, nil].freeze
83
+
84
+ subject do
85
+ SimpleCov::SourceFile.new(source_fixture("never.rb"), COVERAGE_FOR_NEVER_RB)
86
+ end
87
+
88
+ it "has 0.0 covered_strength" do
89
+ expect(subject.covered_strength).to eq 0.0
90
+ end
91
+
92
+ it "has 0.0 covered_percent" do
93
+ expect(subject.covered_percent).to eq 100.0
94
+ end
95
+ end
96
+
97
+ context "a file where nothing is ever executed mixed with skipping #563" do
98
+ COVERAGE_FOR_SKIPPED_RB = [nil, nil, nil, nil].freeze
99
+
100
+ subject do
101
+ SimpleCov::SourceFile.new(source_fixture("skipped.rb"), COVERAGE_FOR_SKIPPED_RB)
102
+ end
103
+
104
+ it "has 0.0 covered_strength" do
105
+ expect(subject.covered_strength).to eq 0.0
106
+ end
107
+
108
+ it "has 0.0 covered_percent" do
109
+ expect(subject.covered_percent).to eq 0.0
110
+ end
111
+ end
112
+
113
+ context "a file where everything is skipped and missed #563" do
114
+ COVERAGE_FOR_SKIPPED_RB_2 = [nil, nil, 0, nil].freeze
115
+
116
+ subject do
117
+ SimpleCov::SourceFile.new(source_fixture("skipped.rb"), COVERAGE_FOR_SKIPPED_RB_2)
118
+ end
119
+
120
+ it "has 0.0 covered_strength" do
121
+ expect(subject.covered_strength).to eq 0.0
122
+ end
123
+
124
+ it "has 0.0 covered_percent" do
125
+ expect(subject.covered_percent).to eq 0.0
126
+ end
127
+ end
128
+
129
+ context "a file where everything is skipped/irrelevamt but executed #563" do
130
+ COVERAGE_FOR_SKIPPED_AND_EXECUTED_RB = [nil, nil, 1, 1, 0, nil, nil, nil].freeze
131
+
132
+ subject do
133
+ SimpleCov::SourceFile.new(source_fixture("skipped_and_executed.rb"), COVERAGE_FOR_SKIPPED_AND_EXECUTED_RB)
134
+ end
135
+
136
+ it "has 0.0 covered_strength" do
137
+ expect(subject.covered_strength).to eq 0.0
138
+ end
139
+
140
+ it "has 0.0 covered_percent" do
141
+ expect(subject.covered_percent).to eq 0.0
142
+ end
143
+ end
76
144
  end
77
145
  end
metadata CHANGED
@@ -1,17 +1,16 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: simplecov
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.14.0
4
+ version: 0.15.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Christoph Olszowka
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-03-15 00:00:00.000000000 Z
11
+ date: 2017-08-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: json
15
14
  requirement: !ruby/object:Gem::Requirement
16
15
  requirements:
17
16
  - - ">="
@@ -20,8 +19,9 @@ dependencies:
20
19
  - - "<"
21
20
  - !ruby/object:Gem::Version
22
21
  version: '3'
23
- type: :runtime
22
+ name: json
24
23
  prerelease: false
24
+ type: :runtime
25
25
  version_requirements: !ruby/object:Gem::Requirement
26
26
  requirements:
27
27
  - - ">="
@@ -31,42 +31,42 @@ dependencies:
31
31
  - !ruby/object:Gem::Version
32
32
  version: '3'
33
33
  - !ruby/object:Gem::Dependency
34
- name: simplecov-html
35
34
  requirement: !ruby/object:Gem::Requirement
36
35
  requirements:
37
36
  - - "~>"
38
37
  - !ruby/object:Gem::Version
39
38
  version: 0.10.0
40
- type: :runtime
39
+ name: simplecov-html
41
40
  prerelease: false
41
+ type: :runtime
42
42
  version_requirements: !ruby/object:Gem::Requirement
43
43
  requirements:
44
44
  - - "~>"
45
45
  - !ruby/object:Gem::Version
46
46
  version: 0.10.0
47
47
  - !ruby/object:Gem::Dependency
48
- name: docile
49
48
  requirement: !ruby/object:Gem::Requirement
50
49
  requirements:
51
50
  - - "~>"
52
51
  - !ruby/object:Gem::Version
53
52
  version: 1.1.0
54
- type: :runtime
53
+ name: docile
55
54
  prerelease: false
55
+ type: :runtime
56
56
  version_requirements: !ruby/object:Gem::Requirement
57
57
  requirements:
58
58
  - - "~>"
59
59
  - !ruby/object:Gem::Version
60
60
  version: 1.1.0
61
61
  - !ruby/object:Gem::Dependency
62
- name: bundler
63
62
  requirement: !ruby/object:Gem::Requirement
64
63
  requirements:
65
64
  - - "~>"
66
65
  - !ruby/object:Gem::Version
67
66
  version: '1.9'
68
- type: :development
67
+ name: bundler
69
68
  prerelease: false
69
+ type: :development
70
70
  version_requirements: !ruby/object:Gem::Requirement
71
71
  requirements:
72
72
  - - "~>"
@@ -106,6 +106,7 @@ files:
106
106
  - features/config_project_name.feature
107
107
  - features/config_styles.feature
108
108
  - features/config_tracked_files.feature
109
+ - features/config_tracked_files_relevant_lines.feature
109
110
  - features/cucumber_basic.feature
110
111
  - features/maximum_coverage_drop.feature
111
112
  - features/merging_test_unit_and_rspec.feature
@@ -122,6 +123,7 @@ files:
122
123
  - features/step_definitions/simplecov_steps.rb
123
124
  - features/step_definitions/transformers.rb
124
125
  - features/step_definitions/web_steps.rb
126
+ - features/support/aruba_freedom_patch.rb
125
127
  - features/support/env.rb
126
128
  - features/test_unit_basic.feature
127
129
  - features/test_unit_groups_and_filters_basic.feature
@@ -141,6 +143,7 @@ files:
141
143
  - lib/simplecov/formatter/simple_formatter.rb
142
144
  - lib/simplecov/jruby_fix.rb
143
145
  - lib/simplecov/last_run.rb
146
+ - lib/simplecov/lines_classifier.rb
144
147
  - lib/simplecov/load_global_config.rb
145
148
  - lib/simplecov/no_defaults.rb
146
149
  - lib/simplecov/profiles.rb
@@ -187,17 +190,22 @@ files:
187
190
  - spec/fixtures/frameworks/testunit_bad.rb
188
191
  - spec/fixtures/frameworks/testunit_good.rb
189
192
  - spec/fixtures/iso-8859.rb
193
+ - spec/fixtures/never.rb
190
194
  - spec/fixtures/resultset1.rb
191
195
  - spec/fixtures/resultset2.rb
192
196
  - spec/fixtures/sample.rb
197
+ - spec/fixtures/skipped.rb
198
+ - spec/fixtures/skipped_and_executed.rb
193
199
  - spec/fixtures/utf-8.rb
194
200
  - spec/helper.rb
195
201
  - spec/last_run_spec.rb
202
+ - spec/lines_classifier_spec.rb
196
203
  - spec/multi_formatter_spec.rb
197
204
  - spec/raw_coverage_spec.rb
198
205
  - spec/result_merger_spec.rb
199
206
  - spec/result_spec.rb
200
207
  - spec/return_codes_spec.rb
208
+ - spec/simplecov_spec.rb
201
209
  - spec/source_file_line_spec.rb
202
210
  - spec/source_file_spec.rb
203
211
  - spec/support/fail_rspec_on_ruby_warning.rb
@@ -205,7 +213,7 @@ homepage: http://github.com/colszowka/simplecov
205
213
  licenses:
206
214
  - MIT
207
215
  metadata: {}
208
- post_install_message:
216
+ post_install_message:
209
217
  rdoc_options: []
210
218
  require_paths:
211
219
  - lib
@@ -220,9 +228,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
220
228
  - !ruby/object:Gem::Version
221
229
  version: '0'
222
230
  requirements: []
223
- rubyforge_project:
224
- rubygems_version: 2.6.10
225
- signing_key:
231
+ rubyforge_project:
232
+ rubygems_version: 2.6.11
233
+ signing_key:
226
234
  specification_version: 4
227
235
  summary: Code coverage for Ruby 1.9+ with a powerful configuration library and automatic
228
236
  merging of coverage across test suites