-
Notifications
You must be signed in to change notification settings - Fork 1.2k
[gardening] Clean repeated use of force unwrapping on test files #1509
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
[gardening] Clean repeated use of force unwrapping on test files #1509
Conversation
@swift-ci please test |
@@ -31,74 +31,74 @@ class TestISO8601DateFormatter: XCTestCase { | |||
func test_stringFromDate() { | |||
let formatter = DateFormatter() | |||
formatter.dateFormat = "yyyy/MM/dd HH:mm zzz" | |||
let someDateTime = formatter.date(from: "2016/10/08 22:31 GMT") | |||
let someDateTime = formatter.date(from: "2016/10/08 22:31 GMT")! | |||
let isoFormatter = ISO8601DateFormatter() |
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.
This can be enhanced to check for nil
, call XCTFail()
and abort this test here to avoid the unwrap failing.
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.
That is true, I will do it.
33e0d2e
to
f31c89d
Compare
~~I don't get why my GPG status is |
f31c89d
to
fa90fef
Compare
@swift-ci please test |
TestFoundation/TestURL.swift
Outdated
compWithAuthority!.path = "/path/to/file with space.html" | ||
compWithAuthority!.query = "id=23&search=Foo Bar" | ||
guard var compWithAuthority = URLComponents(string: "https://www.swift.org") else { | ||
XCTFail() |
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.
If we're going to replace an assert which very clearly indicates an unexpected nil with a blank XCTFail, at least we should put a message in here explaining what went wrong.
|
||
#if !os(Android) | ||
/* | ||
The following tests cover various cases when changing the .formatOptions property with a different TimeZone set. | ||
*/ | ||
|
||
timeZone = TimeZone(identifier: "PST") | ||
guard let pstTimeZone = TimeZone(identifier: "PST") else { |
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.
In my mind this is one of those cases where the !
is actually clearer than the guard let
. Getting the time zone for the "PST" identifier will not fail. If it does, we're in some kind of odd situation, so we may as well just crash right there and indicate that something has gone wrong.
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 don't think one failing test should abort all of the testing, even if in this case something fundamental like "PST" is missing. At least with XCTFail()
better failure messaging can be provided (which should be fixed here). We don't consider any failing XCTAssert*()
should lead to a fatalError
.
fa90fef
to
f861313
Compare
Rebased and added the messages to |
@swift-ci please test and merge |
No description provided.