Skip to content

Commit 72ecb06

Browse files
committed
Add test for CommonMark output
1 parent d3c6cec commit 72ecb06

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

Tests/EndToEndTests/GenerateSubcommandTests.swift

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,47 @@ import class Foundation.Bundle
22
import XCTest
33

44
final class GenerateSubcommandTests: XCTestCase {
5+
func testCommonMark() throws {
6+
let command = Bundle.productsDirectory.appendingPathComponent("swift-doc")
7+
let outputDirectory = try temporaryDirectory()
8+
9+
defer { try? FileManager.default.removeItem(at: outputDirectory) }
10+
try Process.run(command: command,
11+
arguments: [
12+
"generate",
13+
"--module-name", "SwiftDoc",
14+
"--format", "commonmark",
15+
"--output", outputDirectory.path,
16+
"Sources"
17+
]
18+
) { result in
19+
XCTAssertEqual(result.terminationStatus, EXIT_SUCCESS)
20+
XCTAssertEqual(result.output, "")
21+
XCTAssertEqual(result.error, "")
22+
23+
do {
24+
let commonmark = try String(contentsOf: outputDirectory.appendingPathComponent("Home.md"))
25+
XCTAssertTrue(commonmark.contains("# Types"))
26+
}
27+
28+
do {
29+
let commonmark = try String(contentsOf: outputDirectory.appendingPathComponent("_Sidebar.md"))
30+
XCTAssertTrue(commonmark.contains("<summary>Types</summary>"))
31+
}
32+
33+
do {
34+
let commonmark = try String(contentsOf: outputDirectory.appendingPathComponent("_Footer.md"))
35+
XCTAssertTrue(commonmark.contains("[swift-doc](https://github.com/SwiftDocOrg/swift-doc)"))
36+
}
37+
38+
do {
39+
let contents = try FileManager.default.contentsOfDirectory(at: outputDirectory, includingPropertiesForKeys: [.isDirectoryKey], options: [.skipsHiddenFiles])
40+
let subdirectories = contents.filter { $0.hasDirectoryPath }
41+
XCTAssertEqual(subdirectories.count, 0, "output should not contain any subdirectories")
42+
}
43+
}
44+
}
45+
546
func testHTML() throws {
647
let command = Bundle.productsDirectory.appendingPathComponent("swift-doc")
748
let outputDirectory = try temporaryDirectory()

0 commit comments

Comments
 (0)