You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When developing rules and fixing bugs, trying to correlate the test output with the code can be difficult. It would be nicer if incorrectly triggered or ignored examples were highlighted in Xcode like other test failures.
This would be possible with the technique I describe in this blog post: XCTest Line by Line
As a quick sketch, it would transform the test case declarations from this:
The addition of the Example wrapper struct would capture the file and line number, which would be passed to the XCTest methods, ensuring that failures are reflected on the correct line. The initializer of the Example struct would have to look like this:
// "example" parameter could also be a StaticString if you want to encourage
// passing string literals to aid in debugging
init(_example:String,file:StaticString=#file,line:Uint=#line)
I'd be interested in contributing a PR to address this.
Ohh, interesting. Do you know where it is/was? I can look into fixing it up. It would be a real quality-of-life improvement for people doing small fixes who aren't as familiar with the code base as a whole.
I'm already working on it, but it turns out there are a ton of rules with weirdly formatted strings, which makes some of this a little tricky. Thoughts on converting them all to multiline strings as part of the conversion effort? I'm pretty sure that either way, this will wreak havoc on any open PRs that substantially change any examples :\
I had a cool idea of using ExpressibleByStringLiteral to provide a compatibility mode for contributors, which would fail the tests (instead of failing the build) until they've wrapped their examples in Example(...), but that doesn't work for the hundreds or thousands of tests that use old-style "foo\n" + "bar" string concatenations.
That's why I'm currently investigating SwiftRewriter to see if it's worth building some kind of utility to do the conversion to multiline strings, but the answer is almost definitely "it is not worth it."
Do you know why so many triggering/non-triggering examples in SwiftLint have a \n at the end of them? Is it required? Wondering if I should clean those up as part of this work. It would certainly clear up some visual noise in the test strings.
Activity
jpsim commentedon Jan 13, 2020
We actually already have this, although it might have stopped working a while back.
ZevEisenberg commentedon Jan 13, 2020
Ohh, interesting. Do you know where it is/was? I can look into fixing it up. It would be a real quality-of-life improvement for people doing small fixes who aren't as familiar with the code base as a whole.
jpsim commentedon Jan 13, 2020
Turns out we do this for the integration tests: https://github.com/realm/SwiftLint/blob/0.38.2/Tests/SwiftLintFrameworkTests/IntegrationTests.swift#L26-L28
But we don't do this for the rule examples. This would be a lovely addition.
ZevEisenberg commentedon Jan 13, 2020
I'm already working on it, but it turns out there are a ton of rules with weirdly formatted strings, which makes some of this a little tricky. Thoughts on converting them all to multiline strings as part of the conversion effort? I'm pretty sure that either way, this will wreak havoc on any open PRs that substantially change any examples :\
I had a cool idea of using
ExpressibleByStringLiteralto provide a compatibility mode for contributors, which would fail the tests (instead of failing the build) until they've wrapped their examples inExample(...), but that doesn't work for the hundreds or thousands of tests that use old-style"foo\n" + "bar"string concatenations.That's why I'm currently investigating SwiftRewriter to see if it's worth building some kind of utility to do the conversion to multiline strings, but the answer is almost definitely "it is not worth it."
ZevEisenberg commentedon Jan 14, 2020
Do you know why so many triggering/non-triggering examples in SwiftLint have a
\nat the end of them? Is it required? Wondering if I should clean those up as part of this work. It would certainly clear up some visual noise in the test strings.