Xcode 16 Swift Testing: default value for `SourceLocation` when calling helper function
03:51 22 Jun 2024

I have a helper function that looks something like this:

private func test(state: State, against expectedState: State, sourceLocation: SourceLocation) {
    // a bunch of irrelevant checks happening here
    #expect(something == somethingElse, sourceLocation: SourceLocation)
}

XCTAssert & co have the #line and #file values that will set them with default values if you call them. This helps me finding the actual test that failed while calling a helper function in a unit test, instead of all of my tests failing inside of the helper function.

I tried using private func test(state: State, against expectedState: State, sourceLocation = SourceLocation()) { but that only highlights the function definition line where I create the instance.

I'm looking for a way to not having to pass in SourceLocation manually from the calling site, like I could do with #file and #line in XCTAssert.

swift xcode16 swift-testing