simplecov 0.18.2 → 0.18.5

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: 390d8182b24adbf82eaa93b222027107b09efc8f490ab2ea7db5dce03eeaf9b8
4
- data.tar.gz: 7fad5ea78a2dc6a9a0e84caac8432db30cd475fcf6b08fe135aeee099bee46a7
3
+ metadata.gz: 3d8b7307fd45fc7c4079efec764ee740fd7c0d302b8b78e969b11a08a2c94027
4
+ data.tar.gz: 4a39c982bdc16b038c8d4ff88e25498d34b3bf0a1eec6ed99ed2e444a0e5ada7
5
5
  SHA512:
6
- metadata.gz: e5e84c5ca4337bba395afb5ccb44923eaee46294c6116eb8ec15890b1f13500f5a56b117999e5aaacb89fcea1fa012133306d8943530c6e3b96976682511ac77
7
- data.tar.gz: 4af3b7f1df63df9103989cb951efdca6cecf35c99c02176ad0b3b29aa42828b98e031ef683864bc3e00cf6f699da285b4c8eb6f39a68149832abdcd98943506a
6
+ metadata.gz: e7ce525f98807869dcfafa47e154aafa8047fe8e41685cab5d051400e615b056ee5629a0e18e0203f01af675761be3a57a413d9d4f8eb6a57b4260f4a6db6986
7
+ data.tar.gz: 3a0cc93b7ade626e432238d9ebc18514cbad27d6ea67fbd995c19a4cd40afe6c86486396531110f5f11e29cf65fad6dc81479ef9fdd68304f982257b05abf103
data/CHANGELOG.md CHANGED
@@ -1,3 +1,29 @@
1
+ 0.18.5 (2020-02-25)
2
+ ===================
3
+
4
+ Can you guess? Another bugfix release!
5
+
6
+ ## Bugfixes
7
+ * minitest won't crash if SimpleCov isn't loaded - aka don't execute SimpleCov code in the minitest plugin if SimpleCov isn't loaded. Thanks to [@edariedl](https://github.com/edariedl) for the report of the peculiar problem in [#877](https://github.com/colszowka/simplecov/issues/877).
8
+
9
+ 0.18.4 (2020-02-24)
10
+ ===================
11
+
12
+ Another small bugfix release 🙈 Fixes SimpleCov running with rspec-rails, which was broken due to our fixed minitest integration.
13
+
14
+ ## Bugfixes
15
+ * SimpleCov will run again correctly when used with rspec-rails. The excellent bug report [#873](https://github.com/colszowka/simplecov/issues/873) by [@odlp](https://github.com/odlp) perfectly details what went wrong. Thanks to [@adam12](https://github.com/adam12) for the fix [#874](https://github.com/colszowka/simplecov/pull/874).
16
+
17
+
18
+ 0.18.3 (2020-02-23)
19
+ ===========
20
+
21
+ Small bugfix release. It's especially recommended to upgrade simplecov-html as well because of bugs in the 0.12.0 release.
22
+
23
+ ## Bugfixes
24
+ * Fix a regression related to file encodings as special characters were missing. Furthermore we now respect the magic `# encoding: ...` comment and read files in the right encoding. Thanks ([@Tietew](https://github.com/Tietew)) - see [#866](https://github.com/colszowka/simplecov/pull/866)
25
+ * Use `Minitest.after_run` hook to trigger post-run hooks if `Minitest` is present. See [#756](https://github.com/colszowka/simplecov/pull/756) and [#855](https://github.com/colszowka/simplecov/pull/855) thanks ([@adam12](https://github.com/adam12))
26
+
1
27
  0.18.2 (2020-02-12)
2
28
  ===================
3
29
 
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ # How minitest plugins. See https://github.com/colszowka/simplecov/pull/756 for why we need this.
4
+ # https://github.com/seattlerb/minitest#writing-extensions
5
+ module Minitest
6
+ def self.plugin_simplecov_init(_options)
7
+ if defined?(SimpleCov)
8
+ SimpleCov.external_at_exit = true
9
+
10
+ Minitest.after_run do
11
+ SimpleCov.at_exit_behavior
12
+ end
13
+ end
14
+ end
15
+ end
data/lib/simplecov.rb CHANGED
@@ -27,6 +27,11 @@ module SimpleCov
27
27
  attr_accessor :pid
28
28
  attr_reader :exit_exception
29
29
 
30
+ # Basically, should we take care of at_exit behavior or something else?
31
+ # Used by the minitest plugin. See lib/minitest/simplecov_plugin.rb
32
+ attr_accessor :external_at_exit
33
+ alias external_at_exit? external_at_exit
34
+
30
35
  #
31
36
  # Sets up SimpleCov to run against your project.
32
37
  # You can optionally specify a profile to use as well as configuration with a block:
@@ -189,6 +194,14 @@ module SimpleCov
189
194
  end
190
195
  end
191
196
 
197
+ def at_exit_behavior
198
+ # If we are in a different process than called start, don't interfere.
199
+ return if SimpleCov.pid != Process.pid
200
+
201
+ # If SimpleCov is no longer running then don't run exit tasks
202
+ SimpleCov.run_exit_tasks! if SimpleCov.running
203
+ end
204
+
192
205
  # @api private
193
206
  #
194
207
  # Called from at_exit block
@@ -22,13 +22,9 @@ end
22
22
  SimpleCov::CommandGuesser.original_run_command = "#{$PROGRAM_NAME} #{ARGV.join(' ')}"
23
23
 
24
24
  at_exit do
25
- # If we are in a different process than called start, don't interfere.
26
- next if SimpleCov.pid != Process.pid
25
+ next if SimpleCov.external_at_exit?
27
26
 
28
- # If SimpleCov is no longer running then don't run exit tasks
29
- next unless SimpleCov.running
30
-
31
- SimpleCov.run_exit_tasks!
27
+ SimpleCov.at_exit_behavior
32
28
  end
33
29
 
34
30
  # Autoload config from ~/.simplecov if present
@@ -25,7 +25,7 @@ module SimpleCov
25
25
  def src
26
26
  # We intentionally read source code lazily to
27
27
  # suppress reading unused source code.
28
- @src ||= File.open(filename, "rb", &:readlines)
28
+ @src ||= load_source
29
29
  end
30
30
  alias source src
31
31
 
@@ -175,6 +175,51 @@ module SimpleCov
175
175
  end
176
176
  end
177
177
 
178
+ def load_source
179
+ lines = []
180
+ # The default encoding is UTF-8
181
+ File.open(filename, "rb:UTF-8") do |file|
182
+ current_line = file.gets
183
+
184
+ if shebang?(current_line)
185
+ lines << current_line
186
+ current_line = file.gets
187
+ end
188
+
189
+ read_lines(file, lines, current_line)
190
+ end
191
+ end
192
+
193
+ SHEBANG_REGEX = /\A#!/.freeze
194
+ def shebang?(line)
195
+ SHEBANG_REGEX.match?(line)
196
+ end
197
+
198
+ def read_lines(file, lines, current_line)
199
+ return lines unless current_line
200
+
201
+ set_encoding_based_on_magic_comment(file, current_line)
202
+ lines.concat([current_line], ensure_remove_undefs(file.readlines))
203
+ end
204
+
205
+ RUBY_FILE_ENCODING_MAGIC_COMMENT_REGEX = /\A#\s*(?:-\*-)?\s*(?:en)?coding:\s*(\S+)\s*(?:-\*-)?\s*\z/.freeze
206
+ def set_encoding_based_on_magic_comment(file, line)
207
+ # Check for encoding magic comment
208
+ # Encoding magic comment must be placed at first line except for shebang
209
+ if (match = RUBY_FILE_ENCODING_MAGIC_COMMENT_REGEX.match(line))
210
+ file.set_encoding(match[1], "UTF-8")
211
+ end
212
+ end
213
+
214
+ def ensure_remove_undefs(file_lines)
215
+ # invalid/undef replace are technically not really necessary but nice to
216
+ # have and work around a JRuby incompatibility. Also moved here from
217
+ # simplecov-html to have encoding shenaningans in one place. See #866
218
+ # also setting these option on `file.set_encoding` doesn't seem to work
219
+ # properly so it has to be done here.
220
+ file_lines.each { |line| line.encode!("UTF-8", invalid: :replace, undef: :replace) }
221
+ end
222
+
178
223
  def build_lines
179
224
  coverage_exceeding_source_warn if coverage_data["lines"].size > src.size
180
225
  lines = src.map.with_index(1) do |src, i|
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module SimpleCov
4
- VERSION = "0.18.2"
4
+ VERSION = "0.18.5"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: simplecov
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.18.2
4
+ version: 0.18.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Christoph Olszowka
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-02-12 00:00:00.000000000 Z
11
+ date: 2020-02-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: docile
@@ -55,6 +55,7 @@ files:
55
55
  - doc/alternate-formatters.md
56
56
  - doc/commercial-services.md
57
57
  - doc/editor-integration.md
58
+ - lib/minitest/simplecov_plugin.rb
58
59
  - lib/simplecov.rb
59
60
  - lib/simplecov/combine.rb
60
61
  - lib/simplecov/combine/branches_combiner.rb
@@ -96,9 +97,9 @@ licenses:
96
97
  metadata:
97
98
  bug_tracker_uri: https://github.com/colszowka/simplecov/issues
98
99
  changelog_uri: https://github.com/colszowka/simplecov/blob/master/CHANGELOG.md
99
- documentation_uri: https://www.rubydoc.info/gems/simplecov/0.18.2
100
+ documentation_uri: https://www.rubydoc.info/gems/simplecov/0.18.5
100
101
  mailing_list_uri: https://groups.google.com/forum/#!forum/simplecov
101
- source_code_uri: https://github.com/colszowka/simplecov/tree/v0.18.2
102
+ source_code_uri: https://github.com/colszowka/simplecov/tree/v0.18.5
102
103
  post_install_message:
103
104
  rdoc_options: []
104
105
  require_paths: