Skip to content

[5.7] Remove confusing error when no docs are produced #149

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

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -377,12 +377,19 @@ public struct ConvertAction: Action, RecreatingContext {
}

// Process Static Hosting as needed.
if transformForStaticHosting, let templateDirectory = htmlTemplateDirectory {
if transformForStaticHosting,
let templateDirectory = htmlTemplateDirectory,
// If this conversion didn't actually produce documentation, then we expect
// the creation of this data provider to fail because there will be no 'data' subdirectory
// in the documentation output. (r91790147)
let dataProvider = try? LocalFileSystemDataProvider(
rootURL: temporaryFolder.appendingPathComponent(NodeURLGenerator.Path.dataFolderName)
)
{
if indexHTMLData == nil {
indexHTMLData = try StaticHostableTransformer.transformHTMLTemplate(htmlTemplate: templateDirectory, hostingBasePath: hostingBasePath)
}

let dataProvider = try LocalFileSystemDataProvider(rootURL: temporaryFolder.appendingPathComponent(NodeURLGenerator.Path.dataFolderName))
let transformer = StaticHostableTransformer(dataProvider: dataProvider, fileManager: fileManager, outputURL: temporaryFolder, indexHTMLData: indexHTMLData!)
try transformer.transform()
}
Expand Down
29 changes: 29 additions & 0 deletions Tests/SwiftDocCUtilitiesTests/ConvertActionTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2300,6 +2300,35 @@ class ConvertActionTests: XCTestCase {

expectedOutput.assertExist(at: result.outputs[0], fileManager: testDataProvider)
}

// Tests that the default behavior of `docc convert` on the command-line does not throw an error
// when processing a DocC catalog that does not actually produce documentation. (r91790147)
func testConvertDocCCatalogThatProducesNoDocumentationDoesNotThrowError() throws {
let emptyCatalog = Folder(
name: "unit-test.docc",
content: [InfoPlist(displayName: "TestBundle", identifier: "com.test.example")]
)

let temporaryDirectory = try createTemporaryDirectory()
let outputDirectory = temporaryDirectory.appendingPathComponent("output", isDirectory: true)
let doccCatalogDirectory = try emptyCatalog.write(inside: temporaryDirectory)
let htmlTemplateDirectory = try Folder.emptyHTMLTemplateDirectory.write(inside: temporaryDirectory)

setenv(TemplateOption.environmentVariableKey, htmlTemplateDirectory.path, 1)
defer {
unsetenv(TemplateOption.environmentVariableKey)
}

let convertCommand = try Docc.Convert.parse(
[
doccCatalogDirectory.path,
"--output-path", outputDirectory.path,
]
)

var action = try ConvertAction(fromConvertCommand: convertCommand)
_ = try action.perform(logHandle: .none)
}

func testConvertWithCustomTemplates() throws {
let info = InfoPlist(displayName: "TestConvertWithCustomTemplates", identifier: "com.test.example")
Expand Down