single_cov 2.2.0 → 2.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 12be958e8135fecd7c8e8dc446b97cae5dd0a7d1397c33ea851cffdeb7389ee0
4
- data.tar.gz: 315153f27ef5c680a52584c95e28d96904b10c3c9a094d5e19b06ebac66dbfc1
3
+ metadata.gz: 0b02d2e0301ceb4d611d5b5d543f3715971f69a44b5ba200a47c9f705dc013e1
4
+ data.tar.gz: 6a916a1ff4b8232e7132e731b92b157e500537c0c324489e4e10df52ba49a54c
5
5
  SHA512:
6
- metadata.gz: e3c97161e9ef85134dd6456b5e4ee75c0c9f0c5fe238f64bb5fbf9b9551e3773833f00ace1f567e4071e33f95d0b85fb79d0841765e1b2ddac83cd9a70ada3a9
7
- data.tar.gz: 3bbf1d85f580c4affb6672c5d8b5ac4523b896379b282146484d7199ff9fb79263c96b692b22edd47b5bdd32269a3ac547ea67e4b48d38d32e5ff4956519406b
6
+ metadata.gz: 905ea1116dfa415a892cbddfbc1b67ffcefd113036b491c544589be016a13ae6264ffe2ff4a5d335db7f91e62661639b62855d5f0c276ace4789aa92b468e110
7
+ data.tar.gz: 16161caf77b469e861b82852ca3b87ec0a7f45b443c1dc2b093cb4180c892be1bf2d3409448d2574d3d4567c20061947ea1d730a476a17fcb3e14c91ef41bd0f
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  module SingleCov
3
- VERSION = "2.2.0"
3
+ VERSION = "2.3.0"
4
4
  end
data/lib/single_cov.rb CHANGED
@@ -10,6 +10,16 @@ module SingleCov
10
10
  SIMPLECOV_ENABLE_BLOCK_MARKER = /^\s*#\s*simplecov:enable\b/
11
11
  PREFIXES_TO_IGNORE = [] # things to not prefix with lib/ etc
12
12
 
13
+ # fails the minitest run when coverage is missing
14
+ module MinitestReporter
15
+ attr_writer :single_cov_options
16
+
17
+ # minitest only calls this once all tests finished, so interrupted runs are not reported
18
+ def passed?
19
+ super && SingleCov.send(:minitest_report_passed?, @single_cov_options)
20
+ end
21
+ end
22
+
13
23
  class << self
14
24
  # enable coverage reporting: path to output file, changed by forking-test-runner at runtime to combine many reports
15
25
  attr_accessor :coverage_report
@@ -127,7 +137,7 @@ module SingleCov
127
137
 
128
138
  case framework
129
139
  when :minitest
130
- return if minitest_running_subset_of_tests?(ARGV)
140
+ return if minitest_running_subset_of_tests?(ARGV, {})
131
141
  when :rspec
132
142
  return if rspec_running_subset_of_tests?
133
143
  else
@@ -138,17 +148,13 @@ module SingleCov
138
148
 
139
149
  # minitest overrides at_exit, so we need to get into it to execute after it finishes
140
150
  # so when using the `minitest` executable or loading minitest before SingleCov the first branch is used
141
- if defined?(Minitest)
142
- (class << Minitest; self; end).prepend(Module.new do
143
- def run(args = [])
144
- original_args = args.dup # minitest modified them
145
- result = super
146
- if result && !SingleCov.send(:minitest_running_subset_of_tests?, original_args)
147
- return SingleCov.report_at_exit
148
- end
149
- result
150
- end
151
- end)
151
+ if framework == :minitest && defined?(Minitest)
152
+ # a plugin since setup can run inside of Minitest.run (rails 8.1+ loads tests in process_args)
153
+ Minitest.extensions |= ["single_cov"]
154
+ def Minitest.plugin_single_cov_init(options)
155
+ # override passed? on the composite since plugins like minitest-reporters replace its reporters
156
+ reporter.extend(SingleCov::MinitestReporter).single_cov_options = options
157
+ end
152
158
  else
153
159
  override_at_exit do |status, _exception|
154
160
  if main_process? && status == 0 && !report_at_exit
@@ -280,8 +286,18 @@ module SingleCov
280
286
  COVERAGES.size == 1
281
287
  end
282
288
 
289
+ # @return [Boolean] false when coverage is missing
290
+ def minitest_report_passed?(options)
291
+ return true if minitest_running_subset_of_tests?(options[:args].to_s.split, options)
292
+
293
+ report_at_exit != false # nil when disabled
294
+ end
295
+
283
296
  # do not record or verify when only running selected tests since it would be missing data
284
- def minitest_running_subset_of_tests?(argv)
297
+ def minitest_running_subset_of_tests?(argv, options)
298
+ # via parsed options: -n is :filter in MT 5 or :include in MT 6, -e is :exclude
299
+ options[:filter] || options[:include] || options[:exclude] ||
300
+
285
301
  # via direct option (ruby test.rb -n /foo/)
286
302
  # or `minitest foo.rb:123` which is translated to -n
287
303
  argv.map { |a| a.split('=', 2).first }.intersect?(['-n', '--name', '-l', '--line']) ||
@@ -295,6 +311,12 @@ module SingleCov
295
311
  Minitest.reporter &&
296
312
  (reporter = Minitest.reporter.reporters.first) &&
297
313
  (reporter.options[:filter] || reporter.options[:include]) # MT 5 vs MT 6
314
+ ) ||
315
+
316
+ # via rails 8.1+ test with line numbers, which rails filters itself
317
+ (
318
+ defined?(Rails::TestUnit::Runner) &&
319
+ Rails::TestUnit::Runner.filters.any? { |_file, lines| lines.any? }
298
320
  )
299
321
  end
300
322
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: single_cov
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.2.0
4
+ version: 2.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Grosser