Skip to content

Commit f1bcff3

Browse files
committed
Avoid eager call trace inspection in type assertions
1 parent 6341786 commit f1bcff3

2 files changed

Lines changed: 7 additions & 7 deletions

File tree

lib/rbs/unit_test/type_assertions.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -180,11 +180,11 @@ def send_setup(method_type, receiver, method, args, proc)
180180
)
181181
errors = typecheck.method_call(method, method_type, trace, errors: [])
182182

183-
assert_empty errors.map {|x| RBS::Test::Errors.to_string(x) }, "Call trace does not match with given method type: #{trace.inspect}"
183+
assert_empty errors.map {|x| RBS::Test::Errors.to_string(x) }, -> { "Call trace does not match with given method type: #{trace.inspect}" }
184184

185185
method_defs = method_defs(method)
186186
all_errors = method_defs.map {|t| typecheck.method_call(method, t.type, trace, errors: [], annotations: t.each_annotation.to_a) }
187-
assert all_errors.any? {|es| es.empty? }, "Call trace does not match one of method definitions:\n #{trace.inspect}\n #{method_defs.map(&:type).join(" | ")}"
187+
assert all_errors.any? {|es| es.empty? }, -> { "Call trace does not match one of method definitions:\n #{trace.inspect}\n #{method_defs.map(&:type).join(" | ")}" }
188188

189189
raise exception if exception
190190

@@ -204,11 +204,11 @@ def send_setup(method_type, receiver, method, args, proc)
204204
)
205205
errors = typecheck.method_call(method, method_type, trace, errors: [])
206206

207-
assert_empty errors.map {|x| RBS::Test::Errors.to_string(x) }, "Call trace does not match with given method type: #{trace.inspect}"
207+
assert_empty errors.map {|x| RBS::Test::Errors.to_string(x) }, -> { "Call trace does not match with given method type: #{trace.inspect}" }
208208

209209
method_defs = method_defs(method)
210210
all_errors = method_defs.map {|t| typecheck.method_call(method, t.type, trace, errors: [], annotations: t.each_annotation.to_a) }
211-
assert all_errors.any? {|es| es.empty? }, "Call trace does not match one of method definitions:\n #{trace.inspect}\n #{method_defs.map(&:type).join(" | ")}"
211+
assert all_errors.any? {|es| es.empty? }, -> { "Call trace does not match one of method definitions:\n #{trace.inspect}\n #{method_defs.map(&:type).join(" | ")}" }
212212

213213
# Use `instnace_of?` instead of `is_a?` as we want to check for _the exact exception class_.
214214
assert exception.instance_of? error_type
@@ -246,7 +246,7 @@ def send_setup(method_type, receiver, method, args, proc)
246246

247247
method_defs = method_defs(method)
248248
all_errors = method_defs.map {|t| typecheck.method_call(method, t.type, trace, errors: [], annotations: t.each_annotation.to_a) }
249-
assert all_errors.all? {|es| es.size > 0 }, "Call trace unexpectedly matches one of method definitions:\n #{trace.inspect}\n #{method_defs.map(&:type).join(" | ")}"
249+
assert all_errors.all? {|es| es.size > 0 }, -> { "Call trace unexpectedly matches one of method definitions:\n #{trace.inspect}\n #{method_defs.map(&:type).join(" | ")}" }
250250

251251
result
252252
end

sig/unit_test/type_assertions.rbs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,11 @@ module RBS
3030
type target_type = Types::ClassInstance | Types::ClassSingleton
3131

3232
interface _BaseAssertions
33-
def assert: (untyped, ?String?) -> void
33+
def assert: (untyped, ?(String | ^() -> String)?) -> void
3434

3535
def refute: (untyped, ?String?) -> void
3636

37-
def assert_empty: (untyped, ?String?) -> void
37+
def assert_empty: (untyped, ?(String | ^() -> String)?) -> void
3838

3939
def assert_operator: (untyped, Symbol, *untyped) -> void
4040

0 commit comments

Comments
 (0)