swift-testing icon indicating copy to clipboard operation
swift-testing copied to clipboard

Capture source location of elements in collection literal test arguments

Open wwake opened this issue 1 year ago • 6 comments

Description

For parameterized tests, I'd like the error report to point to the source line of the failing test case (perhaps as well as the #expect that failed). This makes more sense for sequences of test cases than combinatorial tests.

In XCTest, I used a struct wrapping each test case that captured #file and #line, so I could pass those through to the assertions. (Sub-issue: there's no corresponding #sourceLocation macro so I can't capture the exact location.)

Wrapping each line was annoying. It would really be nice if there were an implicit way to get this information - e.g., automatically capture the source location for each test case, and add an argument or implicit value that you could pass to #expect.

Expected behavior

No response

Actual behavior

No response

Steps to reproduce

No response

swift-testing version/commit hash

No response

Swift & OS version (output of swift --version && uname -a)

No response

wwake avatar Jul 02 '24 11:07 wwake

For inputs like array or dictionary literals, we want to implement something here in a future update. In the general case, it's not possible (because source location information is only available for elements in collection literals.)

grynspan avatar Jul 02 '24 12:07 grynspan

Separately, we did just add #_sourceLocation, although it's not in Xcode or in a tagged release yet.

grynspan avatar Jul 02 '24 13:07 grynspan

I updated the title to scope the request a bit more narrowly to something we can actually achieve:

Capture source location of elements in collection literal test arguments

stmontgomery avatar Jul 02 '24 14:07 stmontgomery

Tracked internally as rdar://130959475

stmontgomery avatar Jul 02 '24 14:07 stmontgomery

I think we have an earlier radar?

grynspan avatar Jul 02 '24 16:07 grynspan

This topic came up again recently in dupe #1037.

stmontgomery avatar Mar 25 '25 15:03 stmontgomery