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 +4 -4
- data/README.md +1 -1
- data/lib/fast_cov/trackers/file_tracker.rb +63 -24
- data/lib/fast_cov/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: dfbb83e455b2aa5e3c11f705b2358bc38e881b773ee6cf0598b0daee551b4669
|
|
4
|
+
data.tar.gz: f9baa9d8f6f38d45741328b99872307cce4097011a8091ac4f6157db20729d14
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
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 `
|
|
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
|
|
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
|
|
27
|
-
def read(name,
|
|
28
|
-
super
|
|
29
|
-
|
|
30
|
-
|
|
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
|
|
35
|
-
|
|
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
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
FastCov::FileTracker.record(name)
|
|
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,
|
|
47
|
-
super
|
|
48
|
-
|
|
49
|
-
|
|
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,
|
|
53
|
-
super
|
|
54
|
-
|
|
55
|
-
|
|
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,
|
|
59
|
-
super
|
|
60
|
-
|
|
61
|
-
|
|
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
|
data/lib/fast_cov/version.rb
CHANGED