Skip to content

Commit e727af0

Browse files
committed
Address my own feedback
1 parent b1c2dbd commit e727af0

File tree

3 files changed

+10
-20
lines changed

3 files changed

+10
-20
lines changed

Documentation/Proposals/NNNN-return-errors-from-expect-throws.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ is not statically available. The problematic overloads will also be deprecated:
7676
sourceLocation: SourceLocation = #_sourceLocation,
7777
performing expression: () async throws -> R
7878
-) = #externalMacro(module: "TestingMacros", type: "ExpectMacro") where E: Error
79-
+) -> E? = #externalMacro(module: "TestingMacros", type: "ExpectMacro") where E: Error
79+
+) -> E? where E: Error
8080

8181
+@discardableResult
8282
@freestanding(expression) public macro require<E, R>(
@@ -85,7 +85,7 @@ is not statically available. The problematic overloads will also be deprecated:
8585
sourceLocation: SourceLocation = #_sourceLocation,
8686
performing expression: () async throws -> R
8787
-) = #externalMacro(module: "TestingMacros", type: "RequireMacro") where E: Error
88-
+) -> E = #externalMacro(module: "TestingMacros", type: "RequireThrowsMacro") where E: Error
88+
+) -> E where E: Error
8989

9090
+@discardableResult
9191
@freestanding(expression) public macro expect<E, R>(
@@ -94,7 +94,7 @@ is not statically available. The problematic overloads will also be deprecated:
9494
sourceLocation: SourceLocation = #_sourceLocation,
9595
performing expression: () async throws -> R
9696
-) = #externalMacro(module: "TestingMacros", type: "ExpectMacro") where E: Error & Equatable
97-
+) -> E? = #externalMacro(module: "TestingMacros", type: "ExpectMacro") where E: Error & Equatable
97+
+) -> E? where E: Error & Equatable
9898

9999
+@discardableResult
100100
@freestanding(expression) public macro require<E, R>(
@@ -103,7 +103,7 @@ is not statically available. The problematic overloads will also be deprecated:
103103
sourceLocation: SourceLocation = #_sourceLocation,
104104
performing expression: () async throws -> R
105105
-) = #externalMacro(module: "TestingMacros", type: "RequireMacro") where E: Error & Equatable
106-
+) -> E = #externalMacro(module: "TestingMacros", type: "RequireMacro") where E: Error & Equatable
106+
+) -> E where E: Error & Equatable
107107

108108
+@available(*, deprecated, message: "Examine the result of '#expect(throws:)' instead.")
109109
+@discardableResult

Sources/Testing/Support/Additions/ResultAdditions.swift

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ extension Result {
3131
///
3232
/// - Warning: This function is used to implement the `#expect()` and
3333
/// `#require()` macros. Do not call it directly.
34-
@inlinable public func __expected<T>() -> Success where Success == T? {
34+
@discardableResult @inlinable public func __expected<T>() -> Success where Success == T? {
3535
try? get()
3636
}
3737

@@ -42,27 +42,15 @@ extension Result {
4242
/// `__check()` function family so that we can support uninhabited types and
4343
/// "soft" failures.
4444
///
45-
/// - Warning: This function is used to implement the `#expect()` and
46-
/// `#require()` macros. Do not call it directly.
47-
@inlinable public func __required<T>() throws -> T where Success == T? {
48-
try get()!
49-
}
50-
51-
/// Handle this instance as if it were returned from a call to `#require()`.
52-
///
53-
/// This overload of `__require()` is used by `#require(throws:)`. It has
54-
/// special handling for a `nil` result so that `Never.self` (which can't be
55-
/// instantiated) can be used as the error type in the macro call.
56-
///
57-
/// If the value really is `nil` (i.e. we're dealing with `Never`), the
45+
/// If the value really is `nil` (e.g. we're dealing with `Never`), the
5846
/// testing library throws an error representing an issue of kind
5947
/// ``Issue/Kind-swift.enum/apiMisused``.
6048
///
6149
/// - Warning: This function is used to implement the `#expect()` and
6250
/// `#require()` macros. Do not call it directly.
63-
public func __required<T>() throws -> T where T: Error, Success == T? {
51+
@discardableResult public func __required<T>() throws -> T where Success == T? {
6452
guard let result = try get() else {
65-
throw APIMisuseError(description: "Could not unwrap 'nil' value of type Optional<\(T.self)>. Consider using #expect(throws:) instead of #require(throws:) here.")
53+
throw APIMisuseError(description: "Could not unwrap 'nil' value of type Optional<\(T.self)>. Consider using #expect() instead of #require() here.")
6654
}
6755
return result
6856
}

Sources/TestingMacros/Support/Additions/MacroExpansionContextAdditions.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ extension MacroExpansionContext {
9090
/// - Warning: This functionality is not part of the public interface of the
9191
/// testing library. It may be modified or removed in a future update.
9292
var areWarningsSuppressed: Bool {
93+
#if DEBUG
9394
for lexicalContext in self.lexicalContext {
9495
guard let lexicalContext = lexicalContext.asProtocol((any WithAttributesSyntax).self) else {
9596
continue
@@ -103,6 +104,7 @@ extension MacroExpansionContext {
103104
}
104105
}
105106
}
107+
#endif
106108
return false
107109
}
108110

0 commit comments

Comments
 (0)