Skip to content

Add regression test for XCTAssert* failure messages #39

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

Conversation

briancroom
Copy link
Contributor

This backfills tests for the behavior introduced in #22.

It also fixes a minor formatting regression introduced in e5cf2f4 in which the output of XCTAssertNil incorrectly prints the actual value as an optional.

@@ -267,7 +267,7 @@ public func XCTAssertNil(@autoclosure expression: () -> Any?, @autoclosure _ mes
if value == nil {
return .Success
} else {
return .ExpectedFailure("\"\(value)\"")
return .ExpectedFailure("\"\(value!)\"")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we reverse the conditional here, to avoid the !? Exclamation points make me nervous. 😅

How about:

if let value = expression() {
    return .ExpectedFailure("\"\(value)\"")
} else {
    return .Success
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had initially chosen to not reorder it that way because I liked the symmetry of the conditionals between the various assertion functions, but I have no problem flipping it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just reverted it to the original ordering at @eschaton's request. AFAIK there is no clean way to avoid the force-unwrap when doing the nil check first like this. Using guard could allow keeping the ordering the same, but I feel it be a pretty bad abuse of the expected semantics of that keyword.

Is there an alternative I'm overlooking? @modocache

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fine with me! I defer to him. 😄

@briancroom briancroom force-pushed the test_xctassert_failure_messages branch from c86ff1b to d02e208 Compare January 14, 2016 02:32
@briancroom
Copy link
Contributor Author

Rebased and fixed up now.

@eschaton
Copy link
Contributor

I strongly prefer the if predicate to “match” the intent of the assertion; that’s why I wrote them as if _ { return .Success } else { return .ExpectedFailure(“_”) }.

@briancroom briancroom force-pushed the test_xctassert_failure_messages branch from d02e208 to 32d2a2b Compare January 14, 2016 04:42
mike-ferris pushed a commit that referenced this pull request Jan 19, 2016
Add regression test for XCTAssert* failure messages
@mike-ferris mike-ferris merged commit 0970216 into swiftlang:master Jan 19, 2016
@briancroom briancroom deleted the test_xctassert_failure_messages branch January 22, 2016 12:47
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.

4 participants