Skip to content

[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

Merged
merged 1 commit into from
Apr 12, 2018

Conversation

otaviolima
Copy link
Contributor

No description provided.

@spevans
Copy link
Contributor

spevans commented Apr 8, 2018

@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()
Copy link
Contributor

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.

Copy link
Contributor Author

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.

@otaviolima otaviolima force-pushed the clean-repeated-forceunwrap branch from 33e0d2e to f31c89d Compare April 8, 2018 20:00
@otaviolima
Copy link
Contributor Author

otaviolima commented Apr 9, 2018

~~I don't get why my GPG status is unverified gonna check that and try to fix, if this is a problem.~~~
GPG status fixed.

@otaviolima otaviolima force-pushed the clean-repeated-forceunwrap branch from f31c89d to fa90fef Compare April 9, 2018 14:36
@spevans
Copy link
Contributor

spevans commented Apr 9, 2018

@swift-ci please test

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()
Copy link
Contributor

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 {
Copy link
Contributor

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.

Copy link
Contributor

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.

@otaviolima otaviolima force-pushed the clean-repeated-forceunwrap branch from fa90fef to f861313 Compare April 12, 2018 16:11
@otaviolima
Copy link
Contributor Author

Rebased and added the messages to XCTFail() calls.

@ianpartridge
Copy link
Contributor

@swift-ci please test and merge

@swift-ci swift-ci merged commit 5e8da8d into swiftlang:master Apr 12, 2018
@otaviolima otaviolima deleted the clean-repeated-forceunwrap branch April 13, 2018 07:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants