-
Notifications
You must be signed in to change notification settings - Fork 150
Avoid using legacy test data in most (but not all) of SymbolTests.swift #1278
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
base: main
Are you sure you want to change the base?
Avoid using legacy test data in most (but not all) of SymbolTests.swift #1278
Conversation
@@ -53,20 +53,18 @@ class SymbolTests: XCTestCase { | |||
- name: A parameter | |||
- Returns: Return value | |||
""", | |||
articleContent: """ | |||
# Leading heading is ignored |
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 was incorrect. It's not ignored. There's a warning about this but the old test helper never reported that warning.
@Metadata { | ||
@DocumentationExtension(mergeBehavior: override) | ||
} | ||
""" | ||
) | ||
XCTAssert(problems.isEmpty) | ||
XCTAssertEqual(problems.count, 0, "Unexpected problems: \(problems.map(\.diagnostic.summary).sorted())") |
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 is technically not necessary but makes it nicer to debug these tests in the future if they break because of a new diagnostic.
|
||
""" | ||
) | ||
XCTAssert(problems.isEmpty) |
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 was incorrect. There's should be two warnings about curating the module and curating the container type but the old test helper never reported those warnings.
"The article overrides—and removes—the abstract from the in-source documentation") | ||
XCTAssertNil(withArticleOverride.discussion, | ||
"The article overries the discussion.") | ||
"The article overrides the discussion.") |
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 is just fixing typos
""" | ||
) | ||
XCTAssert(problems.isEmpty) |
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 was incorrect. There are two sources of warnings here:
- The redundant
DocumentationExtension(mergeBehavior: append)
raises a warning - The cyclic curation raises two warnings.
The old test helper never reported these kinds of warnings so the test was incorrectly asserting that there were no warnings.
XCTAssertEqual(problems.first?.diagnostic.range?.lowerBound.line, 14) | ||
XCTAssertEqual(problems.first?.diagnostic.range?.lowerBound.column, 18) |
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.
To help test that source location are reported correctly, the new test uses a non-zero row and column for the start of the doc comment. This helps verify that locations are reported in absolute values rather than relative values.
let myFunctionUSR = "s:5MyKit0A5ClassC10myFunctionyyF" | ||
let (_, _, context) = try await testBundleAndContext(copying: "LegacyBundle_DoNotUseInNewTests") { url in | ||
var graph = try JSONDecoder().decode(SymbolGraph.self, from: Data(contentsOf: url.appendingPathComponent("mykit-iOS.symbols.json"))) | ||
|
||
let newDocComment = self.makeLineList( | ||
docComment: """ | ||
A cool API to call. | ||
|
||
- Parameters: | ||
- name: A parameter | ||
- Returns: Return value | ||
""", | ||
articleContent: nil | ||
) | ||
moduleName: nil, | ||
startOffset: .init(line: 0, character: 0), | ||
url: URL(string: "file:///tmp/File.swift")! | ||
) | ||
|
||
// The `guard` statement` below will handle the `nil` case by failing the test and | ||
graph.symbols[myFunctionUSR]?.docComment = newDocComment | ||
|
||
let newGraphData = try JSONEncoder().encode(graph) | ||
try newGraphData.write(to: url.appendingPathComponent("mykit-iOS.symbols.json")) | ||
} |
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.
There was too much in this test that relied on the legacy fixture so rather than fix it I inlined the setup code from the old test helper here.
@@ -1309,6 +1315,8 @@ class SymbolTests: XCTestCase { | |||
"org.swift.docc.Metadata.InvalidPageColorInDocumentationComment", | |||
"org.swift.docc.Metadata.InvalidTitleHeadingInDocumentationComment", | |||
"org.swift.docc.Metadata.InvalidRedirectedInDocumentationComment", | |||
|
|||
"org.swift.docc.unresolvedResource", // For the "test" asset that doesn't exist. |
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.
Like elsewhere, this warning should be there but the old test helper never reported this type of warning.
docCommentLineOffset: Int = 0, | ||
articleContent: String?, | ||
docCommentLineStart: Int = 11, // an arbitrary non-zero start line | ||
extensionFileContent: String?, |
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 renamed this argument because this parameter doesn't represent the content of an article it represents the content of an extension file. The original test helper was confusing in this regard.
@@ -1506,79 +1514,78 @@ class SymbolTests: XCTestCase { | |||
|
|||
// MARK: - Helpers | |||
|
|||
func makeDocumentationNodeForSymbol( | |||
private func makeDocumentationNodeForSymbol( |
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.
There is enough special knowledge in this test file about the specifics of this test data (for example that the symbol is a function, that it has a "name" parameter, and that it has a return value) for this to be useful in other test files. To prevent other test files from accidentally using it, I made it private (same with the other helper below)
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.
would it make sense to push that further to fileprivate
? (are the uses all in this test suite?)
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.
private
is more restrictive than fileprivate
(or equivalent in top-level declarations) but in this case the file only has one XCTestCase class, so it doesn't make any difference in practice.
@swift-ci please test |
@swift-ci please test |
ca311c5
to
805b7cb
Compare
@swift-ci please test |
805b7cb
to
fec0864
Compare
@swift-ci please test |
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.
Nice updates - as a question (not directly related to this PR) - is there a pattern of adding tests to validate warnings and the edge cases for those as they're added? Is that an intention, or kind of a side effect, of this cleanup?
@@ -1506,79 +1514,78 @@ class SymbolTests: XCTestCase { | |||
|
|||
// MARK: - Helpers | |||
|
|||
func makeDocumentationNodeForSymbol( | |||
private func makeDocumentationNodeForSymbol( |
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.
would it make sense to push that further to fileprivate
? (are the uses all in this test suite?)
I would say that it's a little bit of both. Based on a quick regex search we have 239 places in 56 files that do some variation of At the same time, in this specific PR the additional warning validation is largely a side effect of cleaning up the test helper. Because the original test helper was using a legacy fixture that has lots of warnings, the test helper doesn't reported all warnings. Instead it only reported the warnings raised from merging the symbol markup with the extension file markup. This unfortunately doesn't include any "checkers" that run on that markup, doesn't include curation warnings, doesn't include link warnings, doesn't include asset warnings, etc. for that same markup. This led to these test asserting and claiming behaviors that were incorrect. By fixing the test helper so that it reported all warnings, I forced the tests to correct these inaccuracies and deal with these warnings (or correct the markup to caused these warnings). |
Bug/issue #, if applicable:
Summary
This is a test only change to phase out some usage of the "LegacyBundle_DoNotUseInNewTests".
After seeing new code that used
makeDocumentationNodeForSymbol(...)
and noticing that it used "LegacyBundle_DoNotUseInNewTests" internally I decided to update those tests and reduce the usage of that legacy fixture.While doing this I had to make several correction to most of those tests because the original
makeDocumentationNodeForSymbol(...)
implementation incorrectly skipped most warnings in the documentation, resulting in tests that verify 0 problems when there was in fact 2 or 3 problems with the documentation.Dependencies
None
Testing
Nothing in particular. This isn't a user-facing change.
Checklist
Make sure you check off the following items. If they cannot be completed, provide a reason.
AddedUpdated tests./bin/test
script and it succeededUpdated documentation if necessaryNot applicable