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

Discourage using unrealistic catalog inputs in tests #1106

Merged
Show file tree
Hide file tree
Changes from 17 commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
47c33f7
Discourage future use of the "TestBundle" by renaming it.
d-ronnqvist Nov 22, 2024
d144a67
Update tests that don't need a catalog input to use an empty context.
d-ronnqvist Nov 22, 2024
880c7f1
Update `SymbolGraphRelationshipsBuilderTests` to not load any catalog
d-ronnqvist Nov 22, 2024
9e834e8
Update name of test specifically about the unrealistic test catalog
d-ronnqvist Nov 22, 2024
7f9e204
Create minimal catalog for final remaining `ChoiceTests` test case
d-ronnqvist Nov 22, 2024
b5d32e8
Create minimal catalog for final remaining `VolumeTests` test case
d-ronnqvist Nov 22, 2024
9c18643
Avoid referencing an input catalog for image size test
d-ronnqvist Nov 22, 2024
04881aa
Create minimal catalog for `NonInclusiveLanguageCheckerTests`
d-ronnqvist Nov 22, 2024
36fb640
Create minimal catalog for `DiagnosticTests`
d-ronnqvist Nov 22, 2024
95c94ce
Create minimal catalogs for some `DocumentationContextTests`
d-ronnqvist Nov 22, 2024
6c0a6f2
Update more tests that don't need a catalog input to use an empty con…
d-ronnqvist Nov 22, 2024
4a56cda
Create minimal catalogs for more `DocumentationContextTests`
d-ronnqvist Nov 22, 2024
0bba001
Create minimal catalogs for some `VideoMediaTests`
d-ronnqvist Nov 25, 2024
5029f23
Create minimal catalogs for two `SemaToRenderNodeTests`
d-ronnqvist Nov 25, 2024
164b1c7
Create minimal catalogs for a few more `DocumentationContextTests`
d-ronnqvist Nov 25, 2024
87758ba
Load test catalogs from in-memory file system in many more tests
d-ronnqvist Nov 25, 2024
27de70a
Merge branch 'main' into discourage-using-unrealistic-test-bundle
d-ronnqvist Dec 5, 2024
86ce80f
Rename legacy test bundle again
d-ronnqvist Dec 5, 2024
1756407
Resolve some warnings in tests about using `var` for unmutated action
d-ronnqvist Dec 5, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions Tests/SwiftDocCTests/Benchmark/ExternalTopicsHashTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class ExternalTopicsGraphHashTests: XCTestCase {

func testNoMetricAddedIfNoExternalTopicsAreResolved() throws {
// Load bundle without using external resolvers
let (_, context) = try testBundleAndContext(named: "TestBundle")
let (_, context) = try testBundleAndContext(named: "DoNotUseInNewTests")
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: Any thoughts on something more explicit like LegacyBundle_DoNotUseInNewTests to make it clearer that this is a test bundle?

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 like 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.

Updated in 86ce80f

XCTAssertTrue(context.externallyResolvedLinks.isEmpty)

// Try adding external topics metrics
Expand All @@ -55,7 +55,7 @@ class ExternalTopicsGraphHashTests: XCTestCase {

// Add external links and verify the checksum is always the same
let hashes: [String] = try (0...10).map { _ -> MetricValue? in
let (_, _, context) = try testBundleAndContext(copying: "TestBundle", externalResolvers: [externalResolver.bundleID: externalResolver]) { url in
let (_, _, context) = try testBundleAndContext(copying: "DoNotUseInNewTests", externalResolvers: [externalResolver.bundleID: externalResolver]) { url in
try """
# ``SideKit/SideClass``

Expand Down Expand Up @@ -93,7 +93,7 @@ class ExternalTopicsGraphHashTests: XCTestCase {

// Add external links and verify the checksum is always the same
let hashes: [String] = try (0...10).map { _ -> MetricValue? in
let (_, _, context) = try testBundleAndContext(copying: "TestBundle", externalResolvers: [externalResolver.bundleID: externalResolver], externalSymbolResolver: externalSymbolResolver) { url in
let (_, _, context) = try testBundleAndContext(copying: "DoNotUseInNewTests", externalResolvers: [externalResolver.bundleID: externalResolver], externalSymbolResolver: externalSymbolResolver) { url in
try """
# ``SideKit/SideClass``

Expand Down Expand Up @@ -131,7 +131,7 @@ class ExternalTopicsGraphHashTests: XCTestCase {
let externalResolver = self.externalResolver

// Load a bundle with external links
let (_, _, context) = try testBundleAndContext(copying: "TestBundle", externalResolvers: [externalResolver.bundleID: externalResolver]) { url in
let (_, _, context) = try testBundleAndContext(copying: "DoNotUseInNewTests", externalResolvers: [externalResolver.bundleID: externalResolver]) { url in
try """
# ``SideKit/SideClass``

Expand Down
6 changes: 3 additions & 3 deletions Tests/SwiftDocCTests/Benchmark/TopicGraphHashTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import XCTest
class TopicGraphHashTests: XCTestCase {
func testTopicGraphSameHash() throws {
let hashes: [String] = try (0...10).map { _ -> MetricValue? in
let (_, context) = try testBundleAndContext(named: "TestBundle")
let (_, context) = try testBundleAndContext(named: "DoNotUseInNewTests")
let testBenchmark = Benchmark()
benchmark(add: Benchmark.TopicGraphHash(context: context), benchmarkLog: testBenchmark)
return testBenchmark.metrics[0].result
Expand All @@ -32,7 +32,7 @@ class TopicGraphHashTests: XCTestCase {
func testTopicGraphChangedHash() throws {
// Verify that the hash changes if we change the topic graph
let initialHash: String
let (_, context) = try testBundleAndContext(named: "TestBundle")
let (_, context) = try testBundleAndContext(named: "DoNotUseInNewTests")

do {
let testBenchmark = Benchmark()
Expand Down Expand Up @@ -88,7 +88,7 @@ class TopicGraphHashTests: XCTestCase {
"/externally/resolved/path/to/article2": .success(.init(referencePath: "/externally/resolved/path/to/article2")),
]

let (_, bundle, context) = try testBundleAndContext(copying: "TestBundle", externalResolvers: [
let (_, bundle, context) = try testBundleAndContext(copying: "DoNotUseInNewTests", externalResolvers: [
"com.external.testbundle" : resolver
]) { url in
// Add external links to the MyKit Topics.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import XCTest
import Markdown
@testable import SwiftDocC
import SwiftDocCTestUtilities

class NonInclusiveLanguageCheckerTests: XCTestCase {

Expand Down Expand Up @@ -167,9 +168,9 @@ func aBlackListedFunc() {
}

private let nonInclusiveContent = """
# ``SideKit``
# Some root page

SideKit module root symbol. And here is a ~~whitelist~~:
Some custom root page. And here is a ~~whitelist~~:

- item one
- item two
Expand All @@ -178,11 +179,12 @@ func aBlackListedFunc() {

func testDisabledByDefault() throws {
// Create a test bundle with some non-inclusive content.
let (_, _, context) = try testBundleAndContext(copying: "TestBundle", diagnosticEngine: .init(filterLevel: .error)) { url in
try self.nonInclusiveContent.write(to: url.appendingPathComponent("documentation").appendingPathComponent("sidekit.md"), atomically: true, encoding: .utf8)
}
let catalog = Folder(name: "unit-test.docc", content: [
TextFile(name: "Root.md", utf8Content: nonInclusiveContent)
])
let (_, context) = try loadBundle(catalog: catalog)

XCTAssertEqual(context.problems.count, 0)
XCTAssertEqual(context.problems.count, 0) // Non-inclusive content is an info-level diagnostic, so it's filtered out.
}

func testEnablingTheChecker() throws {
Expand All @@ -196,9 +198,12 @@ func aBlackListedFunc() {
]

for (severity, enabled) in expectations {
let (_, _, context) = try testBundleAndContext(copying: "TestBundle", diagnosticEngine: .init(filterLevel: severity)) { url in
try self.nonInclusiveContent.write(to: url.appendingPathComponent("documentation").appendingPathComponent("sidekit.md"), atomically: true, encoding: .utf8)
}
let catalog = Folder(name: "unit-test.docc", content: [
TextFile(name: "Root.md", utf8Content: nonInclusiveContent)
])
var configuration = DocumentationContext.Configuration()
configuration.externalMetadata.diagnosticLevel = severity
let (_, context) = try loadBundle(catalog: catalog, diagnosticEngine: .init(filterLevel: severity), configuration: configuration)

// Verify that checker diagnostics were emitted or not, depending on the diagnostic level set.
XCTAssertEqual(context.problems.contains(where: { $0.diagnostic.identifier == "org.swift.docc.NonInclusiveLanguage" }), enabled)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import XCTest

class DocumentationContextConverterTests: XCTestCase {
func testRenderNodesAreIdentical() throws {
let (bundle, context) = try testBundleAndContext(named: "TestBundle")
let (bundle, context) = try testBundleAndContext(named: "DoNotUseInNewTests")

// We'll use this to convert nodes ad-hoc
let perNodeConverter = DocumentationNodeConverter(bundle: bundle, context: context)
Expand All @@ -41,7 +41,7 @@ class DocumentationContextConverterTests: XCTestCase {
}

func testSymbolLocationsAreOnlyIncludedWhenRequested() throws {
let (bundle, context) = try testBundleAndContext(named: "TestBundle")
let (bundle, context) = try testBundleAndContext(named: "DoNotUseInNewTests")
let renderContext = RenderContext(documentationContext: context, bundle: bundle)

let fillIntroducedSymbolNode = try XCTUnwrap(
Expand Down Expand Up @@ -71,7 +71,7 @@ class DocumentationContextConverterTests: XCTestCase {
}

func testSymbolAccessLevelsAreOnlyIncludedWhenRequested() throws {
let (bundle, context) = try testBundleAndContext(named: "TestBundle")
let (bundle, context) = try testBundleAndContext(named: "DoNotUseInNewTests")
let renderContext = RenderContext(documentationContext: context, bundle: bundle)

let fillIntroducedSymbolNode = try XCTUnwrap(
Expand Down
2 changes: 1 addition & 1 deletion Tests/SwiftDocCTests/Converter/RenderContextTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import XCTest

class RenderContextTests: XCTestCase {
func testCreatesRenderReferences() throws {
let (bundle, context) = try testBundleAndContext(named: "TestBundle")
let (bundle, context) = try testBundleAndContext(named: "DoNotUseInNewTests")

let renderContext = RenderContext(documentationContext: context, bundle: bundle)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ class TopicRenderReferenceEncoderTests: XCTestCase {
/// Verifies that when JSON encoder should sort keys, the custom render reference cache
/// respects that setting and prints the referencs in alphabetical order.
func testSortedReferences() throws {
let (bundle, context) = try testBundleAndContext(named: "TestBundle")
let (bundle, context) = try testBundleAndContext(named: "DoNotUseInNewTests")
let converter = DocumentationNodeConverter(bundle: bundle, context: context)

// Create a JSON encoder
Expand Down Expand Up @@ -218,7 +218,7 @@ class TopicRenderReferenceEncoderTests: XCTestCase {

// Verifies that there is no extra comma at the end of the references list.
func testRemovesLastReferencesListDelimiter() throws {
let (bundle, context) = try testBundleAndContext(named: "TestBundle")
let (bundle, context) = try testBundleAndContext(named: "DoNotUseInNewTests")
let converter = DocumentationNodeConverter(bundle: bundle, context: context)

// Create a JSON encoder
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ class DiagnosticConsoleWriterDefaultFormattingTest: XCTestCase {
let summary = "Test diagnostic summary"
let explanation = "Test diagnostic explanation."
let baseURL = Bundle.module.url(
forResource: "TestBundle", withExtension: "docc", subdirectory: "Test Bundles")!
forResource: "DoNotUseInNewTests", withExtension: "docc", subdirectory: "Test Bundles")!
let source = baseURL.appendingPathComponent("TestTutorial.tutorial")
let range = SourceLocation(line: 44, column: 59, source: source)..<SourceLocation(line: 44, column: 138, source: source)

Expand Down Expand Up @@ -307,7 +307,7 @@ class DiagnosticConsoleWriterDefaultFormattingTest: XCTestCase {
let summary = "Test diagnostic summary"
let explanation = "Test diagnostic explanation."
let baseURL = Bundle.module.url(
forResource: "TestBundle", withExtension: "docc", subdirectory: "Test Bundles")!
forResource: "DoNotUseInNewTests", withExtension: "docc", subdirectory: "Test Bundles")!
let source = baseURL.appendingPathComponent("TestTutorial.tutorial")
let diagnosticRange = SourceLocation(line: 44, column: 59, source: source)..<SourceLocation(line: 44, column: 138, source: source)
let diagnostic = Diagnostic(source: source, severity: .warning, range: diagnosticRange, identifier: identifier, summary: summary, explanation: explanation)
Expand Down
7 changes: 5 additions & 2 deletions Tests/SwiftDocCTests/Diagnostics/DiagnosticTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,15 @@ class DiagnosticTests: XCTestCase {

/// Test offsetting diagnostic ranges
func testOffsetDiagnostics() throws {
let (bundle, context) = try testBundleAndContext(named: "TestBundle")
let (bundle, context) = try loadBundle(catalog: Folder(name: "unit-test.docc", content: [
JSONFile(name: "SomeModuleName.symbols.json", content: makeSymbolGraph(moduleName: "SomeModuleName"))
]))

let content = "Test a ``Reference`` in a sentence."
let markup = Document(parsing: content, source: URL(string: "/tmp/foo.symbols.json"), options: .parseSymbolLinks)

var resolver = ReferenceResolver(context: context, bundle: bundle, rootReference: ResolvedTopicReference(bundleID: "org.swift.docc.example", path: "/documentation/MyKit", sourceLanguage: .swift))
let moduleReference = try XCTUnwrap(context.soleRootModuleReference)
var resolver = ReferenceResolver(context: context, bundle: bundle, rootReference: moduleReference)

// Resolve references
_ = resolver.visitMarkup(markup)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1383,7 +1383,7 @@ class ConvertServiceTests: XCTestCase {

func testConvertAllPagesForOnDiskContent() throws {
let testBundleURL = Bundle.module.url(
forResource: "TestBundle", withExtension: "docc", subdirectory: "Test Bundles")!
forResource: "DoNotUseInNewTests", withExtension: "docc", subdirectory: "Test Bundles")!

let request = ConvertRequest(
bundleInfo: testBundleInfo,
Expand Down Expand Up @@ -1444,7 +1444,7 @@ class ConvertServiceTests: XCTestCase {

func testConvertSomeSymbolsAndSomeArticlesForOnDiskContent() throws {
let testBundleURL = Bundle.module.url(
forResource: "TestBundle", withExtension: "docc", subdirectory: "Test Bundles")!
forResource: "DoNotUseInNewTests", withExtension: "docc", subdirectory: "Test Bundles")!

let request = ConvertRequest(
bundleInfo: testBundleInfo,
Expand All @@ -1468,7 +1468,7 @@ class ConvertServiceTests: XCTestCase {

func testConvertNoSymbolsAndNoArticlesForOnDiskContent() throws {
let testBundleURL = Bundle.module.url(
forResource: "TestBundle", withExtension: "docc", subdirectory: "Test Bundles")!
forResource: "DoNotUseInNewTests", withExtension: "docc", subdirectory: "Test Bundles")!

let request = ConvertRequest(
bundleInfo: testBundleInfo,
Expand All @@ -1495,7 +1495,7 @@ class ConvertServiceTests: XCTestCase {
""")
#else
let (testBundleURL, _, _) = try testBundleAndContext(
copying: "TestBundle",
copying: "DoNotUseInNewTests",
excludingPaths: [
"sidekit.symbols.json",
"mykit-iOS.symbols.json",
Expand Down Expand Up @@ -1624,7 +1624,7 @@ class ConvertServiceTests: XCTestCase {
""")
#else
let (testBundleURL, _, _) = try testBundleAndContext(
copying: "TestBundle",
copying: "DoNotUseInNewTests",
excludingPaths: [
"mykit-iOS.symbols.json",
"[email protected]",
Expand Down
8 changes: 4 additions & 4 deletions Tests/SwiftDocCTests/Indexing/IndexingTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class IndexingTests: XCTestCase {

// MARK: - Tutorial
func testTutorial() throws {
let (bundle, context) = try testBundleAndContext(named: "TestBundle")
let (bundle, context) = try testBundleAndContext(named: "DoNotUseInNewTests")
let tutorialReference = ResolvedTopicReference(bundleID: "org.swift.docc.example", path: "/tutorials/Test-Bundle/TestTutorial", sourceLanguage: .swift)
let node = try context.entity(with: tutorialReference)
let tutorial = node.semantic as! Tutorial
Expand Down Expand Up @@ -89,7 +89,7 @@ class IndexingTests: XCTestCase {
// MARK: - Article

func testArticle() throws {
let (bundle, context) = try testBundleAndContext(named: "TestBundle")
let (bundle, context) = try testBundleAndContext(named: "DoNotUseInNewTests")
let articleReference = ResolvedTopicReference(bundleID: "org.swift.docc.example", path: "/tutorials/Test-Bundle/TestTutorialArticle", sourceLanguage: .swift)
let node = try context.entity(with: articleReference)
let article = node.semantic as! TutorialArticle
Expand Down Expand Up @@ -187,7 +187,7 @@ class IndexingTests: XCTestCase {
}

func testRootPageIndexingRecord() throws {
let (bundle, context) = try testBundleAndContext(named: "TestBundle")
let (bundle, context) = try testBundleAndContext(named: "DoNotUseInNewTests")
let articleReference = ResolvedTopicReference(bundleID: "org.swift.docc.example", path: "/documentation/MyKit", sourceLanguage: .swift)
let node = try context.entity(with: articleReference)
let article = node.semantic as! Symbol
Expand All @@ -207,7 +207,7 @@ class IndexingTests: XCTestCase {
}

func testSymbolIndexingRecord() throws {
let (_, bundle, context) = try testBundleAndContext(copying: "TestBundle") { url in
let (_, bundle, context) = try testBundleAndContext(copying: "DoNotUseInNewTests") { url in
// Modify the documentaion to have default availability for MyKit so that there is platform availability
// information for MyProtocol (both in the render node and in the indexing record.
let plistURL = url.appendingPathComponent("Info.plist")
Expand Down
Loading