Skip to content

Commit 6516bb1

Browse files
Refactored tests to clean up repeated code.
(#812 (comment))
1 parent c188327 commit 6516bb1

File tree

1 file changed

+20
-35
lines changed

1 file changed

+20
-35
lines changed

Tests/SwiftDocCUtilitiesTests/ConvertActionTests.swift

Lines changed: 20 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -3071,36 +3071,35 @@ class ConvertActionTests: XCTestCase {
30713071

30723072
// Tests that when converting a catalog with no technology root a warning is raised (r93371988)
30733073
func testConvertWithNoTechnologyRoot() throws {
3074-
func convert(_ bundle: Folder) throws -> ConvertAction {
3075-
return try ConvertAction(
3076-
documentationBundleURL: bundle.absoluteURL,
3074+
func problemsFromConverting(_ catalogContent: [File]) throws -> [Problem] {
3075+
let catalog = Folder(name: "unit-test.docc", content: catalogContent)
3076+
let testDataProvider = try TestFileSystem(folders: [catalog, Folder.emptyHTMLTemplateDirectory])
3077+
let engine = DiagnosticEngine()
3078+
var action = try ConvertAction(
3079+
documentationBundleURL: catalog.absoluteURL,
30773080
outOfProcessResolver: nil,
3078-
analyze: true,
3079-
targetDirectory: targetDirectory,
3081+
analyze: false,
3082+
targetDirectory: URL(fileURLWithPath: "/output"),
30803083
htmlTemplateDirectory: Folder.emptyHTMLTemplateDirectory.absoluteURL,
30813084
emitDigest: false,
30823085
currentPlatforms: nil,
30833086
dataProvider: testDataProvider,
30843087
fileManager: testDataProvider,
3085-
temporaryDirectory: createTemporaryDirectory(),
3088+
temporaryDirectory: URL(fileURLWithPath: "/tmp"),
30863089
diagnosticEngine: engine
30873090
)
3091+
_ = try action.perform(logHandle: .none)
3092+
return engine.problems
30883093
}
3089-
var bundle = Folder(name: "unit-test.docc", content: [
3094+
3095+
3096+
let TutorialArticleWithNoContentProblems = try problemsFromConverting([
30903097
InfoPlist(displayName: "TestBundle", identifier: "com.test.example"),
3091-
TextFile(name: "Documentation.md", utf8Content: "")
3098+
TextFile(name: "Article.tutorial", utf8Content: "")
30923099
])
3093-
var testDataProvider = try TestFileSystem(folders: [bundle, Folder.emptyHTMLTemplateDirectory])
3094-
var targetDirectory = URL(fileURLWithPath: testDataProvider.currentDirectoryPath)
3095-
.appendingPathComponent("target", isDirectory: true)
3096-
var engine = DiagnosticEngine()
3097-
var action = try convert(bundle)
3098-
let _ = try action.perform(logHandle: .standardOutput)
3099-
XCTAssertEqual(engine.problems.count, 1)
3100-
XCTAssertEqual(engine.problems.map { $0.diagnostic.identifier }, ["org.swift.docc.MissingTechnologyRoot"])
3101-
XCTAssert(engine.problems.contains(where: { $0.diagnostic.severity == .warning }))
3100+
XCTAssert(TutorialArticleWithNoContentProblems.contains(where: { $0.diagnostic.identifier == "org.swift.docc.MissingTechnologyRoot" }))
31023101

3103-
bundle = Folder(name: "unit-test.docc", content: [
3102+
let onlyTutorialArticleProblems = try problemsFromConverting([
31043103
InfoPlist(displayName: "TestBundle", identifier: "com.test.example"),
31053104
TextFile(name: "Article.tutorial", utf8Content: """
31063105
@Article(time: 20) {
@@ -3111,31 +3110,17 @@ class ConvertActionTests: XCTestCase {
31113110
"""
31123111
),
31133112
])
3114-
testDataProvider = try TestFileSystem(folders: [bundle, Folder.emptyHTMLTemplateDirectory])
3115-
targetDirectory = URL(fileURLWithPath: testDataProvider.currentDirectoryPath)
3116-
.appendingPathComponent("target", isDirectory: true)
3117-
engine = DiagnosticEngine()
3118-
action = try convert(bundle)
3119-
_ = try action.perform(logHandle: .standardOutput)
3120-
XCTAssert(engine.problems.contains(where: { $0.diagnostic.identifier == "org.swift.docc.MissingTechnologyRoot" }))
3113+
XCTAssert(onlyTutorialArticleProblems.contains(where: { $0.diagnostic.identifier == "org.swift.docc.MissingTechnologyRoot" }))
31213114

3122-
bundle = Folder(name: "unit-test.docc", content: [
3115+
let tutorialTableOfContentProblem = try problemsFromConverting([
31233116
InfoPlist(displayName: "TestBundle", identifier: "com.test.example"),
31243117
TextFile(name: "table-of-contents.tutorial", utf8Content: """
31253118
@Tutorials(name: "Tutorial") {
3126-
@Intro(title: "Tutorial Introduction") {
3127-
}
31283119
}
31293120
"""
31303121
),
31313122
])
3132-
testDataProvider = try TestFileSystem(folders: [bundle, Folder.emptyHTMLTemplateDirectory])
3133-
targetDirectory = URL(fileURLWithPath: testDataProvider.currentDirectoryPath)
3134-
.appendingPathComponent("target", isDirectory: true)
3135-
engine = DiagnosticEngine()
3136-
action = try convert(bundle)
3137-
_ = try action.perform(logHandle: .standardOutput)
3138-
XCTAssertFalse(engine.problems.contains(where: { $0.diagnostic.identifier == "org.swift.docc.MissingTechnologyRoot" }))
3123+
XCTAssert(tutorialTableOfContentProblem.contains(where: { $0.diagnostic.identifier == "org.swift.docc.MissingTechnologyRoot" }))
31393124
}
31403125

31413126
func testWrittenDiagnosticsAfterConvert() throws {

0 commit comments

Comments
 (0)