fast_cov 0.5.0 → 0.6.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: f05621dfa93b2807fd7060732bd323ddd407e9af1d80b0857d5d50d6c8667a24
4
- data.tar.gz: f0cc0a9afd99fddac4e0cc263c0dc5edefb373e5da1b145f12148c2a3640aa39
3
+ metadata.gz: dfbb83e455b2aa5e3c11f705b2358bc38e881b773ee6cf0598b0daee551b4669
4
+ data.tar.gz: f9baa9d8f6f38d45741328b99872307cce4097011a8091ac4f6157db20729d14
5
5
  SHA512:
6
- metadata.gz: 8736b3e941eb96518a55ff674429610cb429e790a4fcf67a808d5b5830d3f5110ce443ab18a8e15b657a74a4f3f69734121c8bb924b14b93f0b12eddc00745b2
7
- data.tar.gz: cc856dc60b6d55b534982b1cb83e6bbf8f5b699ff7f1bbd39b9f96749a119261880ec010243a72cbddb00c535a6e47bd0582546a5288ea6370bfa89a43eea582
6
+ metadata.gz: 6675501c274f8a683af895ecd898e8e0dae5600fb8c9197d00cb46a5db9716890d0e0f30f091b03bc191e4a5a04d86389a87ae236049d18fea7a0f3300f78b1d
7
+ data.tar.gz: 882bf56b3d468460ce276ddf90e4ecdbe24293420360bf028088ac5283a077f0dd3af85e472c1e70ff6047a956a4feccb2bd6098bb659a9800a555444f5ac174
data/README.md CHANGED
@@ -83,7 +83,7 @@ Native line coverage is always enabled. Extra trackers registered with `use` are
83
83
 
84
84
  ### FileTracker
85
85
 
86
- Tracks files read from disk during coverage, including YAML, JSON, ERB templates, and any file accessed via `File.read`, read-mode `File.open`, `YAML.load_file`, `YAML.safe_load_file`, or `YAML.unsafe_load_file`.
86
+ Tracks files read from disk during coverage, including YAML, JSON, ERB templates, and any file accessed via `read`, `binread`, `readlines` or `foreach` (on `File` or `IO`), read-mode `File.open` or `File.new`, `YAML.load_file`, `YAML.safe_load_file`, or `YAML.unsafe_load_file`.
87
87
 
88
88
  The YAML methods are patched directly to handle Bootsnap's compile cache, which bypasses `File.open` for YAML files.
89
89
 
@@ -4,7 +4,11 @@ require_relative "abstract_tracker"
4
4
 
5
5
  module FastCov
6
6
  # Tracks files read from disk during coverage (JSON, YAML, .rb templates, etc.)
7
- # via File.read, File.open, and YAML load methods.
7
+ # via the IO read methods (read, binread, readlines, foreach), read-mode
8
+ # File.open and File.new, and YAML load methods.
9
+ #
10
+ # The IO methods are patched on IO itself, and File inherits them, so
11
+ # File.read and IO.read share one patch and a read is recorded once.
8
12
  #
9
13
  # YAML methods are patched separately because Bootsnap's compile cache
10
14
  # overrides YAML.load_file/safe_load_file to bypass File.open entirely.
@@ -12,6 +16,10 @@ module FastCov
12
16
  # Register via: coverage_map.use(FastCov::FileTracker)
13
17
  class FileTracker < AbstractTracker
14
18
  def install
19
+ unless IO.singleton_class.ancestors.include?(IoPatch)
20
+ IO.singleton_class.prepend(IoPatch)
21
+ end
22
+
15
23
  unless File.singleton_class.ancestors.include?(FilePatch)
16
24
  File.singleton_class.prepend(FilePatch)
17
25
  end
@@ -21,44 +29,75 @@ module FastCov
21
29
  end
22
30
  end
23
31
 
32
+ def self.read_mode?(mode)
33
+ mode.nil? || (mode.is_a?(String) && mode.start_with?("r")) ||
34
+ (mode.is_a?(Integer) && (mode & (File::WRONLY | File::RDWR)).zero?)
35
+ end
36
+
24
37
  # The patches are permanent, so each checks active before doing any work.
25
38
  # Paths go over raw because AbstractTracker#record normalizes them.
26
- module FilePatch
27
- def read(name, *args, **kwargs, &block)
28
- super.tap do
29
- FastCov::FileTracker.record(name) if FastCov::FileTracker.active
30
- end
39
+ module IoPatch
40
+ def read(name, ...)
41
+ result = super
42
+ FastCov::FileTracker.record(name) if FastCov::FileTracker.active
43
+ result
44
+ end
45
+
46
+ def binread(name, ...)
47
+ result = super
48
+ FastCov::FileTracker.record(name) if FastCov::FileTracker.active
49
+ result
50
+ end
51
+
52
+ def readlines(name, ...)
53
+ result = super
54
+ FastCov::FileTracker.record(name) if FastCov::FileTracker.active
55
+ result
31
56
  end
32
57
 
58
+ def foreach(name, ...)
59
+ result = super
60
+ FastCov::FileTracker.record(name) if FastCov::FileTracker.active
61
+ result
62
+ end
63
+ end
64
+
65
+ # File.open and File.new take a path only on File; on IO they take a file descriptor.
66
+ module FilePatch
33
67
  def open(name, *args, **kwargs, &block)
34
- super.tap do
35
- next unless FastCov::FileTracker.active
68
+ result = super
69
+ if FastCov::FileTracker.active && FastCov::FileTracker.read_mode?(args[0])
70
+ FastCov::FileTracker.record(name)
71
+ end
72
+ result
73
+ end
36
74
 
37
- mode = args[0]
38
- is_read = mode.nil? || (mode.is_a?(String) && mode.start_with?("r")) ||
39
- (mode.is_a?(Integer) && (mode & (File::WRONLY | File::RDWR)).zero?)
40
- FastCov::FileTracker.record(name) if is_read
75
+ def new(name, *args, **kwargs, &block)
76
+ result = super
77
+ if FastCov::FileTracker.active && FastCov::FileTracker.read_mode?(args[0])
78
+ FastCov::FileTracker.record(name)
41
79
  end
80
+ result
42
81
  end
43
82
  end
44
83
 
45
84
  module YamlPatch
46
- def load_file(path, *args, **kwargs)
47
- super.tap do
48
- FastCov::FileTracker.record(path) if FastCov::FileTracker.active
49
- end
85
+ def load_file(path, ...)
86
+ result = super
87
+ FastCov::FileTracker.record(path) if FastCov::FileTracker.active
88
+ result
50
89
  end
51
90
 
52
- def safe_load_file(path, *args, **kwargs)
53
- super.tap do
54
- FastCov::FileTracker.record(path) if FastCov::FileTracker.active
55
- end
91
+ def safe_load_file(path, ...)
92
+ result = super
93
+ FastCov::FileTracker.record(path) if FastCov::FileTracker.active
94
+ result
56
95
  end
57
96
 
58
- def unsafe_load_file(path, *args, **kwargs)
59
- super.tap do
60
- FastCov::FileTracker.record(path) if FastCov::FileTracker.active
61
- end
97
+ def unsafe_load_file(path, ...)
98
+ result = super
99
+ FastCov::FileTracker.record(path) if FastCov::FileTracker.active
100
+ result
62
101
  end
63
102
  end
64
103
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module FastCov
4
- VERSION = "0.5.0"
4
+ VERSION = "0.6.0"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fast_cov
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ngan Pham