-
-
Notifications
You must be signed in to change notification settings - Fork 32
Migrate to Swift Testing #99
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
dimitribouniol
merged 12 commits into
brokenhandsio:main
from
M7md-Ebrahim:swift_testing
Feb 4, 2025
Merged
Changes from 2 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
a963df3
Migrate to Swift Testing
M7md-Ebrahim 83373ae
Merge branch 'swift-server:main' into swift_testing
M7md-Ebrahim 86ff09f
Moved CI workflows to swiftlang's github workflows
dimitribouniol dcfe6c1
Removed explicit yamllint disabling
dimitribouniol fa0d67f
Removed all workflows for Swift 5
dimitribouniol e0294ea
Replaced soundness script with the official check
dimitribouniol 97d8df3
Updated the minimum tools version to 6.0
dimitribouniol c45be97
Updated uses of `any` to be explicit
dimitribouniol 3df7bba
Updated throws to specify types when possible
dimitribouniol b98e556
Migrate to Swift Testing
M7md-Ebrahim 85c1c6c
Replace assertThrowsError with '#expect(throws:)'
M7md-Ebrahim 3869900
Merge branch 'swift_testing' of https://github.com/M7md-Ebrahim/swift…
M7md-Ebrahim File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,22 +11,21 @@ | |
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
import XCTest | ||
import Testing | ||
import WebAuthn | ||
|
||
func assertThrowsError<T, E: Error>( | ||
|
||
_ expression: @autoclosure () throws -> T, | ||
_ message: @autoclosure () -> String = "", | ||
file: StaticString = #filePath, | ||
line: UInt = #line, | ||
sourceLocation: SourceLocation = #_sourceLocation, | ||
_ errorHandler: (_ error: E) -> Void = { _ in } | ||
) { | ||
do { | ||
_ = try expression() | ||
XCTFail(message(), file: file, line: line) | ||
Issue.record("\(message())", sourceLocation: sourceLocation) | ||
} catch { | ||
guard let error = error as? E else { | ||
XCTFail(""" | ||
Issue.record(""" | ||
Error was thrown, but didn't match expected type '\(E.self)'. | ||
Got error of type '\(type(of: error))'. | ||
Error: \(error) | ||
|
@@ -40,11 +39,10 @@ func assertThrowsError<T, E: Error>( | |
func assertThrowsError<T, E: Error & Equatable>( | ||
_ expression: @autoclosure () throws -> T, | ||
_ message: @autoclosure () -> String = "", | ||
file: StaticString = #filePath, | ||
line: UInt = #line, | ||
sourceLocation: SourceLocation = #_sourceLocation, | ||
expect: E | ||
) { | ||
try assertThrowsError(expression(), message(), file: file, line: line) { error in | ||
XCTAssertEqual(error, expect, message(), file: file, line: line) | ||
try assertThrowsError(expression(), message(), sourceLocation: sourceLocation) { error in | ||
#expect(error == expect, Comment("\(message())"), sourceLocation: sourceLocation) | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can probably drop this helper altogether now, can't we?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this helper is beneficial. Why would we want to drop it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doesn't swift Testing have a new
#expect(throws: ...) { ... }
that would replace this helper?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It does yes
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But doesn’t this work the same as XCTAssertThrowsError?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great, I’ll work on that
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I assume these were there because XCTAssert didn't handle async code very well, so this abstracted over that with a single signature