Skip to content
This repository has been archived by the owner on Jun 1, 2023. It is now read-only.

Add end-to-end tests for command-line interface #199

Merged
merged 16 commits into from
Oct 6, 2020
Merged
Show file tree
Hide file tree
Changes from 5 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
8 changes: 6 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,12 @@ jobs:
key: ${{ runner.os }}-spm-xcode-${{ matrix.xcode }}-${{ hashFiles('**/Package.resolved') }}
restore-keys: |
${{ runner.os }}-spm-xcode-${{ matrix.xcode }}-
- name: Install System Dependencies
run: |
brew install graphviz
- name: Build and Test
run: swift test -c release
run: |
swift test -c release
env:
DEVELOPER_DIR: /Applications/Xcode_${{ matrix.xcode }}.app/Contents/Developer

Expand All @@ -52,6 +56,6 @@ jobs:
- name: Install System Dependencies
run: |
apt-get update
apt-get install -y libxml2-dev
apt-get install -y libxml2-dev graphviz
- name: Build and Test
run: swift test -c release --enable-test-discovery
5 changes: 5 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Added

- Added an end-to-end test for validity of generated `all.css` file.
#199 by @MaxDesiatov.

## [1.0.0-beta.5] - 2020-09-29

### Added
Expand Down
6 changes: 6 additions & 0 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -63,5 +63,11 @@ let package = Package(
.product(name: "SwiftMarkup", package: "SwiftMarkup")
]
),
.testTarget(
name: "EndToEndTests",
dependencies: [
.target(name: "swift-doc"),
]
),
]
)
6 changes: 6 additions & 0 deletions Package@swift-5.2.swift
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,11 @@ let package = Package(
name: "SwiftDocTests",
dependencies: ["SwiftDoc", "SwiftSyntax", "SwiftSemantics", "SwiftMarkup"]
),
.testTarget(
name: "EndToEndTests",
dependencies: [
.target(name: "swift-doc"),
]
),
]
)
50 changes: 50 additions & 0 deletions Tests/EndToEndTests/EndToEndTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import class Foundation.Bundle
import XCTest

final class EndToEndTests: XCTestCase {
func testCSS() throws {
// Some of the APIs that we use below are available in macOS 10.13 and above.
let process = Process()
process.executableURL = productsDirectory.appendingPathComponent("swift-doc")
process.arguments = ["generate", "--module-name", "SwiftDoc", "--format", "html", "Sources"]

let pipe = Pipe()
process.standardOutput = pipe

if #available(OSX 10.13, *) {
try process.run()
} else {
process.launch()
}
process.waitUntilExit()

let data = pipe.fileHandleForReading.readDataToEndOfFile()
let output = String(data: data, encoding: .utf8)

XCTAssertEqual(output, "")

let cssPath = productsDirectory
.deletingLastPathComponent()
.deletingLastPathComponent()
.appendingPathComponent("documentation")
.appendingPathComponent("all.css")
let cssData = try Data(contentsOf: cssPath)
guard let css = String(data: cssData, encoding: .utf8) else {
return XCTFail("Failed to decode a UTF-8 string from `cssData` in \(#function)")
}

XCTAssertTrue(css.contains(":root"))
}

/// Returns path to the built products directory.
lazy var productsDirectory: URL = {
#if os(macOS)
for bundle in Bundle.allBundles where bundle.bundlePath.hasSuffix(".xctest") {
return bundle.bundleURL.deletingLastPathComponent()
}
fatalError("couldn't find the products directory")
#else
return Bundle.main.bundleURL
#endif
}()
}