simplecov 0.18.2 → 0.18.3

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: 8e154e20c4783b0bf086268b9ef996f2137e62db61e383ccb68e271b22e6ebb6
4
+ data.tar.gz: b14b1151d5935267924bafa9abf436b1aa070bbd4839215abf883afa238f6fea
5
5
  SHA512:
6
- metadata.gz: e5e84c5ca4337bba395afb5ccb44923eaee46294c6116eb8ec15890b1f13500f5a56b117999e5aaacb89fcea1fa012133306d8943530c6e3b96976682511ac77
7
- data.tar.gz: 4af3b7f1df63df9103989cb951efdca6cecf35c99c02176ad0b3b29aa42828b98e031ef683864bc3e00cf6f699da285b4c8eb6f39a68149832abdcd98943506a
6
+ metadata.gz: b5c87c16a29b4d6682f2dfeb4a24ce4027751c70fd7594c0651b1b66b5db2c274d458569d9342cdc7a7a03c5b52d5fd7261396748988a16bf23976d850bc7b12
7
+ data.tar.gz: 87192405c9cf26f88bd59e609322ea8d7516174a22d99de2578e65ee5c916687ef09b0f5fdf7504dee2a58787319c47205a7b9a8286715d97e73917580238114
@@ -1,3 +1,12 @@
1
+ 0.18.3 (2020-02-23)
2
+ ===========
3
+
4
+ Small bugfix release. It's especially recommended to upgrade simplecov-html as well because of bugs in the 0.12.0 release.
5
+
6
+ ## Bugfixes
7
+ * 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)
8
+ * 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))
9
+
1
10
  0.18.2 (2020-02-12)
2
11
  ===================
3
12
 
@@ -0,0 +1,11 @@
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
+ Minitest.after_run do
8
+ SimpleCov.at_exit_behavior if SimpleCov.respond_to?(:at_exit_behavior)
9
+ end
10
+ end
11
+ end
@@ -189,6 +189,14 @@ module SimpleCov
189
189
  end
190
190
  end
191
191
 
192
+ def at_exit_behavior
193
+ # If we are in a different process than called start, don't interfere.
194
+ return if SimpleCov.pid != Process.pid
195
+
196
+ # If SimpleCov is no longer running then don't run exit tasks
197
+ SimpleCov.run_exit_tasks! if SimpleCov.running
198
+ end
199
+
192
200
  # @api private
193
201
  #
194
202
  # Called from at_exit block
@@ -22,13 +22,10 @@ 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
+ # Exit hook for Minitest defined in Minitest plugin
26
+ next if defined?(Minitest)
27
27
 
28
- # If SimpleCov is no longer running then don't run exit tasks
29
- next unless SimpleCov.running
30
-
31
- SimpleCov.run_exit_tasks!
28
+ SimpleCov.at_exit_behavior
32
29
  end
33
30
 
34
31
  # 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.3"
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.3
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-23 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.3
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.3
102
103
  post_install_message:
103
104
  rdoc_options: []
104
105
  require_paths: