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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 94700e701d6e70078cff18ec8db5689ebcb69fc1
4
- data.tar.gz: cf854f8bb406169ccf8b22869d77b8320191a07c
2
+ SHA256:
3
+ metadata.gz: 2a370d0589f6825379578235e06ca2c1d249577582acda601f73d83bdc90220f
4
+ data.tar.gz: 0ff765413706da6b356e96ee17b6767b6074b8093b9776f65e025d520395fc0b
5
5
  SHA512:
6
- metadata.gz: 52ee0c7f1fb5ea27e42f64c99160e71d54ab3ca8787f703d173a340c98bccb0a0f5fc322c96c97ec99c0f04f6cabd664e4cae1085653c47e34a25c1de71a49db
7
- data.tar.gz: def9341626a182f990d568a67fb8970d004644dfe0d48d89daef2671fa87e18c6f48099594c237130da74e4d762a9f38c9af723f86fd443ebdea19e189505509
6
+ metadata.gz: 9c3bc4482abf9078cfc429b4ca32865521a11d9bc5ecc5cdaec7d796edd9f99d9146214101d10fe58dfe4438b5499a07e348396ed96e86dae6c6a6aab5fcd6a5
7
+ data.tar.gz: 8197767a6e6ac199aa599a332254e7fdb40252856eb3a411ac55320af7bf25c4ae58591d3f3017d547aa67436a40ee58dac26bb5688ed627ebbfc65e21986d2c
@@ -3,9 +3,10 @@ language: ruby
3
3
  rvm:
4
4
  - 2.0.0-p648
5
5
  - 2.1.10
6
- - 2.2.7
7
- - 2.3.4
8
- - 2.4.1
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
- - gem update bundler
18
+ - gem update --system
19
+ - gem update bundler
18
20
  before_script:
19
- - bundle exec rake before_script
21
+ - bundle exec rake before_script
20
22
  after_script:
21
- - bundle exec rake after_script
23
+ - bundle exec rake after_script
data/BSDL CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (C) 2014-2017 Kazuki Tsujimoto, All rights reserved.
1
+ Copyright (C) 2014 Kazuki Tsujimoto
2
2
 
3
3
  Redistribution and use in source and binary forms, with or without
4
4
  modification, are permitted provided that the following conditions
data/COPYING CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (C) 2014-2017 Kazuki Tsujimoto, All rights reserved.
1
+ Copyright (C) 2014 Kazuki Tsujimoto
2
2
 
3
3
  You can redistribute it and/or modify it under either the terms of the
4
4
  2-clause BSDL (see the file BSDL), or the conditions below:
@@ -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
- return false unless defined?(RubyVM)
12
- RubyVM::InstructionSequence.compile(open(i).read)
11
+ next false unless defined?(RubyVM)
12
+ RubyVM::InstructionSequence.compile(File.read(i))
13
13
  false
14
14
  rescue SyntaxError
15
15
  true
@@ -1,6 +1,6 @@
1
1
  # power_assert.rb
2
2
  #
3
- # Copyright (C) 2014-2017 Kazuki Tsujimoto, All rights reserved.
3
+ # Copyright (C) 2014 Kazuki Tsujimoto
4
4
 
5
5
  begin
6
6
  unless defined?(Byebug)
@@ -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
- unless method_id_set
18
- next unless Thread.current == @target_thread
19
- method_id_set = @parser.method_id_set
20
- end
21
- method_id = SUPPORT_ALIAS_METHOD ? tp.callee_id :
22
- trace_alias_method && tp.event == :return ? tp.binding.eval('::Kernel.__callee__') :
23
- tp.method_id
24
- next if ! method_id_set[method_id]
25
- next if tp.event == :c_return and
26
- not (@parser.lineno == tp.lineno and @parser.path == tp.path)
27
- locs = PowerAssert.app_caller_locations
28
- diff = locs.length - base_caller_length
29
- if (tp.event == :c_return && diff == 1 || tp.event == :return && diff <= 2) and Thread.current == @target_thread
30
- idx = -(base_caller_length + 1)
31
- if @parser.path == locs[idx].path and @parser.lineno == locs[idx].lineno
32
- val = PowerAssert.configuration.lazy_inspection ?
33
- tp.return_value :
34
- InspectedValue.new(SafeInspectable.new(tp.return_value).inspect)
35
- @return_values << Value[method_id.to_s, val, locs[idx].lineno, nil]
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.column = j.column
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(&:column).sort_by(&:column).reverse
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].column).map do |i|
80
- if vals.find {|v| v.column == i }
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.column.to_s.to_sym] = '|' }).chomp
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.column)).inspect
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.column.to_s.to_sym] = [l, '|', ' '][i.column <=> j.column]
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
@@ -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
- with_safe_op = sexp[2] == :"&."
98
- if sexp[3] == :call
99
- handle_columnless_ident(extract_idents(sexp[1]), :call, [], with_safe_op)
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(sexp[1]) + (with_safe_op ? [Branch[extract_idents(sexp[3]), []]] : extract_idents(sexp[3]))
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) } : []
@@ -1,3 +1,3 @@
1
1
  module PowerAssert
2
- VERSION = "1.1.1"
2
+ VERSION = "1.1.2"
3
3
  end
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.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: 2017-10-25 00:00:00.000000000 Z
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.11
149
+ rubygems_version: 2.7.6
150
150
  signing_key:
151
151
  specification_version: 4
152
152
  summary: Power Assert for Ruby