Skip to content

Commit

Permalink
+ Refactored location information in assertions, now using locations.
Browse files Browse the repository at this point in the history
[git-p4: depot-paths = "//src/minitest/dev/": change = 13993]
  • Loading branch information
zenspider committed Jan 4, 2024
1 parent 487f44e commit 4545d5c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
14 changes: 7 additions & 7 deletions lib/minitest/assertions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,11 @@ def assert_empty obj, msg = nil
assert obj.empty?, msg
end

def _where # :nodoc:
where = Minitest.filter_backtrace(caller_locations).first
[where.path, where.lineno].join ":"
end

E = "" # :nodoc:

##
Expand All @@ -221,10 +226,7 @@ def assert_equal exp, act, msg = nil
if Minitest::VERSION =~ /^6/ then
refute_nil exp, "Use assert_nil if expecting nil."
else
where = Minitest.filter_backtrace(caller).first
where = where.split(/:in /, 2).first # clean up noise

warn "DEPRECATED: Use assert_nil if expecting nil from #{where}. This will fail in Minitest 6."
warn "DEPRECATED: Use assert_nil if expecting nil from #{_where}. This will fail in Minitest 6."
end
end

Expand Down Expand Up @@ -475,9 +477,7 @@ def assert_same exp, act, msg = nil
# Fails unless the call returns a true value

def assert_send send_ary, m = nil
where = Minitest.filter_backtrace(caller).first
where = where.split(/:in /, 2).first # clean up noise
warn "DEPRECATED: assert_send. From #{where}"
warn "DEPRECATED: assert_send. From #{_where}"

recv, msg, *args = send_ary
m = message(m) {
Expand Down
4 changes: 2 additions & 2 deletions lib/minitest/spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ def infect_an_assertion meth, new_name, dont_flip = false # :nodoc:
# warn "%-22p -> %p %p" % [meth, new_name, dont_flip]
self.class_eval <<-EOM, __FILE__, __LINE__ + 1
def #{new_name} *args
where = Minitest.filter_backtrace(caller).first
where = where.split(/:in /, 2).first # clean up noise
where = Minitest.filter_backtrace(caller_locations).first
where = [where.path, where.lineno].join ":"
Kernel.warn "DEPRECATED: global use of #{new_name} from #\{where}. Use #{target_obj}.#{new_name} instead. This will fail in Minitest 6."
Minitest::Expectation.new(self, Minitest::Spec.current).#{new_name}(*args)
end
Expand Down

0 comments on commit 4545d5c

Please sign in to comment.