minitest-holdify 1.3.1 → 1.3.3
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/lib/holdify/feedback.rb +23 -24
- data/lib/holdify/hold.rb +1 -3
- data/lib/holdify/store.rb +2 -2
- data/lib/holdify.rb +33 -10
- data/lib/minitest/holdify_plugin.rb +22 -9
- 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: 16f323fa95fbafe93f7554b26b3bcfd77c64904541374d1bb2355625a0cf3456
|
|
4
|
+
data.tar.gz: 35af707d16f16b01da03cdc4c57601c62d7c33157604a5a539f3b3b313dcfc21
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 1becfd3103d6e03e31e25b5cbfc16155792a6454d5052b85e4797d7d1597a25689dfc109597d115cd541c736eedb17c2b708cf6cd28089f13e8819b79cef62ac
|
|
7
|
+
data.tar.gz: 7a7be717e2bba29f50c16dcc0d4017cd9dc96a41618e65c8eeabec5a457de4da6891b190efe7a04464d2a447e4a81e55baf24b4546c37785022d1c9068f01a49
|
data/lib/holdify/feedback.rb
CHANGED
|
@@ -7,34 +7,34 @@ require 'open3'
|
|
|
7
7
|
module Holdify
|
|
8
8
|
# Feedback report on failure
|
|
9
9
|
class Feedback
|
|
10
|
-
attr_reader :xxhi_ref
|
|
11
|
-
|
|
12
10
|
def initialize(hold, hold_ref, *args)
|
|
13
11
|
test_lno = hold.test_loc.lineno
|
|
14
12
|
index = hold.session[test_lno].size - 1 # current index
|
|
15
13
|
xxh = hold.store.xxh(test_lno)
|
|
16
14
|
yaml_path = hold.store.path
|
|
17
15
|
|
|
18
|
-
@xxhi_ref = "<<< @xxh[i] --> #{xxh}[#{index}]"
|
|
19
|
-
|
|
20
16
|
@yaml_lno = find_yaml_lno(yaml_path, test_lno, xxh, index)
|
|
21
|
-
@yaml_ref = Holdify.
|
|
17
|
+
@yaml_ref = Holdify.relativize("#{yaml_path}:#{@yaml_lno}")
|
|
22
18
|
|
|
23
|
-
@hold_ref = Holdify.
|
|
24
|
-
test_ref = Holdify.
|
|
19
|
+
@hold_ref = Holdify.relativize(hold_ref)
|
|
20
|
+
test_ref = Holdify.relativize(hold.test_loc.to_s.sub(/:in .*$/, ''))
|
|
25
21
|
@test_ref = test_ref unless @hold_ref == test_ref
|
|
26
22
|
|
|
27
23
|
@expected, @actual, @message = *args
|
|
28
24
|
|
|
29
|
-
# Extend
|
|
30
|
-
extend
|
|
31
|
-
return unless Holdify.
|
|
25
|
+
# Extend features
|
|
26
|
+
extend Color if Holdify.color
|
|
27
|
+
return unless Holdify.git_diff
|
|
32
28
|
|
|
33
|
-
|
|
34
|
-
extend
|
|
29
|
+
@diff_yaml_headers = 2 # ----expected and +---actual (no sgr code) on 2 lines
|
|
30
|
+
extend GitDiff # rubocop:disable Layout/EmptyLinesAfterModuleInclusion
|
|
31
|
+
return unless Holdify.color
|
|
32
|
+
|
|
33
|
+
@diff_yaml_headers = 1 # ---expected---actual (with sgr codes) on single line
|
|
34
|
+
extend Color::GitDiff
|
|
35
35
|
end
|
|
36
36
|
|
|
37
|
-
def message = [@message,
|
|
37
|
+
def message = [@message, *file_refs, *diff, ''].join("\n")
|
|
38
38
|
|
|
39
39
|
def file_refs
|
|
40
40
|
["--- @stored --> #{@yaml_ref}", "+++ @tested --> #{@hold_ref}"].tap do |refs|
|
|
@@ -42,7 +42,7 @@ module Holdify
|
|
|
42
42
|
end
|
|
43
43
|
end
|
|
44
44
|
|
|
45
|
-
def diff = ["
|
|
45
|
+
def diff = ["-#{@expected.inspect}", "+#{@actual.inspect}"]
|
|
46
46
|
|
|
47
47
|
private
|
|
48
48
|
|
|
@@ -58,7 +58,7 @@ module Holdify
|
|
|
58
58
|
|
|
59
59
|
return ln
|
|
60
60
|
else
|
|
61
|
-
found = line.match(/^L#{test_lno}
|
|
61
|
+
found = line.match(/^L#{test_lno}-#{xxh}:$/)
|
|
62
62
|
end
|
|
63
63
|
end
|
|
64
64
|
end
|
|
@@ -91,14 +91,15 @@ module Holdify
|
|
|
91
91
|
end
|
|
92
92
|
|
|
93
93
|
def process_lines(lines)
|
|
94
|
-
width
|
|
95
|
-
lineno
|
|
94
|
+
width = 0
|
|
95
|
+
lineno = [@yaml_lno - 1]
|
|
96
96
|
lines.map.with_index do |line, i|
|
|
97
97
|
if i.zero? # @@ ... @@
|
|
98
98
|
width, line = render_hunk(line)
|
|
99
99
|
next line
|
|
100
|
+
elsif i <= @diff_yaml_headers # ---
|
|
101
|
+
next
|
|
100
102
|
end
|
|
101
|
-
next if i == 1 || (i == 2 && !Holdify.color) # ---
|
|
102
103
|
|
|
103
104
|
render_line(line, lineno, width)
|
|
104
105
|
end.compact
|
|
@@ -137,16 +138,14 @@ module Holdify
|
|
|
137
138
|
yellow: "\e[33m",
|
|
138
139
|
magenta: "\e[35m" }.freeze
|
|
139
140
|
|
|
140
|
-
def
|
|
141
|
+
def dye(color, string) = "#{SGR[color]}#{string}#{SGR[:clear]}"
|
|
141
142
|
|
|
142
143
|
def file_refs
|
|
143
144
|
refs = super
|
|
144
|
-
[
|
|
145
|
+
[dye(:red, refs.shift), *refs.map { dye(:green, _1) }]
|
|
145
146
|
end
|
|
146
147
|
|
|
147
|
-
def diff = [
|
|
148
|
-
|
|
149
|
-
def xxhi_ref = wrap(:magenta, @xxhi_ref)
|
|
148
|
+
def diff = [dye(:red, "-#{@expected.inspect}"), dye(:green, "+#{@actual.inspect}")]
|
|
150
149
|
|
|
151
150
|
# Methods enabling the git-diff ANSI feedback
|
|
152
151
|
module GitDiff
|
|
@@ -162,7 +161,7 @@ module Holdify
|
|
|
162
161
|
|
|
163
162
|
sgr = SGR[color].to_s if color
|
|
164
163
|
gutter = if added
|
|
165
|
-
"#{sgr}#{type}
|
|
164
|
+
"#{sgr}#{type}#{' ' * width}#{SGR[:clear]}"
|
|
166
165
|
else
|
|
167
166
|
lineno[0] += 1
|
|
168
167
|
"#{sgr}#{type || ' '}#{lineno[0].to_s.rjust(width)}#{SGR[:clear]}"
|
data/lib/holdify/hold.rb
CHANGED
|
@@ -11,7 +11,6 @@ module Holdify
|
|
|
11
11
|
@store = Holdify.stores(@path)
|
|
12
12
|
@session = Hash.new { |h, k| h[k] = [] } # { lineno => [values] }
|
|
13
13
|
@forced = [] # [ lines ]
|
|
14
|
-
@added = [] # [ lines ]
|
|
15
14
|
end
|
|
16
15
|
|
|
17
16
|
def call(actual, force: false)
|
|
@@ -28,7 +27,7 @@ module Holdify
|
|
|
28
27
|
elsif values && index < values.size
|
|
29
28
|
values[index]
|
|
30
29
|
else
|
|
31
|
-
@
|
|
30
|
+
Holdify.push_fresh("#{Holdify.relativize(@test_loc.path)}:#{lineno}")
|
|
32
31
|
actual
|
|
33
32
|
end
|
|
34
33
|
|
|
@@ -37,7 +36,6 @@ module Holdify
|
|
|
37
36
|
end
|
|
38
37
|
|
|
39
38
|
def save
|
|
40
|
-
@added.each { |lineno| warn "[holdify] Held new value for #{Holdify.relative(@path)}:#{lineno}" } unless Holdify.quiet
|
|
41
39
|
@session.each { |lineno, values| @store.set_values(lineno, values) }
|
|
42
40
|
end
|
|
43
41
|
|
data/lib/holdify/store.rb
CHANGED
|
@@ -40,7 +40,7 @@ module Holdify
|
|
|
40
40
|
xxh = @source.xxh(lineno)
|
|
41
41
|
next unless xxh
|
|
42
42
|
|
|
43
|
-
output["L#{lineno}
|
|
43
|
+
output["L#{lineno}-#{xxh}"] = @data[lineno]
|
|
44
44
|
end
|
|
45
45
|
|
|
46
46
|
File.write(@path, self.class.hold_dump(output))
|
|
@@ -51,7 +51,7 @@ module Holdify
|
|
|
51
51
|
def load_and_align
|
|
52
52
|
{}.tap do |aligned|
|
|
53
53
|
data = YAML.unsafe_load_file(@path) || {}
|
|
54
|
-
data.group_by { |k, _| k.split.last }.each do |xxh, entries|
|
|
54
|
+
data.group_by { |k, _| k.split('-').last }.each do |xxh, entries|
|
|
55
55
|
lines = @source.lines(xxh)
|
|
56
56
|
next if lines.empty?
|
|
57
57
|
|
data/lib/holdify.rb
CHANGED
|
@@ -7,27 +7,50 @@ require_relative 'holdify/store'
|
|
|
7
7
|
|
|
8
8
|
# The container module
|
|
9
9
|
module Holdify
|
|
10
|
-
VERSION = '1.3.
|
|
10
|
+
VERSION = '1.3.3'
|
|
11
|
+
|
|
12
|
+
@fresh_mutex = Mutex.new
|
|
13
|
+
@fresh = []
|
|
14
|
+
@stores_mutex = Mutex.new
|
|
15
|
+
@stores = {}
|
|
11
16
|
|
|
12
17
|
class << self
|
|
13
|
-
attr_accessor :reconcile, :quiet, :
|
|
18
|
+
attr_accessor :reconcile, :quiet, :git_diff, :pwd, :color, :rel_paths, :store_ext
|
|
14
19
|
|
|
15
|
-
def
|
|
20
|
+
def push_fresh(test_ref)
|
|
21
|
+
@fresh_mutex.synchronize do
|
|
22
|
+
@fresh << test_ref
|
|
23
|
+
end
|
|
24
|
+
end
|
|
16
25
|
|
|
17
|
-
def
|
|
18
|
-
return
|
|
26
|
+
def fresh_report
|
|
27
|
+
return if quiet
|
|
19
28
|
|
|
20
|
-
|
|
29
|
+
@fresh_mutex.synchronize do
|
|
30
|
+
return if @fresh.empty?
|
|
31
|
+
|
|
32
|
+
warn "[HOLDIFY] Fresh value held for:\n#{@fresh.uniq.sort.map { " #{_1}" }.join("\n")}"
|
|
33
|
+
end
|
|
21
34
|
end
|
|
22
35
|
|
|
23
36
|
def stores(path = nil)
|
|
24
|
-
|
|
37
|
+
@stores_mutex.synchronize do
|
|
38
|
+
return @stores unless path
|
|
25
39
|
|
|
26
|
-
@mutex.synchronize do
|
|
27
40
|
@stores[path] ||= Store.new(path)
|
|
28
41
|
end
|
|
29
42
|
end
|
|
43
|
+
|
|
44
|
+
def persist_stores!
|
|
45
|
+
@stores_mutex.synchronize do
|
|
46
|
+
@stores&.each_value(&:persist)
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
def relativize(path)
|
|
51
|
+
return path unless rel_paths
|
|
52
|
+
|
|
53
|
+
path.sub(%r{^#{pwd}/}, '')
|
|
54
|
+
end
|
|
30
55
|
end
|
|
31
|
-
@mutex = Mutex.new
|
|
32
|
-
@stores = {}
|
|
33
56
|
end
|
|
@@ -19,8 +19,8 @@ module Minitest
|
|
|
19
19
|
opts.on '--holdify-no-color', 'Disable colored output' do
|
|
20
20
|
options[:holdify_no_color] = true
|
|
21
21
|
end
|
|
22
|
-
opts.on '--holdify-no-
|
|
23
|
-
options[:
|
|
22
|
+
opts.on '--holdify-no-relative-paths', 'Disable relative paths in file references' do
|
|
23
|
+
options[:holdify_no_relative_paths] = true
|
|
24
24
|
end
|
|
25
25
|
opts.on '--holdify-store-ext EXT', 'The yaml store extension (default .yaml)' do |ext|
|
|
26
26
|
options[:holdify_store_ext] = ext
|
|
@@ -29,15 +29,28 @@ module Minitest
|
|
|
29
29
|
|
|
30
30
|
# Register the after_run hook to persist all data
|
|
31
31
|
def self.plugin_holdify_init(options)
|
|
32
|
+
# :nocov:
|
|
33
|
+
git = system('git --version', out: File::NULL, err: File::NULL)
|
|
34
|
+
Holdify.pwd = git ? `git rev-parse --show-toplevel`.strip : Dir.pwd
|
|
35
|
+
# :nocov:
|
|
36
|
+
|
|
32
37
|
Holdify.reconcile = options[:holdify_reconcile]
|
|
33
38
|
Holdify.quiet = options[:holdify_quiet]
|
|
34
|
-
Holdify.
|
|
35
|
-
Holdify.pwd = Holdify.git ? `git rev-parse --show-toplevel`.strip : Dir.pwd
|
|
39
|
+
Holdify.git_diff = git unless options[:holdify_no_git_diff]
|
|
36
40
|
Holdify.color = !ENV.key?('NO_COLOR') unless options[:holdify_no_color]
|
|
37
|
-
Holdify.rel_paths = true unless options[:
|
|
41
|
+
Holdify.rel_paths = true unless options[:holdify_no_relative_paths]
|
|
38
42
|
Holdify.store_ext = options[:holdify_store_ext] || '.yaml'
|
|
39
43
|
|
|
40
|
-
Minitest.after_run
|
|
44
|
+
Minitest.after_run do
|
|
45
|
+
Holdify.persist_stores!
|
|
46
|
+
Holdify.fresh_report
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
# Patching Minitest::Assertion
|
|
51
|
+
class Assertion
|
|
52
|
+
remove_const :RE
|
|
53
|
+
RE = /in [`'](?:[^']+[#.])?(?:assert|refute|flunk|pass|fail|raise|must|wont|to)/ # :nodoc:
|
|
41
54
|
end
|
|
42
55
|
|
|
43
56
|
# Reopen the minitest class
|
|
@@ -51,10 +64,10 @@ module Minitest
|
|
|
51
64
|
return unless @hold.forced.any?
|
|
52
65
|
|
|
53
66
|
path, = method(name).source_location
|
|
54
|
-
msg = +%([
|
|
67
|
+
msg = +%([HOLDIFY] Reconciled values (Remove the "!" suffix to pass the test)\n)
|
|
55
68
|
msg << @hold.forced.uniq.map { |lineno| " #{path}:#{lineno}" }.join("\n")
|
|
56
69
|
|
|
57
|
-
|
|
70
|
+
flunk msg
|
|
58
71
|
end
|
|
59
72
|
end
|
|
60
73
|
|
|
@@ -69,7 +82,7 @@ module Minitest
|
|
|
69
82
|
|
|
70
83
|
begin
|
|
71
84
|
if inspect
|
|
72
|
-
message = ['
|
|
85
|
+
message = ['[HOLDIFY] Inspect actual value (Remove the "?" suffix to pass the test)', message].compact.join(' ')
|
|
73
86
|
flunk(message)
|
|
74
87
|
elsif actual.nil?
|
|
75
88
|
assert_nil expected, message
|