Skip to content

Commit 16b23a2

Browse files
authored
Mark XCTFail as @_disfavoredOverload (#46)
* fix filename typo * Add regression test * Fix regression test
1 parent a9daebf commit 16b23a2

File tree

3 files changed

+23
-0
lines changed

3 files changed

+23
-0
lines changed

Sources/XCTestDynamicOverlay/XCTFail.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
///
1111
/// - Parameter message: An optional description of the assertion, for inclusion in test
1212
/// results.
13+
@_disfavoredOverload
1314
public func XCTFail(_ message: String = "") {
1415
guard
1516
let currentTestCase = XCTCurrentTestCase,
@@ -42,6 +43,7 @@
4243
///
4344
/// - Parameter message: An optional description of the assertion, for inclusion in test
4445
/// results.
46+
@_disfavoredOverload
4547
public func XCTFail(_ message: String = "", file: StaticString, line: UInt) {
4648
_XCTFailureHandler(nil, true, "\(file)", line, "\(message.isEmpty ? "failed" : message)", nil)
4749
}
@@ -57,7 +59,9 @@
5759
// NB: It seems to be safe to import XCTest on Linux
5860
@_exported import func XCTest.XCTFail
5961
#else
62+
@_disfavoredOverload
6063
public func XCTFail(_ message: String = "") {}
64+
@_disfavoredOverload
6165
public func XCTFail(_ message: String = "", file: StaticString, line: UInt) {}
6266
#endif
6367
#else
@@ -69,6 +73,7 @@
6973
///
7074
/// - Parameter message: An optional description of the assertion, for inclusion in test
7175
/// results.
76+
@_disfavoredOverload
7277
public func XCTFail(_ message: String = "") {}
7378

7479
/// This function generates a failure immediately and unconditionally.
@@ -79,5 +84,6 @@
7984
///
8085
/// - Parameter message: An optional description of the assertion, for inclusion in test
8186
/// results.
87+
@_disfavoredOverload
8288
public func XCTFail(_ message: String = "", file: StaticString, line: UInt) {}
8389
#endif
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import XCTest
2+
import XCTestDynamicOverlay
3+
4+
// This ensures `XCTest.XCTFail` takes precedence over `XCTestDynamicOverlay.XCTFail` when both are imported.
5+
//
6+
// For full details, see https://github.com/pointfreeco/swift-dependencies/issues/13
7+
public enum Foo {
8+
func exampleHelper(
9+
file: StaticString = #filePath,
10+
line: UInt = #line
11+
) {
12+
XCTFail(
13+
"This should compile.",
14+
file: file, line: line
15+
)
16+
}
17+
}

0 commit comments

Comments
 (0)