simplecov 0.21.1 → 0.22.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: afc0e78d256ce0dd4b33c55efb46a4463f31b72a6dcaefea8dba983ba366f7ba
4
- data.tar.gz: d0c17198c79fe4e85ec21497355e618048637595b00fbecf180ab61815e75c65
3
+ metadata.gz: 53fa0b46a6da5abd78be052c332c7bc956bb9a432e929965f1cfd460d637c21d
4
+ data.tar.gz: 714c61ef2abd25f9fc78e0f56681811eb571904c9348775acf5b7b13ad002dfe
5
5
  SHA512:
6
- metadata.gz: b6cd1717e5c3a639b6f4392e4067625d700aa9732c56898f3be5d9bf9c633715455efaecaf421e53e6c4c734756992ac623ba341a2b78fdc30d0ec56ed27e76f
7
- data.tar.gz: c031ee7dfe0317d5e6536fb4cf393a8bf3dca3c691bb4ab3240678a253a6f514bccf544a0767291959d671581329399f6e1993ead0660fa5875980e6c0862114
6
+ metadata.gz: f2e715ac3b3067755b2f32981359736cbb5335606b83e84523b03b37d93804d39bbd1f40099d78058d21dad038623911eb031d672fbad97f1fdaa292b2c3652b
7
+ data.tar.gz: 9155c02eba7b6389c8e19de0c28a2b78017999ca404cadfbaa3cde1ee2012e0420d86471af81b0ced38dedef26bde60e7130fb86965fbb4021663fbb75c96554
data/CHANGELOG.md CHANGED
@@ -1,3 +1,21 @@
1
+ 0.22.0 (2022-12-23)
2
+ ==========
3
+
4
+ ## Enhancements
5
+
6
+ * On Ruby 3.2+, you can now use the new Coverage library feature for `eval` - See https://github.com/simplecov-ruby/simplecov/pull/1037. Thanks [@mame](https://github.com/mame)!
7
+
8
+ ## Bugfixes
9
+ * Fix for making the test suite pass against the upcoming Ruby 3.2 - See https://github.com/simplecov-ruby/simplecov/pull/1035. Thanks [@mame](https://github.com/mame)
10
+
11
+ 0.21.2 (2021-01-09)
12
+ ==========
13
+
14
+ ## Bugfixes
15
+ * `maximum_coverage_drop` won't fail any more if `.last_run.json` is still in the old format. Thanks [@petertellgren](https://github.com/petertellgren)
16
+ * `maximum_coverage_drop` won't fail if an expectation is specified for a previous unrecorded criterion, it will just pass (there's nothing, so nothing to drop)
17
+ * fixed bug in `maximum_coverage_drop` calculation that could falsely report it had dropped for minimal differences
18
+
1
19
  0.21.1 (2021-01-04)
2
20
  ==========
3
21
 
data/README.md CHANGED
@@ -69,6 +69,8 @@ Getting started
69
69
  The `SimpleCov.start` **must** be issued **before any of your application
70
70
  code is required!**
71
71
 
