Skip to content

Commit

Permalink
Mark XCTFail as @_disfavoredOverload (#46)
Browse files Browse the repository at this point in the history
* fix filename typo

* Add regression test

* Fix regression test
  • Loading branch information
davdroman authored Jan 11, 2023
1 parent a9daebf commit 16b23a2
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 0 deletions.
6 changes: 6 additions & 0 deletions Sources/XCTestDynamicOverlay/XCTFail.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
///
/// - Parameter message: An optional description of the assertion, for inclusion in test
/// results.
@_disfavoredOverload
public func XCTFail(_ message: String = "") {
guard
let currentTestCase = XCTCurrentTestCase,
Expand Down Expand Up @@ -42,6 +43,7 @@
///
/// - Parameter message: An optional description of the assertion, for inclusion in test
/// results.
@_disfavoredOverload
public func XCTFail(_ message: String = "", file: StaticString, line: UInt) {
_XCTFailureHandler(nil, true, "\(file)", line, "\(message.isEmpty ? "failed" : message)", nil)
}
Expand All @@ -57,7 +59,9 @@
// NB: It seems to be safe to import XCTest on Linux
@_exported import func XCTest.XCTFail
#else
@_disfavoredOverload
public func XCTFail(_ message: String = "") {}
@_disfavoredOverload
public func XCTFail(_ message: String = "", file: StaticString, line: UInt) {}
#endif
#else
Expand All @@ -69,6 +73,7 @@
///
/// - Parameter message: An optional description of the assertion, for inclusion in test
/// results.
@_disfavoredOverload
public func XCTFail(_ message: String = "") {}

/// This function generates a failure immediately and unconditionally.
Expand All @@ -79,5 +84,6 @@
///
/// - Parameter message: An optional description of the assertion, for inclusion in test
/// results.
@_disfavoredOverload
public func XCTFail(_ message: String = "", file: StaticString, line: UInt) {}
#endif
17 changes: 17 additions & 0 deletions Tests/XCTestDynamicOverlayTests/XCTFailRegressionTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import XCTest
import XCTestDynamicOverlay

// This ensures `XCTest.XCTFail` takes precedence over `XCTestDynamicOverlay.XCTFail` when both are imported.
//
// For full details, see https://github.com/pointfreeco/swift-dependencies/issues/13
public enum Foo {
func exampleHelper(
file: StaticString = #filePath,
line: UInt = #line
) {
XCTFail(
"This should compile.",
file: file, line: line
)
}
}

0 comments on commit 16b23a2

Please sign in to comment.