Skip to content
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

[HaveCountMatcher] Implement Shorter Failure Message #310

Merged
merged 1 commit into from
Jul 5, 2016

Conversation

Ben-G
Copy link
Contributor

@Ben-G Ben-G commented Jun 22, 2016

As discussed in #308 I took a shot at implementing a new failure message for the haveCount matcher.

I've added a new prettyCollectionType with two overloads to print nicer type information for Objective-C types. This way the failure message will mention NSArray instead of __NSArrayI.

Not sure if there's a better approach for this; or if you consider it useful at all. Would love to hear your feedback!

@briancroom
Copy link
Member

@Ben-G Thanks a lot for taking the time to open this discussion and put the PR together! I think there can be a lot of value in these kinds of micro-optimizations, and the screenshots you posted in #308 sure do illustrate the issue well.

I do have some concern about simply dropping the mored detailed information altogether. When I'm looking at the console output of a failed CI run, I almost always wish for more data about the failure rather than less! 😀 I think I'd rather see Nimble move in the direction of having a shorter failure of the summary as the first line, and including extra details afterwards. A little experimentation seems to indicate that the inline failure highlights in the Xcode source editor only include the first line of the message, with the rest available either in the console log, or test build log.

What if we were to introduce the concept of "extra details" to the FailureMessage type which would be appended on a separate line when recording the failure. The haveCount message could then look something like:

expected to have Array<Int> with count 1, got 3
Actual value: [1, 2, 3]

@Ben-G
Copy link
Contributor Author

Ben-G commented Jun 22, 2016

@briancroom You're bringing up a good point!

I touched on this third option in #308 as well. We could conserve the details but simply move them to the end of the message so that we get the quick lookup in the source editor + additional detail in CI and other scenarios.

What if we were to introduce the concept of "extra details" to the FailureMessage type which would be appended on a separate line when recording the failure. The haveCount message could then look something like:
expected to have Array with count 1, got 3
Actual value: [1, 2, 3]

Intuitively this sounds great! But would love to hear other's opinions on this.

@briancroom
Copy link
Member

Calling all @Quick/contributors 😀

@ashfurrow
Copy link
Member

The compromise of moving details to the end sounds good to me, 👍

@Ben-G
Copy link
Contributor Author

Ben-G commented Jun 28, 2016

@briancroom @ashfurrow I just took a look at this again. There's code in place that trims whitespace characters and newlines (https://github.com/Quick/Nimble/blob/master/Sources/Nimble/FailureMessage.swift#L36-L41) which makes it difficult to implement this is as a small change.

I can set the postfixActual value on FailureMessage but because of the lack of newlines / spacing the formatting is off.

Seems like more changes would be required to support this. Probably not worth it? What do you think?

@ashfurrow
Copy link
Member

@Ben-G what does the message look like, in terms of poor formatting?

@Ben-G
Copy link
Contributor Author

Ben-G commented Jun 29, 2016

@ashfurrow Ah, once again lacking a screenshot. Here we go:

screen shot 2016-06-29 at 8 57 15 am

@ashfurrow
Copy link
Member

That's a tricky one, a bit outside my wheelhouse I'm afraid.

@Ben-G
Copy link
Contributor Author

Ben-G commented Jun 29, 2016

@ashfurrow The blame information on https://github.com/Quick/Nimble/blob/master/Sources/Nimble/FailureMessage.swift#L36-L41suggests that @briancroom might now why whitespaces / newlines are currently removed and if it is possible/desirable to change that.

Thanks a lot for trying to help! 👍

@briancroom
Copy link
Member

I don't have a lot of context on the motivation for stripping newlines, but I'd wager that it is to help prevent failure messages from bloating too much when they contain descriptions of expected and actual values which are formatted to take a lot of vertical space. I've found it's easy to lose track of the failure message itself when the value descriptions are too overwhelming.

My thought here is that we should introduce a new optional String property on FailureMessage (extendedMessage or similar, perhaps?), which would get appended to the final string after a newline. How does that sound?

@Ben-G
Copy link
Contributor Author

Ben-G commented Jun 30, 2016

@briancroom sounds good to me!

@Ben-G Ben-G force-pushed the benji/new-havecount-message branch 4 times, most recently from adc7c58 to dcaf680 Compare June 30, 2016 02:30
@Ben-G
Copy link
Contributor Author

Ben-G commented Jun 30, 2016

@briancroom I rewrote the the commit based on your latest suggestion. Let me know what you think of the result!

@briancroom
Copy link
Member

I feel pretty good about this! Thanks for sticking with it @Ben-G

The Linux CI failure is because NSHashTable isn't available in Corelibs-Foundation. Could you wrap that entry in the switch with a #if _runtime(_ObjC) conditional?

@Ben-G Ben-G force-pushed the benji/new-havecount-message branch from dcaf680 to 436328a Compare July 1, 2016 16:50
@Ben-G
Copy link
Contributor Author

Ben-G commented Jul 1, 2016

@briancroom updated and linux build is passing now!

Unfortunately I need to move the runtime check out of the switch statement to avoid a compile error.

@briancroom
Copy link
Member

Excellent! Having seen no dissent to this approach in the last days, I'm really happy to merge this! Thanks again for this well thought-through contribution @Ben-G

@briancroom briancroom merged commit de76ce8 into Quick:master Jul 5, 2016
Megal pushed a commit to Megal/Nimble that referenced this pull request Jul 31, 2019
[HaveCountMatcher] Implement Shorter Failure Message
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.

3 participants