|
| 1 | +import XCTest |
| 2 | + |
| 3 | +final class GenerateSubcommandTests: XCTestCase { |
| 4 | + func testCommonMark() throws { |
| 5 | + let command = Bundle.productsDirectory.appendingPathComponent("swift-doc") |
| 6 | + |
| 7 | + let outputDirectory = try temporaryDirectory() |
| 8 | + defer { try? FileManager.default.removeItem(at: outputDirectory) } |
| 9 | + |
| 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 = try contents.filter { try $0.resourceValues(forKeys: [.isDirectoryKey]).isDirectory == true } |
| 41 | + XCTAssertEqual(subdirectories.count, 0, "output should not contain any subdirectories") |
| 42 | + } |
| 43 | + } |
| 44 | + } |
| 45 | + |
| 46 | + func testHTML() throws { |
| 47 | + let command = Bundle.productsDirectory.appendingPathComponent("swift-doc") |
| 48 | + let outputDirectory = try temporaryDirectory() |
| 49 | + |
| 50 | + defer { try? FileManager.default.removeItem(at: outputDirectory) } |
| 51 | + try Process.run(command: command, |
| 52 | + arguments: [ |
| 53 | + "generate", |
| 54 | + "--module-name", "SwiftDoc", |
| 55 | + "--format", "html", |
| 56 | + "--output", outputDirectory.path, |
| 57 | + "Sources" |
| 58 | + ] |
| 59 | + ) { result in |
| 60 | + XCTAssertEqual(result.terminationStatus, EXIT_SUCCESS) |
| 61 | + XCTAssertEqual(result.output, "") |
| 62 | + XCTAssertEqual(result.error, "") |
| 63 | + |
| 64 | + do { |
| 65 | + let html = try String(contentsOf: outputDirectory.appendingPathComponent("index.html")) |
| 66 | + XCTAssertTrue(html.contains("<!DOCTYPE html>")) |
| 67 | + } |
| 68 | + |
| 69 | + do { |
| 70 | + let css = try String(contentsOf: outputDirectory.appendingPathComponent("all.css")) |
| 71 | + XCTAssertTrue(css.contains(":root")) |
| 72 | + } |
| 73 | + |
| 74 | + do { |
| 75 | + let contents = try FileManager.default.contentsOfDirectory(at: outputDirectory, includingPropertiesForKeys: [.isDirectoryKey], options: [.skipsHiddenFiles]) |
| 76 | + let subdirectories = try contents.filter { try $0.resourceValues(forKeys: [.isDirectoryKey]).isDirectory == true } |
| 77 | + .filter { FileManager.default.fileExists(atPath: $0.appendingPathComponent("index.html").path) } |
| 78 | + XCTAssertGreaterThanOrEqual(subdirectories.count, 1, "output should contain one or more subdirectories containing index.html") |
| 79 | + } |
| 80 | + } |
| 81 | + } |
| 82 | +} |
0 commit comments