power_assert 1.1.1 → 1.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.travis.yml +8 -6
- data/BSDL +1 -1
- data/COPYING +1 -1
- data/README.rdoc +7 -0
- data/Rakefile +2 -2
- data/lib/power_assert.rb +1 -1
- data/lib/power_assert/context.rb +45 -30
- data/lib/power_assert/parser.rb +6 -5
- data/lib/power_assert/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 2a370d0589f6825379578235e06ca2c1d249577582acda601f73d83bdc90220f
|
4
|
+
data.tar.gz: 0ff765413706da6b356e96ee17b6767b6074b8093b9776f65e025d520395fc0b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9c3bc4482abf9078cfc429b4ca32865521a11d9bc5ecc5cdaec7d796edd9f99d9146214101d10fe58dfe4438b5499a07e348396ed96e86dae6c6a6aab5fcd6a5
|
7
|
+
data.tar.gz: 8197767a6e6ac199aa599a332254e7fdb40252856eb3a411ac55320af7bf25c4ae58591d3f3017d547aa67436a40ee58dac26bb5688ed627ebbfc65e21986d2c
|
data/.travis.yml
CHANGED
@@ -3,9 +3,10 @@ language: ruby
|
|
3
3
|
rvm:
|
4
4
|
- 2.0.0-p648
|
5
5
|
- 2.1.10
|
6
|
-
- 2.2.
|
7
|
-
- 2.3.
|
8
|
-
- 2.4.
|
6
|
+
- 2.2.10
|
7
|
+
- 2.3.7
|
8
|
+
- 2.4.4
|
9
|
+
- 2.5.1
|
9
10
|
- ruby-head
|
10
11
|
env:
|
11
12
|
- TEST_SYMLINK="no"
|
@@ -14,8 +15,9 @@ matrix:
|
|
14
15
|
allow_failures:
|
15
16
|
- rvm: ruby-head
|
16
17
|
before_install:
|
17
|
-
|
18
|
+
- gem update --system
|
19
|
+
- gem update bundler
|
18
20
|
before_script:
|
19
|
-
|
21
|
+
- bundle exec rake before_script
|
20
22
|
after_script:
|
21
|
-
|
23
|
+
- bundle exec rake after_script
|
data/BSDL
CHANGED
data/COPYING
CHANGED
data/README.rdoc
CHANGED
@@ -5,6 +5,13 @@ Power Assert for Ruby.
|
|
5
5
|
Power Assert shows each value of variables and method calls in the expression.
|
6
6
|
It is useful for testing, providing which value wasn't correct when the condition is not satisfied.
|
7
7
|
|
8
|
+
Failure:
|
9
|
+
assert { 3.times.to_a.include?(3) }
|
10
|
+
| | |
|
11
|
+
| | false
|
12
|
+
| [0, 1, 2]
|
13
|
+
#<Enumerator: 3:times>
|
14
|
+
|
8
15
|
== Related Projects
|
9
16
|
In general, you don't need to use this library directly.
|
10
17
|
Use following test frameworks or extensions instead.
|
data/Rakefile
CHANGED
@@ -8,8 +8,8 @@ Rake::TestTask.new(:test) do |t|
|
|
8
8
|
t.ruby_opts = ["-w", "-r#{helper_path}"]
|
9
9
|
t.test_files = FileList["test/**/*_test.rb"].exclude do |i|
|
10
10
|
begin
|
11
|
-
|
12
|
-
RubyVM::InstructionSequence.compile(
|
11
|
+
next false unless defined?(RubyVM)
|
12
|
+
RubyVM::InstructionSequence.compile(File.read(i))
|
13
13
|
false
|
14
14
|
rescue SyntaxError
|
15
15
|
true
|
data/lib/power_assert.rb
CHANGED
data/lib/power_assert/context.rb
CHANGED
@@ -5,7 +5,7 @@ require 'power_assert/parser'
|
|
5
5
|
|
6
6
|
module PowerAssert
|
7
7
|
class Context
|
8
|
-
Value = Struct.new(:name, :value, :lineno, :column)
|
8
|
+
Value = Struct.new(:name, :value, :lineno, :column, :display_offset)
|
9
9
|
|
10
10
|
def initialize(base_caller_length)
|
11
11
|
@fired = false
|
@@ -14,26 +14,30 @@ module PowerAssert
|
|
14
14
|
@return_values = []
|
15
15
|
trace_alias_method = PowerAssert.configuration._trace_alias_method
|
16
16
|
@trace_return = TracePoint.new(:return, :c_return) do |tp|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
17
|
+
begin
|
18
|
+
unless method_id_set
|
19
|
+
next unless Thread.current == @target_thread
|
20
|
+
method_id_set = @parser.method_id_set
|
21
|
+
end
|
22
|
+
method_id = SUPPORT_ALIAS_METHOD ? tp.callee_id :
|
23
|
+
trace_alias_method && tp.event == :return ? tp.binding.eval('::Kernel.__callee__') :
|
24
|
+
tp.method_id
|
25
|
+
next if ! method_id_set[method_id]
|
26
|
+
next if tp.event == :c_return and
|
27
|
+
not (@parser.lineno == tp.lineno and @parser.path == tp.path)
|
28
|
+
locs = PowerAssert.app_caller_locations
|
29
|
+
diff = locs.length - base_caller_length
|
30
|
+
if (tp.event == :c_return && diff == 1 || tp.event == :return && diff <= 2) and Thread.current == @target_thread
|
31
|
+
idx = -(base_caller_length + 1)
|
32
|
+
if @parser.path == locs[idx].path and @parser.lineno == locs[idx].lineno
|
33
|
+
val = PowerAssert.configuration.lazy_inspection ?
|
34
|
+
tp.return_value :
|
35
|
+
InspectedValue.new(SafeInspectable.new(tp.return_value).inspect)
|
36
|
+
@return_values << Value[method_id.to_s, val, locs[idx].lineno, nil]
|
37
|
+
end
|
36
38
|
end
|
39
|
+
rescue Exception => e
|
40
|
+
warn "power_assert: [BUG] Failed to trace: #{e.class}: #{e.message}"
|
37
41
|
end
|
38
42
|
end
|
39
43
|
end
|
@@ -63,21 +67,22 @@ module PowerAssert
|
|
63
67
|
path = detect_path(parser, return_values)
|
64
68
|
return line unless path
|
65
69
|
|
70
|
+
c2d = column2display_offset(parser.line)
|
66
71
|
return_values, methods_in_path = find_all_identified_calls(return_values, path)
|
67
72
|
return_values.zip(methods_in_path) do |i, j|
|
68
73
|
unless i.name == j.name
|
69
74
|
warn "power_assert: [BUG] Failed to get column: #{i.name}"
|
70
75
|
return line
|
71
76
|
end
|
72
|
-
i.
|
77
|
+
i.display_offset = c2d[j.column]
|
73
78
|
end
|
74
79
|
refs_in_path = path.find_all {|i| i.type == :ref }
|
75
|
-
ref_values = refs_in_path.map {|i| Value[i.name, parser.binding.eval(i.name), parser.lineno, i.column] }
|
76
|
-
vals = (return_values + ref_values).find_all(&:
|
80
|
+
ref_values = refs_in_path.map {|i| Value[i.name, parser.binding.eval(i.name), parser.lineno, i.column, c2d[i.column]] }
|
81
|
+
vals = (return_values + ref_values).find_all(&:display_offset).sort_by(&:display_offset).reverse
|
77
82
|
return line if vals.empty?
|
78
83
|
|
79
|
-
fmt = (0..vals[0].
|
80
|
-
if vals.find {|v| v.
|
84
|
+
fmt = (0..vals[0].display_offset).map do |i|
|
85
|
+
if vals.find {|v| v.display_offset == i }
|
81
86
|
"%<#{i}>s"
|
82
87
|
else
|
83
88
|
line[i] == "\t" ? "\t" : ' '
|
@@ -85,12 +90,12 @@ module PowerAssert
|
|
85
90
|
end.join
|
86
91
|
lines = []
|
87
92
|
lines << line.chomp
|
88
|
-
lines << sprintf(fmt, vals.each_with_object({}) {|v, h| h[v.
|
93
|
+
lines << sprintf(fmt, vals.each_with_object({}) {|v, h| h[v.display_offset.to_s.to_sym] = '|' }).chomp
|
89
94
|
vals.each do |i|
|
90
|
-
inspected_val = SafeInspectable.new(Formatter.new(i.value, i.
|
95
|
+
inspected_val = SafeInspectable.new(Formatter.new(i.value, i.display_offset)).inspect
|
91
96
|
inspected_val.each_line do |l|
|
92
97
|
map_to = vals.each_with_object({}) do |j, h|
|
93
|
-
h[j.
|
98
|
+
h[j.display_offset.to_s.to_sym] = [l, '|', ' '][i.display_offset <=> j.display_offset]
|
94
99
|
end
|
95
100
|
lines << encoding_safe_rstrip(sprintf(fmt, map_to))
|
96
101
|
end
|
@@ -142,6 +147,16 @@ module PowerAssert
|
|
142
147
|
str
|
143
148
|
end
|
144
149
|
end
|
150
|
+
|
151
|
+
def column2display_offset(str)
|
152
|
+
display_offset = 0
|
153
|
+
str.each_char.with_object([]) do |c, r|
|
154
|
+
c.bytesize.times do
|
155
|
+
r << display_offset
|
156
|
+
end
|
157
|
+
display_offset += c.ascii_only? ? 1 : 2 # FIXME
|
158
|
+
end
|
159
|
+
end
|
145
160
|
end
|
146
161
|
private_constant :Context
|
147
162
|
|
@@ -163,7 +178,7 @@ module PowerAssert
|
|
163
178
|
path = locs.last.path
|
164
179
|
lineno = locs.last.lineno
|
165
180
|
if File.exist?(path)
|
166
|
-
line ||= open(path).each_line.drop(lineno - 1).first
|
181
|
+
line ||= File.open(path) {|fp| fp.each_line.drop(lineno - 1).first }
|
167
182
|
@parser = Parser.new(line, path, lineno, @assertion_proc.binding, assertion_method.to_s, @assertion_proc)
|
168
183
|
end
|
169
184
|
end
|
@@ -194,7 +209,7 @@ module PowerAssert
|
|
194
209
|
path = target_frame.path
|
195
210
|
lineno = target_frame.lineno
|
196
211
|
if File.exist?(path)
|
197
|
-
line = open(path).each_line.drop(lineno - 1).first
|
212
|
+
line = File.open(path) {|fp| fp.each_line.drop(lineno - 1).first }
|
198
213
|
@parser = Parser.new(line, path, lineno, binding)
|
199
214
|
else
|
200
215
|
@parser = Parser::DUMMY
|
data/lib/power_assert/parser.rb
CHANGED
@@ -8,7 +8,7 @@ module PowerAssert
|
|
8
8
|
|
9
9
|
def initialize(line, path, lineno, binding, assertion_method_name = nil, assertion_proc = nil)
|
10
10
|
@line = line
|
11
|
-
@line_for_parsing = valid_syntax?(line) ? line : slice_expression(line)
|
11
|
+
@line_for_parsing = (valid_syntax?(line) ? line : slice_expression(line)).b
|
12
12
|
@path = path
|
13
13
|
@lineno = lineno
|
14
14
|
@binding = binding
|
@@ -94,11 +94,12 @@ module PowerAssert
|
|
94
94
|
handle_columnless_ident(extract_idents(sexp[1]), op, extract_idents(sexp[3]))
|
95
95
|
end
|
96
96
|
when :call
|
97
|
-
|
98
|
-
|
99
|
-
|
97
|
+
_, recv, (op_sym, op_name, _), method = sexp
|
98
|
+
with_safe_op = ((op_sym == :@op and op_name == '&.') or op_sym == :"&.")
|
99
|
+
if method == :call
|
100
|
+
handle_columnless_ident(extract_idents(recv), :call, [], with_safe_op)
|
100
101
|
else
|
101
|
-
extract_idents(
|
102
|
+
extract_idents(recv) + (with_safe_op ? [Branch[extract_idents(method), []]] : extract_idents(method))
|
102
103
|
end
|
103
104
|
when :array
|
104
105
|
sexp[1] ? sexp[1].flat_map {|s| extract_idents(s) } : []
|
data/lib/power_assert/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: power_assert
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1.
|
4
|
+
version: 1.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kazuki Tsujimoto
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2018-06-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: test-unit
|
@@ -146,7 +146,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
146
146
|
version: '0'
|
147
147
|
requirements: []
|
148
148
|
rubyforge_project:
|
149
|
-
rubygems_version: 2.6
|
149
|
+
rubygems_version: 2.7.6
|
150
150
|
signing_key:
|
151
151
|
specification_version: 4
|
152
152
|
summary: Power Assert for Ruby
|