Skip to content

Commit

Permalink
Add integration tests for building combined documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
d-ronnqvist committed Aug 20, 2024
1 parent 39d886c commit 1df6bb8
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 1 deletion.
56 changes: 56 additions & 0 deletions IntegrationTests/Tests/MixedTargetsTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,62 @@ final class MixedTargetsTests: ConcurrencyRequiringTestCase {

XCTAssertEqual(libraryDataDirectoryContents, expectedLibraryDataFiles)
}

func testCombinedDocumentation() throws {
#if compiler(>=6.0)
let result = try swiftPackage(
"generate-documentation", "--target", "Executable", "--target", "Library",
"--enable-experimental-combined-documentation",
workingDirectory: try setupTemporaryDirectoryForFixture(named: "MixedTargets")
)

result.assertExitStatusEquals(0)
let outputArchives = result.referencedDocCArchives
XCTAssertEqual(outputArchives.count, 1)
XCTAssertEqual(outputArchives.map(\.lastPathComponent), [
"MixedTargets.doccarchive",
])

let combinedArchiveURL = try XCTUnwrap(outputArchives.first)
let combinedDataDirectoryContents = try filesIn(.dataSubdirectory, of: combinedArchiveURL)
.map(\.relativePath)
.sorted()

XCTAssertEqual(combinedDataDirectoryContents, expectedExecutableDataFiles + expectedLibraryDataFiles)
#else
XCTSkip("This test requires a Swift-DocC version that support the link-dependencies feature")
#endif
}

func testCombinedDocumentationWithOutputPath() throws {
#if compiler(>=6.0)
let outputDirectory = try temporaryDirectory().appendingPathComponent("output")

let result = try swiftPackage(
"--disable-sandbox",
"generate-documentation", "--target", "Executable", "--target", "Library",
"--enable-experimental-combined-documentation",
"--output-path", outputDirectory.path,
workingDirectory: try setupTemporaryDirectoryForFixture(named: "MixedTargets")
)

result.assertExitStatusEquals(0)
let outputArchives = result.referencedDocCArchives
XCTAssertEqual(outputArchives.count, 1)
XCTAssertEqual(outputArchives.map(\.path), [
outputDirectory.path
])

let combinedArchiveURL = try XCTUnwrap(outputArchives.first)
let combinedDataDirectoryContents = try filesIn(.dataSubdirectory, of: combinedArchiveURL)
.map(\.relativePath)
.sorted()

XCTAssertEqual(combinedDataDirectoryContents, expectedExecutableDataFiles + expectedLibraryDataFiles)
#else
XCTSkip("This test requires a Swift-DocC version that support the link-dependencies feature")
#endif
}
}

private let expectedExecutableDataFiles = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ struct SwiftInvocationResult {
.components(separatedBy: .newlines)
.reversed()
// Gather the lines that list archive names
.prefix(while: { $0.hasSuffix(".doccarchive") })
.prefix(while: { !$0.hasPrefix("Generated ") })
// Create absolute URLs for each archive
.map { URL(fileURLWithPath: $0.trimmingCharacters(in: .whitespaces)) }
// Restore the original output order
Expand Down

0 comments on commit 1df6bb8

Please sign in to comment.