72
+ This is especially true if you use anything that keeps your tests application loaded like spring, check out the **[spring section](#want-to-use-spring-with-simplecov)**.
73
+
72
74
  SimpleCov must be running in the process that you want the code coverage
73
75
  analysis to happen on. When testing a server process (e.g. a JSON API
74
76
  endpoint) via a separate test process (e.g. when using Selenium) where you
@@ -105,10 +107,6 @@ Getting started
105
107
  5. Add the following to your `.gitignore` file to ensure that coverage results
106
108
  are not tracked by Git (optional):
107
109
 
108
- ```
109
- echo "coverage" >> .gitignore
110
- ```
111
- Or if you use Windows:
112
110
  ```
113
111
  echo coverage >> .gitignore
114
112
  ```
@@ -356,6 +354,18 @@ Primary coverage determines what will come in first all output, and the type of
356
354
 
357
355
  Note that coverage must first be enabled for non-default coverage types.
358
356
 
357
+ ## Coverage for eval
358
+
359
+ You can measure coverage for code that is evaluated by `Kernel#eval`. Supported in CRuby versions 3.2+.
360
+
361
+ ```ruby
362
+ SimpleCov.start do
363
+ enable_coverage_for_eval
364
+ end
365
+ ```
366
+
367
+ This is typically useful for ERB. Set `ERB#filename=` to make it possible for SimpleCov to trace the original .erb source file.
368
+
359
369
  ## Filters
360
370
 
361
371
  Filters can be used to remove selected files from your coverage data. By default, a filter is applied that removes all
@@ -840,15 +850,17 @@ You can use your own formatter with:
840
850
  SimpleCov.formatter = SimpleCov::Formatter::HTMLFormatter
841
851
  ```
842
852
 
843
- When calling SimpleCov.result.format!, it will be invoked with SimpleCov::Formatter::YourFormatter.new.format(result),
844
- "result" being an instance of SimpleCov::Result. Do whatever your wish with that!
853
+ Calling `SimpleCov.result.format!` will be invoked with `SimpleCov::Formatter::YourFormatter.new.format(result)`,
854
+ and `result` is an instance of `SimpleCov::Result`. Do whatever your wish with that!
845
855
 
846
856
 
847
857
  ## Using multiple formatters
848
858
 
849
- As of SimpleCov 0.9, you can specify multiple result formats:
859
+ As of SimpleCov 0.9, you can specify multiple result formats. Formatters besides the default HTML formatter require separate gems, however.
850
860
 
851
861
  ```ruby
862
+ require "simplecov-html"
863
+
852
864
  SimpleCov.formatters = SimpleCov::Formatter::MultiFormatter.new([
853
865
  SimpleCov::Formatter::HTMLFormatter,
854
866
  SimpleCov::Formatter::CSVFormatter,
@@ -877,7 +889,7 @@ SimpleCov.formatter = SimpleCov::Formatter::JSONFormatter
877
889
 
878
890
  ## Ruby version compatibility
879
891
 
880
- SimpleCov is built in [Continuous Integration] on Ruby 2.5+ as well as JRuby 9.2+.
892
+ SimpleCov is built in [Continuous Integration] on Ruby 2.7+ as well as JRuby 9.3+.
881
893
 
882
894
  Note for JRuby => You need to pass JRUBY_OPTS="--debug" or create .jrubyrc and add debug.fullTrace=true
883
895
 
@@ -440,7 +440,26 @@ module SimpleCov
440
440
  end
441
441
  end
442
442
 
443
- alias branch_coverage_supported? coverage_start_arguments_supported?
443
+ def branch_coverage_supported?
444
+ coverage_start_arguments_supported? && RUBY_ENGINE != "jruby"
445
+ end
446
+
447
+ def coverage_for_eval_supported?
448
+ require "coverage"
449
+ defined?(Coverage.supported?) && Coverage.supported?(:eval)
450
+ end
451
+
452
+ def coverage_for_eval_enabled?
453
+ @coverage_for_eval_enabled ||= false
454
+ end
455
+
456
+ def enable_coverage_for_eval
457
+ if coverage_for_eval_supported?
458
+ @coverage_for_eval_enabled = true
459
+ else
460
+ warn "Coverage for eval is not available; Use Ruby 3.2.0 or later"
461
+ end
462
+ end
444
463
 
445
464
  private
446
465
 
@@ -51,22 +51,32 @@ module SimpleCov
51
51
  {
52
52
  criterion: criterion,
53
53
  max_drop: percent,
54
- drop_percent: last_coverage(criterion) -
55
- SimpleCov.round_coverage(
56
- result.coverage_statistics.fetch(criterion).percent
57
- )
54
+ drop_percent: drop_percent(criterion)
58
55
  }
59
56
  end
60
57
  end
61
58
 
59
+ # if anyone says "max_coverage_drop 0.000000000000000001" I appologize. Please don't.
60
+ MAX_DROP_ACCURACY = 10
61
+ def drop_percent(criterion)
62
+ drop = last_coverage(criterion) -
63
+ SimpleCov.round_coverage(
64
+ result.coverage_statistics.fetch(criterion).percent
65
+ )
66
+
67
+ # floats, I tell ya.
68
+ # irb(main):001:0* 80.01 - 80.0
69
+ # => 0.010000000000005116
70
+ drop.floor(MAX_DROP_ACCURACY)
71
+ end
72
+
62
73
  def last_coverage(criterion)
63
74
  last_coverage_percent = last_run[:result][criterion]
64
75
 
65
- if !last_coverage_percent && criterion == "line"
66
- last_run[:result][:covered_percent]
67
- else
68
- last_coverage_percent
69
- end
76
+ # fallback for old file format
77
+ last_coverage_percent = last_run[:result][:covered_percent] if !last_coverage_percent && criterion == :line
78
+
79
+ last_coverage_percent || 0
70
80
  end
71
81
  end
72
82
  end
@@ -18,7 +18,7 @@ module SimpleCov
18
18
 
19
19
  # The path to this source file relative to the projects directory
20
20
  def project_filename
21
- @filename.sub(Regexp.new("^#{Regexp.escape(SimpleCov.root)}"), "")
21
+ @filename.delete_prefix(SimpleCov.root)
22
22
  end
23
23
 
24
24
  # The source code for this file. Aliased as :source
@@ -217,7 +217,13 @@ module SimpleCov
217
217
  # simplecov-html to have encoding shenaningans in one place. See #866
218
218
  # also setting these option on `file.set_encoding` doesn't seem to work
219
219
  # properly so it has to be done here.
220
- file_lines.each { |line| line.encode!("UTF-8", invalid: :replace, undef: :replace) }
220
+ file_lines.each do |line|
221
+ if line.encoding == Encoding::UTF_8
222
+ line
223
+ else
224
+ line.encode!("UTF-8", invalid: :replace, undef: :replace)
225
+ end
226
+ end
221
227
  end
222
228
 
223
229
  def build_lines
@@ -238,7 +244,7 @@ module SimpleCov
238
244
  end
239
245
 
240
246
  def lines_strength
241
- lines.map(&:coverage).compact.reduce(:+)
247
+ lines.sum { |line| line.coverage.to_i }
242
248
  end
243
249
 
244
250
  # Warning to identify condition from Issue #56
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module SimpleCov
4
- VERSION = "0.21.1"
4
+ VERSION = "0.22.0"
5
5
  end
data/lib/simplecov.rb CHANGED
@@ -342,7 +342,7 @@ module SimpleCov
342
342
  if coverage_start_arguments_supported?
343
343
  start_coverage_with_criteria
344
344
  else
345
- Coverage.start
345
+ Coverage.start unless Coverage.running?
346
346
  end
347
347
  end
348
348
 
@@ -351,7 +351,9 @@ module SimpleCov
351
351
  [lookup_corresponding_ruby_coverage_name(criterion), true]
352
352
  end.to_h
353
353
 
354
- Coverage.start(start_arguments)
354
+ start_arguments[:eval] = true if coverage_for_eval_enabled?
355
+
356
+ Coverage.start(start_arguments) unless Coverage.running?
355
357
  end
356
358
 
357
359
  CRITERION_TO_RUBY_COVERAGE = {
metadata CHANGED
@@ -1,15 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: simplecov
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.21.1
4
+ version: 0.22.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Christoph Olszowka
8
8
  - Tobias Pfeiffer
9
- autorequire:
9
+ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2021-01-04 00:00:00.000000000 Z
12
+ date: 2022-12-23 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: docile
@@ -116,10 +116,10 @@ licenses:
116
116
  metadata:
117
117
  bug_tracker_uri: https://github.com/simplecov-ruby/simplecov/issues
118
118
  changelog_uri: https://github.com/simplecov-ruby/simplecov/blob/main/CHANGELOG.md
119
- documentation_uri: https://www.rubydoc.info/gems/simplecov/0.21.1
119
+ documentation_uri: https://www.rubydoc.info/gems/simplecov/0.22.0
120
120
  mailing_list_uri: https://groups.google.com/forum/#!forum/simplecov
121
- source_code_uri: https://github.com/simplecov-ruby/simplecov/tree/v0.21.1
122
- post_install_message:
121
+ source_code_uri: https://github.com/simplecov-ruby/simplecov/tree/v0.22.0
122
+ post_install_message:
123
123
  rdoc_options: []
124
124
  require_paths:
125
125
  - lib
@@ -134,8 +134,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
134
134
  - !ruby/object:Gem::Version
135
135
  version: '0'
136
136
  requirements: []
137
- rubygems_version: 3.2.3
138
- signing_key:
137
+ rubygems_version: 3.3.7
138
+ signing_key:
139
139
  specification_version: 4
140
140
  summary: Code coverage for Ruby
141
141
  test_files: []