thrown error from a naked try (not inside #expect/#require) from a test does not report correct line number #1079
Labels
enhancement
New feature or request
issue-handling
Related to Issue handling within the testing library
Description
If you have a test case like
@test func test1() throws {
a = try getAnObject()
}
and getAnObject() throws an error, the test framework reports the @test line number as where the problem occurs, not the getAnObject() line
Reproduction
testfail.zip
Unzip the above archive, then cd into it and type "swift test". After running the test, it will report
Where testfailTests.swift:5:2 is the location of the start of the function whereas it should have reported line 8 since that's where the throw occurred.
Expected behavior
The testing framework should report the line where the throw occurred, not the start of the function.
Environment
↳ Testing Library Version: 1055
% swift --version
swift-driver version: 1.124.5 Apple Swift version 6.2 (swiftlang-6.2.0.5.56 clang-1700.3.5.51)
Target: arm64-apple-macosx15.0
% uname -a
Darwin MacBook-Pro-1800.local 24.4.0 Darwin Kernel Version 24.4.0: Wed Mar 19 21:37:10 PDT 2025; root:xnu_development-11417.101.15~1/DEVELOPMENT_ARM64_T6000 arm64
Additional information
No response
The text was updated successfully, but these errors were encountered: